blob: 9aa0768c01abeabb4600f28b61505a30d3fcdb41 [file] [log] [blame]
Calin Juravle024160852016-02-23 12:00:03 +00001/*
2 * Copyright (C) 2016 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#ifndef ART_PROFMAN_PROFILE_ASSISTANT_H_
18#define ART_PROFMAN_PROFILE_ASSISTANT_H_
19
20#include <string>
21#include <vector>
22
23#include "base/scoped_flock.h"
David Sehr82d046e2018-04-23 08:14:19 -070024#include "profile/profile_compilation_info.h"
Calin Juravle024160852016-02-23 12:00:03 +000025
26namespace art {
27
28class ProfileAssistant {
29 public:
30 // These also serve as return codes of profman and are processed by installd
31 // (frameworks/native/cmds/installd/commands.cpp)
32 enum ProcessingResult {
Calin Juravlec0200a92019-11-14 09:01:11 -080033 kSuccess = 0, // Generic success code for non-analysis runs.
34 kCompile = 1,
35 kSkipCompilation = 2,
36 kErrorBadProfiles = 3,
37 kErrorIO = 4,
38 kErrorCannotLock = 5,
39 kErrorDifferentVersions = 6,
Calin Juravle0e82e0f2019-11-11 18:34:10 -080040 };
41
42 class Options {
43 public:
44 static constexpr bool kForceMergeDefault = false;
45 static constexpr bool kBootImageMergeDefault = false;
46
47 Options()
48 : force_merge_(kForceMergeDefault),
49 boot_image_merge_(kBootImageMergeDefault) {
50 }
51
52 bool IsForceMerge() const { return force_merge_; }
53 bool IsBootImageMerge() const { return boot_image_merge_; }
54
55 void SetForceMerge(bool value) { force_merge_ = value; }
56 void SetBootImageMerge(bool value) { boot_image_merge_ = value; }
57
58 private:
59 // If true, performs a forced merge, without analyzing if there is a
60 // significant difference between the current profile and the reference profile.
61 // See ProfileAssistant#ProcessProfile.
62 bool force_merge_;
63 // Signals that the merge is for boot image profiles. It will ignore differences
64 // in profile versions (instead of aborting).
65 bool boot_image_merge_;
Calin Juravle024160852016-02-23 12:00:03 +000066 };
67
68 // Process the profile information present in the given files. Returns one of
69 // ProcessingResult values depending on profile information and whether or not
70 // the analysis ended up successfully (i.e. no errors during reading,
71 // merging or writing of profile files).
72 //
73 // When the returned value is kCompile there is a significant difference
74 // between profile_files and reference_profile_files. In this case
75 // reference_profile will be updated with the profiling info obtain after
76 // merging all profiles.
77 //
78 // When the returned value is kSkipCompilation, the difference between the
79 // merge of the current profiles and the reference one is insignificant. In
80 // this case no file will be updated.
81 //
82 static ProcessingResult ProcessProfiles(
83 const std::vector<std::string>& profile_files,
Calin Juravlee10c1e22018-01-26 20:10:15 -080084 const std::string& reference_profile_file,
85 const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn
Calin Juravle0e82e0f2019-11-11 18:34:10 -080086 = ProfileCompilationInfo::ProfileFilterFnAcceptAll,
87 const Options& options = Options());
Calin Juravle024160852016-02-23 12:00:03 +000088
89 static ProcessingResult ProcessProfiles(
90 const std::vector<int>& profile_files_fd_,
Calin Juravlee10c1e22018-01-26 20:10:15 -080091 int reference_profile_file_fd,
92 const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn
Calin Juravle0e82e0f2019-11-11 18:34:10 -080093 = ProfileCompilationInfo::ProfileFilterFnAcceptAll,
94 const Options& options = Options());
Calin Juravle024160852016-02-23 12:00:03 +000095
96 private:
97 static ProcessingResult ProcessProfilesInternal(
98 const std::vector<ScopedFlock>& profile_files,
Calin Juravlee10c1e22018-01-26 20:10:15 -080099 const ScopedFlock& reference_profile_file,
Calin Juravle0e82e0f2019-11-11 18:34:10 -0800100 const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn,
101 const Options& options);
Calin Juravle024160852016-02-23 12:00:03 +0000102
103 DISALLOW_COPY_AND_ASSIGN(ProfileAssistant);
104};
105
106} // namespace art
107
108#endif // ART_PROFMAN_PROFILE_ASSISTANT_H_