blob: 32d4c5bedc32eaab6e275c6a6cb8836325b50964 [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
32/**
33 * Profiling information in a format that can be serialized to disk.
34 * It is a serialize-friendly format based on information collected
35 * by the interpreter (ProfileInfo).
36 * Currently it stores only the hot compiled methods.
37 */
38class OfflineProfilingInfo {
39 public:
Calin Juravle4d77b6a2015-12-01 18:38:09 +000040 void SaveProfilingInfo(const std::string& filename, const std::vector<ArtMethod*>& methods);
Calin Juravle31f2c152015-10-23 17:56:15 +010041
42 private:
43 // Map identifying the location of the profiled methods.
44 // dex_file_ -> [dex_method_index]+
45 using DexFileToMethodsMap = SafeMap<const DexFile*, std::set<uint32_t>>;
46
47 void AddMethodInfo(ArtMethod* method, DexFileToMethodsMap* info)
48 SHARED_REQUIRES(Locks::mutator_lock_);
49 bool Serialize(const std::string& filename, const DexFileToMethodsMap& info) const;
Calin Juravle31f2c152015-10-23 17:56:15 +010050};
51
Calin Juravle226501b2015-12-11 14:41:31 +000052/**
53 * Profile information in a format suitable to be queried by the compiler and performing
54 * profile guided compilation.
55 */
56class ProfileCompilationInfo {
57 public:
58 // Constructs a ProfileCompilationInfo backed by the provided file.
59 explicit ProfileCompilationInfo(const std::string& filename) : filename_(filename) {}
60
61 // Loads profile information corresponding to the provided dex files.
62 // The dex files' multidex suffixes must be unique.
63 // This resets the state of the profiling information
64 // (i.e. all previously loaded info are cleared).
65 bool Load(const std::vector<const DexFile*>& dex_files);
66
67 // Returns true if the method reference is present in the profiling info.
68 bool ContainsMethod(const MethodReference& method_ref) const;
69
70 const std::string& GetFilename() const { return filename_; }
71
72 // Dumps all the loaded profile info into a string and returns it.
73 // This is intended for testing and debugging.
74 std::string DumpInfo(bool print_full_dex_location = true) const;
75
76 private:
77 bool ProcessLine(const std::string& line,
78 const std::vector<const DexFile*>& dex_files);
79
80 using ClassToMethodsMap = SafeMap<uint32_t, std::set<uint32_t>>;
81 // Map identifying the location of the profiled methods.
82 // dex_file -> class_index -> [dex_method_index]+
83 using DexFileToProfileInfoMap = SafeMap<const DexFile*, ClassToMethodsMap>;
84
85 const std::string filename_;
86 DexFileToProfileInfoMap info_;
87};
88
Calin Juravle31f2c152015-10-23 17:56:15 +010089} // namespace art
90
91#endif // ART_RUNTIME_JIT_OFFLINE_PROFILING_INFO_H_