blob: 26e1ac385f48fe7ee0dcbdb3bb24735263147132 [file] [log] [blame]
Calin Juravle31f2c152015-10-23 17:56:15 +01001/*
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 Juravle4d77b6a2015-12-01 18:38:09 +000021#include <vector>
Calin Juravle31f2c152015-10-23 17:56:15 +010022
23#include "atomic.h"
24#include "dex_file.h"
Calin Juravle226501b2015-12-11 14:41:31 +000025#include "method_reference.h"
Calin Juravle31f2c152015-10-23 17:56:15 +010026#include "safe_map.h"
27
28namespace art {
29
30class ArtMethod;
31
Calin Juravle998c2162015-12-21 15:39:33 +020032// TODO: rename file.
Calin Juravle31f2c152015-10-23 17:56:15 +010033/**
Calin Juravle998c2162015-12-21 15:39:33 +020034 * 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 Juravle31f2c152015-10-23 17:56:15 +010038 * Currently it stores only the hot compiled methods.
39 */
Calin Juravle226501b2015-12-11 14:41:31 +000040class ProfileCompilationInfo {
41 public:
Calin Juravle998c2162015-12-21 15:39:33 +020042 static bool SaveProfilingInfo(const std::string& filename,
43 const std::vector<ArtMethod*>& methods);
Calin Juravle226501b2015-12-11 14:41:31 +000044
Calin Juravle998c2162015-12-21 15:39:33 +020045 // 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 Juravle226501b2015-12-11 14:41:31 +000053
54 // Returns true if the method reference is present in the profiling info.
55 bool ContainsMethod(const MethodReference& method_ref) const;
56
Calin Juravle226501b2015-12-11 14:41:31 +000057 // Dumps all the loaded profile info into a string and returns it.
Calin Juravle998c2162015-12-21 15:39:33 +020058 // If dex_files is not null then the method indices will be resolved to their
59 // names.
Calin Juravle226501b2015-12-11 14:41:31 +000060 // This is intended for testing and debugging.
Calin Juravle998c2162015-12-21 15:39:33 +020061 std::string DumpInfo(const std::vector<const DexFile*>* dex_files,
62 bool print_full_dex_location = true) const;
Calin Juravle226501b2015-12-11 14:41:31 +000063
64 private:
Calin Juravle998c2162015-12-21 15:39:33 +020065 bool AddData(const std::string& dex_location, uint32_t checksum, uint16_t method_idx);
66 bool ProcessLine(const std::string& line);
Calin Juravle226501b2015-12-11 14:41:31 +000067
Calin Juravle998c2162015-12-21 15:39:33 +020068 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 Juravle226501b2015-12-11 14:41:31 +000073
Calin Juravle998c2162015-12-21 15:39:33 +020074 using DexFileToProfileInfoMap = SafeMap<const std::string, DexFileData>;
75
Calin Juravle226501b2015-12-11 14:41:31 +000076 DexFileToProfileInfoMap info_;
77};
78
Calin Juravle31f2c152015-10-23 17:56:15 +010079} // namespace art
80
81#endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_