diff options
Diffstat (limited to 'simpleperf/report_lib_interface.cpp')
-rw-r--r-- | simpleperf/report_lib_interface.cpp | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/simpleperf/report_lib_interface.cpp b/simpleperf/report_lib_interface.cpp index 2aa0ccc6..abd09628 100644 --- a/simpleperf/report_lib_interface.cpp +++ b/simpleperf/report_lib_interface.cpp @@ -51,6 +51,7 @@ struct SymbolEntry { const char* dso_name; uint64_t vaddr_in_file; const char* symbol_name; + uint64_t symbol_addr; }; struct CallChainEntry { @@ -80,6 +81,8 @@ Sample* GetNextSample(ReportLib* report_lib) EXPORT; Event* GetEventOfCurrentSample(ReportLib* report_lib) EXPORT; SymbolEntry* GetSymbolOfCurrentSample(ReportLib* report_lib) EXPORT; CallChain* GetCallChainOfCurrentSample(ReportLib* report_lib) EXPORT; + +const char* GetBuildIdForPath(ReportLib* report_lib, const char* path) EXPORT; } struct EventAttrWithName { @@ -122,8 +125,11 @@ class ReportLib { SymbolEntry* GetSymbolOfCurrentSample(); CallChain* GetCallChainOfCurrentSample(); + const char* GetBuildIdForPath(const char* path); + private: Sample* GetCurrentSample(); + bool OpenRecordFileIfNecessary(); std::unique_ptr<android::base::ScopedLogSeverity> log_severity_; std::string record_filename_; @@ -136,6 +142,7 @@ class ReportLib { SymbolEntry current_symbol_; CallChain current_callchain_; std::vector<CallChainEntry> callchain_entries_; + std::string build_id_string_; int update_flag_; std::vector<EventAttrWithName> event_attrs_; }; @@ -161,15 +168,21 @@ bool ReportLib::SetKallsymsFile(const char* kallsyms_file) { return true; } - -Sample* ReportLib::GetNextSample() { +bool ReportLib::OpenRecordFileIfNecessary() { if (record_file_reader_ == nullptr) { record_file_reader_ = RecordFileReader::CreateInstance(record_filename_); if (record_file_reader_ == nullptr) { - return nullptr; + return false; } record_file_reader_->LoadBuildIdAndFileFeatures(thread_tree_); } + return true; +} + +Sample* ReportLib::GetNextSample() { + if (!OpenRecordFileIfNecessary()) { + return nullptr; + } while (true) { std::unique_ptr<Record> record; if (!record_file_reader_->ReadRecord(record)) { @@ -236,6 +249,7 @@ SymbolEntry* ReportLib::GetSymbolOfCurrentSample() { current_symbol_.dso_name = map->dso->Path().c_str(); current_symbol_.vaddr_in_file = vaddr_in_file; current_symbol_.symbol_name = symbol->DemangledName(); + current_symbol_.symbol_addr = symbol->addr; update_flag_ |= UPDATE_FLAG_OF_SYMBOL; } return ¤t_symbol_; @@ -281,6 +295,7 @@ CallChain* ReportLib::GetCallChainOfCurrentSample() { entry.symbol.dso_name = map->dso->Path().c_str(); entry.symbol.vaddr_in_file = vaddr_in_file; entry.symbol.symbol_name = symbol->DemangledName(); + entry.symbol.symbol_addr = symbol->addr; callchain_entries_.push_back(entry); } } @@ -292,6 +307,20 @@ CallChain* ReportLib::GetCallChainOfCurrentSample() { return ¤t_callchain_; } +const char* ReportLib::GetBuildIdForPath(const char* path) { + if (!OpenRecordFileIfNecessary()) { + build_id_string_.clear(); + return build_id_string_.c_str(); + } + BuildId build_id = Dso::FindExpectedBuildIdForPath(path); + if (build_id.IsEmpty()) { + build_id_string_.clear(); + } else { + build_id_string_ = build_id.ToString(); + } + return build_id_string_.c_str(); +} + // Exported methods working with a client created instance ReportLib* CreateReportLib() { return new ReportLib(); @@ -336,3 +365,7 @@ SymbolEntry* GetSymbolOfCurrentSample(ReportLib* report_lib) { CallChain* GetCallChainOfCurrentSample(ReportLib* report_lib) { return report_lib->GetCallChainOfCurrentSample(); } + +const char* GetBuildIdForPath(ReportLib* report_lib, const char* path) { + return report_lib->GetBuildIdForPath(path); +} |