2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SIMPLE_PERF_THREAD_TREE_H_
18 #define SIMPLE_PERF_THREAD_TREE_H_
29 uint64_t time; // Map creation time.
33 struct MapComparator {
34 bool operator()(const MapEntry* map1, const MapEntry* map2) const;
40 const char* comm; // It always refers to the latest comm.
41 std::set<MapEntry*, MapComparator> maps;
46 ThreadTree() : unknown_dso_(DSO_ELF_FILE, "unknown"), unknown_symbol_("unknown", 0, ULLONG_MAX) {
47 unknown_map_ = MapEntry{
56 void AddThread(int pid, int tid, const std::string& comm);
57 void ForkThread(int pid, int tid, int ppid, int ptid);
58 ThreadEntry* FindThreadOrNew(int pid, int tid);
59 void AddKernelMap(uint64_t start_addr, uint64_t len, uint64_t pgoff, uint64_t time,
60 const std::string& filename);
61 void AddThreadMap(int pid, int tid, uint64_t start_addr, uint64_t len, uint64_t pgoff,
62 uint64_t time, const std::string& filename);
63 const MapEntry* FindMap(const ThreadEntry* thread, uint64_t ip, bool in_kernel);
64 const SymbolEntry* FindSymbol(const MapEntry* map, uint64_t ip);
65 const MapEntry* UnknownMap() const {
70 DsoEntry* FindKernelDsoOrNew(const std::string& filename);
71 DsoEntry* FindUserDsoOrNew(const std::string& filename);
73 std::unordered_map<int, std::unique_ptr<ThreadEntry>> thread_tree_;
74 std::vector<std::unique_ptr<std::string>> thread_comm_storage_;
76 std::set<MapEntry*, MapComparator> kernel_map_tree_;
77 std::vector<std::unique_ptr<MapEntry>> map_storage_;
78 MapEntry unknown_map_;
80 std::unique_ptr<DsoEntry> kernel_dso_;
81 std::unordered_map<std::string, std::unique_ptr<DsoEntry>> module_dso_tree_;
82 std::unordered_map<std::string, std::unique_ptr<DsoEntry>> user_dso_tree_;
83 DsoEntry unknown_dso_;
84 SymbolEntry unknown_symbol_;
89 void BuildThreadTree(const Record& record, ThreadTree* thread_tree);
91 #endif // SIMPLE_PERF_THREAD_TREE_H_