blob: 81f2a5692de108f1df0868bd7bf2bc0b63530e98 [file] [log] [blame]
Calin Juravle998c2162015-12-21 15:39:33 +02001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "profile_assistant.h"
18
19namespace art {
20
21// Minimum number of new methods that profiles must contain to enable recompilation.
22static constexpr const uint32_t kMinNewMethodsForCompilation = 10;
23
24bool ProfileAssistant::ProcessProfiles(
25 const std::vector<std::string>& profile_files,
26 const std::vector<std::string>& reference_profile_files,
27 /*out*/ ProfileCompilationInfo** profile_compilation_info) {
28 DCHECK(!profile_files.empty());
29 DCHECK(reference_profile_files.empty() ||
30 (profile_files.size() == reference_profile_files.size()));
31
32 std::vector<ProfileCompilationInfo> new_info(profile_files.size());
33 bool should_compile = false;
34 // Read the main profile files.
35 for (size_t i = 0; i < profile_files.size(); i++) {
36 if (!new_info[i].Load(profile_files[i])) {
37 LOG(WARNING) << "Could not load profile file: " << profile_files[i];
38 return false;
39 }
40 // Do we have enough new profiled methods that will make the compilation worthwhile?
41 should_compile |= (new_info[i].GetNumberOfMethods() > kMinNewMethodsForCompilation);
42 }
43 if (!should_compile) {
44 *profile_compilation_info = nullptr;
45 return true;
46 }
47
48 std::unique_ptr<ProfileCompilationInfo> result(new ProfileCompilationInfo());
49 for (size_t i = 0; i < new_info.size(); i++) {
50 // Merge all data into a single object.
51 result->Load(new_info[i]);
52 // If we have any reference profile information merge their information with
53 // the current profiles and save them back to disk.
54 if (!reference_profile_files.empty()) {
55 if (!new_info[i].Load(reference_profile_files[i])) {
56 LOG(WARNING) << "Could not load reference profile file: " << reference_profile_files[i];
57 return false;
58 }
59 if (!new_info[i].Save(reference_profile_files[i])) {
60 LOG(WARNING) << "Could not save reference profile file: " << reference_profile_files[i];
61 return false;
62 }
63 }
64 }
65 *profile_compilation_info = result.release();
66 return true;
67}
68
69} // namespace art