xref: /aosp_15_r20/art/libprofile/profile/profile_boot_info.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2019 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBPROFILE_PROFILE_PROFILE_BOOT_INFO_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_LIBPROFILE_PROFILE_PROFILE_BOOT_INFO_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <vector>
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker #include "base/value_object.h"
23*795d594fSAndroid Build Coastguard Worker 
24*795d594fSAndroid Build Coastguard Worker namespace art {
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker class DexFile;
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker /**
29*795d594fSAndroid Build Coastguard Worker  * Abstraction over a list of methods representing the boot profile
30*795d594fSAndroid Build Coastguard Worker  * of an application. The order in the list is the order in which the methods
31*795d594fSAndroid Build Coastguard Worker  * should be compiled.
32*795d594fSAndroid Build Coastguard Worker  *
33*795d594fSAndroid Build Coastguard Worker  * TODO: This is currently implemented as a separate profile to
34*795d594fSAndroid Build Coastguard Worker  * ProfileCompilationInfo to enable fast experiments, but we are likely to
35*795d594fSAndroid Build Coastguard Worker  * incorporate it in ProfileCompilationInfo once we settle on an automated way
36*795d594fSAndroid Build Coastguard Worker  * to generate such a boot profile.
37*795d594fSAndroid Build Coastguard Worker  */
38*795d594fSAndroid Build Coastguard Worker class ProfileBootInfo : public ValueObject {
39*795d594fSAndroid Build Coastguard Worker  public:
40*795d594fSAndroid Build Coastguard Worker   // Add the given method located in the given dex file in the profile.
41*795d594fSAndroid Build Coastguard Worker   void Add(const DexFile* dex_file, uint32_t method_index);
42*795d594fSAndroid Build Coastguard Worker 
43*795d594fSAndroid Build Coastguard Worker   // Save this profile boot info into the `fd` file descriptor.
44*795d594fSAndroid Build Coastguard Worker   bool Save(int fd) const;
45*795d594fSAndroid Build Coastguard Worker 
46*795d594fSAndroid Build Coastguard Worker   // Load the profile listing from `fd` into this profile boot info. Note that
47*795d594fSAndroid Build Coastguard Worker   // the profile boot info will store internally the dex files being passed.
48*795d594fSAndroid Build Coastguard Worker   bool Load(int fd, const std::vector<const DexFile*>& dex_files);
49*795d594fSAndroid Build Coastguard Worker 
GetDexFiles()50*795d594fSAndroid Build Coastguard Worker   const std::vector<const DexFile*>& GetDexFiles() const {
51*795d594fSAndroid Build Coastguard Worker     return dex_files_;
52*795d594fSAndroid Build Coastguard Worker   }
53*795d594fSAndroid Build Coastguard Worker 
GetMethods()54*795d594fSAndroid Build Coastguard Worker   const std::vector<std::pair<uint32_t, uint32_t>>& GetMethods() const {
55*795d594fSAndroid Build Coastguard Worker     return methods_;
56*795d594fSAndroid Build Coastguard Worker   }
57*795d594fSAndroid Build Coastguard Worker 
IsEmpty()58*795d594fSAndroid Build Coastguard Worker   bool IsEmpty() const { return dex_files_.empty() && methods_.empty(); }
59*795d594fSAndroid Build Coastguard Worker 
60*795d594fSAndroid Build Coastguard Worker  private:
61*795d594fSAndroid Build Coastguard Worker   // List of dex files this boot profile info covers.
62*795d594fSAndroid Build Coastguard Worker   std::vector<const DexFile*> dex_files_;
63*795d594fSAndroid Build Coastguard Worker 
64*795d594fSAndroid Build Coastguard Worker   // List of pair of <dex file index, method_id> methods to be compiled in
65*795d594fSAndroid Build Coastguard Worker   // order.
66*795d594fSAndroid Build Coastguard Worker   std::vector<std::pair<uint32_t, uint32_t>> methods_;
67*795d594fSAndroid Build Coastguard Worker };
68*795d594fSAndroid Build Coastguard Worker 
69*795d594fSAndroid Build Coastguard Worker }  // namespace art
70*795d594fSAndroid Build Coastguard Worker 
71*795d594fSAndroid Build Coastguard Worker #endif  // ART_LIBPROFILE_PROFILE_PROFILE_BOOT_INFO_H_
72