1 /* 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" 24 #include "profile/profile_compilation_info.h" 25 26 namespace art { 27 28 class 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 { 33 kCompile = 0, 34 kSkipCompilation = 1, 35 kErrorBadProfiles = 2, 36 kErrorIO = 3, 37 kErrorCannotLock = 4 38 }; 39 40 // Process the profile information present in the given files. Returns one of 41 // ProcessingResult values depending on profile information and whether or not 42 // the analysis ended up successfully (i.e. no errors during reading, 43 // merging or writing of profile files). 44 // 45 // When the returned value is kCompile there is a significant difference 46 // between profile_files and reference_profile_files. In this case 47 // reference_profile will be updated with the profiling info obtain after 48 // merging all profiles. 49 // 50 // When the returned value is kSkipCompilation, the difference between the 51 // merge of the current profiles and the reference one is insignificant. In 52 // this case no file will be updated. 53 // 54 static ProcessingResult ProcessProfiles( 55 const std::vector<std::string>& profile_files, 56 const std::string& reference_profile_file, 57 const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn 58 = ProfileCompilationInfo::ProfileFilterFnAcceptAll, 59 bool store_aggregation_counters = false); 60 61 static ProcessingResult ProcessProfiles( 62 const std::vector<int>& profile_files_fd_, 63 int reference_profile_file_fd, 64 const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn 65 = ProfileCompilationInfo::ProfileFilterFnAcceptAll, 66 bool store_aggregation_counters = false); 67 68 private: 69 static ProcessingResult ProcessProfilesInternal( 70 const std::vector<ScopedFlock>& profile_files, 71 const ScopedFlock& reference_profile_file, 72 const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn, 73 bool store_aggregation_counters); 74 75 DISALLOW_COPY_AND_ASSIGN(ProfileAssistant); 76 }; 77 78 } // namespace art 79 80 #endif // ART_PROFMAN_PROFILE_ASSISTANT_H_ 81