summaryrefslogtreecommitdiff
path: root/simpleperf/thread_tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'simpleperf/thread_tree.h')
-rw-r--r--simpleperf/thread_tree.h66
1 files changed, 34 insertions, 32 deletions
diff --git a/simpleperf/thread_tree.h b/simpleperf/thread_tree.h
index 1024b8e2..76d3403d 100644
--- a/simpleperf/thread_tree.h
+++ b/simpleperf/thread_tree.h
@@ -26,13 +26,15 @@
#include "dso.h"
-namespace simpleperf {
-
struct Record;
constexpr char DEFAULT_KERNEL_MMAP_NAME[] = "[kernel.kallsyms]";
+// Seen in perf.data file generated by perf.
+constexpr char DEFAULT_KERNEL_MMAP_NAME_PERF[] = "[kernel.kallsyms]_text";
constexpr char DEFAULT_EXECNAME_FOR_THREAD_MMAP[] = "//anon";
+namespace simpleperf {
+
namespace map_flags {
constexpr uint32_t PROT_JIT_SYMFILE_MAP = 0x4000;
} // namespace map_flags
@@ -45,8 +47,8 @@ struct MapEntry {
bool in_kernel;
uint32_t flags;
- MapEntry(uint64_t start_addr, uint64_t len, uint64_t pgoff, Dso* dso, bool in_kernel,
- uint32_t flags = 0)
+ MapEntry(uint64_t start_addr, uint64_t len, uint64_t pgoff,
+ Dso* dso, bool in_kernel, uint32_t flags = 0)
: start_addr(start_addr),
len(len),
pgoff(pgoff),
@@ -57,7 +59,9 @@ struct MapEntry {
uint64_t get_end_addr() const { return start_addr + len; }
- uint64_t Contains(uint64_t addr) const { return addr >= start_addr && addr < get_end_addr(); }
+ uint64_t Contains(uint64_t addr) const {
+ return addr >= start_addr && addr < get_end_addr();
+ }
uint64_t GetVaddrInFile(uint64_t addr) const {
if (Contains(addr)) {
@@ -69,7 +73,7 @@ struct MapEntry {
struct MapSet {
std::map<uint64_t, const MapEntry*> maps; // Map from start_addr to a MapEntry.
- uint64_t version = 0u; // incremented each time changing maps
+ uint64_t version = 0u; // incremented each time changing maps
const MapEntry* FindMapByAddr(uint64_t addr) const;
};
@@ -77,12 +81,10 @@ struct MapSet {
struct ThreadEntry {
int pid;
int tid;
- const char* comm; // It always refers to the latest comm.
+ const char* comm; // It always refers to the latest comm.
std::shared_ptr<MapSet> maps; // maps is shared by threads in the same process.
};
-struct FileFeature;
-
// ThreadTree contains thread information (in ThreadEntry) and mmap information
// (in MapEntry) of the monitored threads. It also has interface to access
// symbols in executable binaries mapped in the monitored threads.
@@ -91,34 +93,32 @@ class ThreadTree {
ThreadTree()
: show_ip_for_unknown_symbol_(false),
show_mark_for_unknown_symbol_(false),
- unknown_symbol_("unknown", 0, std::numeric_limits<unsigned long long>::max()) {
+ unknown_symbol_("unknown", 0,
+ std::numeric_limits<unsigned long long>::max()) {
unknown_dso_ = Dso::CreateDso(DSO_UNKNOWN_FILE, "unknown");
- unknown_map_ =
- MapEntry(0, std::numeric_limits<unsigned long long>::max(), 0, unknown_dso_.get(), false);
+ unknown_map_ = MapEntry(0, std::numeric_limits<unsigned long long>::max(),
+ 0, unknown_dso_.get(), false);
+ kernel_dso_ = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
// We can't dump comm for pid 0 from /proc, so add it's name here.
SetThreadName(0, 0, "swapper");
}
- virtual ~ThreadTree() {}
void SetThreadName(int pid, int tid, const std::string& comm);
void ForkThread(int pid, int tid, int ppid, int ptid);
- virtual ThreadEntry* FindThread(int tid) const;
+ ThreadEntry* FindThread(int tid);
ThreadEntry* FindThreadOrNew(int pid, int tid);
void ExitThread(int pid, int tid);
- void AddKernelMap(uint64_t start_addr, uint64_t len, uint64_t pgoff, const std::string& filename);
+ void AddKernelMap(uint64_t start_addr, uint64_t len, uint64_t pgoff,
+ const std::string& filename);
const MapSet& GetKernelMaps() { return kernel_maps_; }
- void AddThreadMap(int pid, int tid, uint64_t start_addr, uint64_t len, uint64_t pgoff,
- const std::string& filename, uint32_t flags = 0);
-
- // Add process symbols that do not correspond to any real dso.
- // For example, these might be symbols generated by a JIT.
- void AddSymbolsForProcess(int pid, std::vector<Symbol>* symbols);
-
- const MapEntry* FindMap(const ThreadEntry* thread, uint64_t ip, bool in_kernel);
+ void AddThreadMap(int pid, int tid, uint64_t start_addr, uint64_t len,
+ uint64_t pgoff, const std::string& filename, uint32_t flags = 0);
+ const MapEntry* FindMap(const ThreadEntry* thread, uint64_t ip,
+ bool in_kernel);
// Find map for an ip address when we don't know whether it is in kernel.
const MapEntry* FindMap(const ThreadEntry* thread, uint64_t ip);
- const Symbol* FindSymbol(const MapEntry* map, uint64_t ip, uint64_t* pvaddr_in_file,
- Dso** pdso = nullptr);
+ const Symbol* FindSymbol(const MapEntry* map, uint64_t ip,
+ uint64_t* pvaddr_in_file, Dso** pdso = nullptr);
const Symbol* FindKernelSymbol(uint64_t ip);
bool IsUnknownDso(const Dso* dso) const { return dso == unknown_dso_.get(); }
const Symbol* UnknownSymbol() const { return &unknown_symbol_; }
@@ -131,7 +131,10 @@ class ThreadTree {
// Clear thread and map information, but keep loaded dso information. It saves
// the time to reload dso information.
void ClearThreadAndMap();
- void AddDsoInfo(FileFeature& file);
+
+ void AddDsoInfo(const std::string& file_path, uint32_t file_type,
+ uint64_t min_vaddr, uint64_t file_offset_of_min_vaddr,
+ std::vector<Symbol>* symbols, const std::vector<uint64_t>& dex_file_offsets);
void AddDexFileOffset(const std::string& file_path, uint64_t dex_file_offset);
// Update thread tree with information provided by record.
@@ -141,17 +144,12 @@ class ThreadTree {
private:
ThreadEntry* CreateThread(int pid, int tid);
- Dso* FindKernelDsoOrNew();
- Dso* FindKernelModuleDsoOrNew(const std::string& filename, uint64_t memory_start,
- uint64_t memory_end);
+ Dso* FindKernelDsoOrNew(const std::string& filename);
Dso* FindUserDsoOrNew(const std::string& filename, uint64_t start_addr = 0,
DsoType dso_type = DSO_ELF_FILE);
const MapEntry* AllocateMap(const MapEntry& entry);
void InsertMap(MapSet& maps, const MapEntry& entry);
- // Add thread maps to cover symbols in dso.
- void AddThreadMapsForDsoSymbols(ThreadEntry* thread, Dso* dso);
-
std::unordered_map<int, std::unique_ptr<ThreadEntry>> thread_tree_;
std::vector<std::unique_ptr<std::string>> thread_comm_storage_;
@@ -170,4 +168,8 @@ class ThreadTree {
} // namespace simpleperf
+using MapEntry = simpleperf::MapEntry;
+using ThreadEntry = simpleperf::ThreadEntry;
+using ThreadTree = simpleperf::ThreadTree;
+
#endif // SIMPLE_PERF_THREAD_TREE_H_