Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 1 | /* |
| 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 | #ifndef ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ |
| 18 | #define ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ |
| 19 | |
| 20 | #include <set> |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 21 | #include <vector> |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 22 | |
| 23 | #include "atomic.h" |
| 24 | #include "dex_file.h" |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 25 | #include "method_reference.h" |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 26 | #include "safe_map.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | class ArtMethod; |
| 31 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 32 | // TODO: rename file. |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 33 | /** |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 34 | * Profile information in a format suitable to be queried by the compiler and |
| 35 | * performing profile guided compilation. |
| 36 | * It is a serialize-friendly format based on information collected by the |
| 37 | * interpreter (ProfileInfo). |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 38 | * Currently it stores only the hot compiled methods. |
| 39 | */ |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 40 | class ProfileCompilationInfo { |
| 41 | public: |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 42 | static bool SaveProfilingInfo(const std::string& filename, |
| 43 | const std::vector<ArtMethod*>& methods); |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 44 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 45 | // Loads profile information from the given file. |
| 46 | bool Load(const std::string& profile_filename); |
| 47 | // Loads the data from another ProfileCompilationInfo object. |
| 48 | bool Load(const ProfileCompilationInfo& info); |
| 49 | // Saves the profile data to the given file. |
| 50 | bool Save(const std::string& profile_filename); |
| 51 | // Returns the number of methods that were profiled. |
| 52 | uint32_t GetNumberOfMethods() const; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 53 | |
| 54 | // Returns true if the method reference is present in the profiling info. |
| 55 | bool ContainsMethod(const MethodReference& method_ref) const; |
| 56 | |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 57 | // Dumps all the loaded profile info into a string and returns it. |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 58 | // If dex_files is not null then the method indices will be resolved to their |
| 59 | // names. |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 60 | // This is intended for testing and debugging. |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 61 | std::string DumpInfo(const std::vector<const DexFile*>* dex_files, |
| 62 | bool print_full_dex_location = true) const; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 63 | |
| 64 | private: |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 65 | bool AddData(const std::string& dex_location, uint32_t checksum, uint16_t method_idx); |
| 66 | bool ProcessLine(const std::string& line); |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 67 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 68 | struct DexFileData { |
| 69 | explicit DexFileData(uint32_t location_checksum) : checksum(location_checksum) {} |
| 70 | uint32_t checksum; |
| 71 | std::set<uint16_t> method_set; |
| 72 | }; |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 73 | |
Calin Juravle | 998c216 | 2015-12-21 15:39:33 +0200 | [diff] [blame] | 74 | using DexFileToProfileInfoMap = SafeMap<const std::string, DexFileData>; |
| 75 | |
Calin Juravle | 226501b | 2015-12-11 14:41:31 +0000 | [diff] [blame] | 76 | DexFileToProfileInfoMap info_; |
| 77 | }; |
| 78 | |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 79 | } // namespace art |
| 80 | |
| 81 | #endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_ |