summaryrefslogtreecommitdiff
path: root/compiler/profile_assistant.cc
blob: 81f2a5692de108f1df0868bd7bf2bc0b63530e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "profile_assistant.h"

namespace art {

// Minimum number of new methods that profiles must contain to enable recompilation.
static constexpr const uint32_t kMinNewMethodsForCompilation = 10;

bool ProfileAssistant::ProcessProfiles(
      const std::vector<std::string>& profile_files,
      const std::vector<std::string>& reference_profile_files,
      /*out*/ ProfileCompilationInfo** profile_compilation_info) {
  DCHECK(!profile_files.empty());
  DCHECK(reference_profile_files.empty() ||
      (profile_files.size() == reference_profile_files.size()));

  std::vector<ProfileCompilationInfo> new_info(profile_files.size());
  bool should_compile = false;
  // Read the main profile files.
  for (size_t i = 0; i < profile_files.size(); i++) {
    if (!new_info[i].Load(profile_files[i])) {
      LOG(WARNING) << "Could not load profile file: " << profile_files[i];
      return false;
    }
    // Do we have enough new profiled methods that will make the compilation worthwhile?
    should_compile |= (new_info[i].GetNumberOfMethods() > kMinNewMethodsForCompilation);
  }
  if (!should_compile) {
    *profile_compilation_info = nullptr;
    return true;
  }

  std::unique_ptr<ProfileCompilationInfo> result(new ProfileCompilationInfo());
  for (size_t i = 0; i < new_info.size(); i++) {
    // Merge all data into a single object.
    result->Load(new_info[i]);
    // If we have any reference profile information merge their information with
    // the current profiles and save them back to disk.
    if (!reference_profile_files.empty()) {
      if (!new_info[i].Load(reference_profile_files[i])) {
        LOG(WARNING) << "Could not load reference profile file: " << reference_profile_files[i];
        return false;
      }
      if (!new_info[i].Save(reference_profile_files[i])) {
        LOG(WARNING) << "Could not save reference profile file: " << reference_profile_files[i];
        return false;
      }
    }
  }
  *profile_compilation_info = result.release();
  return true;
}

}  // namespace art