summaryrefslogtreecommitdiff
path: root/simpleperf/report_lib_interface.cpp
diff options
context:
space:
mode:
authorDaniel Friederich <dfriederich@magicleap.com>2016-10-12 09:41:09 -0500
committerDaniel Friederich <dfriederich@magicleap.com>2016-11-14 16:38:47 -0600
commit0e48e18171e17c76834916c2c87360195edf8667 (patch)
tree8aacac433aca2ea64689ebd44abc5d6fdf704c54 /simpleperf/report_lib_interface.cpp
parentee71d0b6a8e00630d4af34d5be7acb2369855e33 (diff)
downloadextras-0e48e18171e17c76834916c2c87360195edf8667.tar.gz
Support for multiple instances
Allows to use separate instances for separate perf.datai files (and possibly also separate instances on separate threads) Test: Tested by running report_sample.py Change-Id: I0ebdb3c650a4540f07237b515d451d69ec3810e6
Diffstat (limited to 'simpleperf/report_lib_interface.cpp')
-rw-r--r--simpleperf/report_lib_interface.cpp75
1 files changed, 45 insertions, 30 deletions
diff --git a/simpleperf/report_lib_interface.cpp b/simpleperf/report_lib_interface.cpp
index 3653e0d7..cdd9fb1c 100644
--- a/simpleperf/report_lib_interface.cpp
+++ b/simpleperf/report_lib_interface.cpp
@@ -24,6 +24,8 @@
#include "thread_tree.h"
#include "utils.h"
+class ReportLib;
+
extern "C" {
#define EXPORT __attribute__((visibility("default")))
@@ -59,17 +61,22 @@ struct CallChain {
CallChainEntry* entries;
};
+// Create a new instance,
+// pass the instance to the other functions below.
+ReportLib* CreateReportLib() EXPORT;
+void DestroyReportLib(ReportLib* report_lib) EXPORT;
+
// Set log severity, different levels are:
// verbose, debug, info, warning, error, fatal.
-bool SetLogSeverity(const char* log_level) EXPORT;
-bool SetSymfs(const char* symfs_dir) EXPORT;
-bool SetRecordFile(const char* record_file) EXPORT;
-void ShowIpForUnknownSymbol() EXPORT;
-
-Sample* GetNextSample() EXPORT;
-Event* GetEventOfCurrentSample() EXPORT;
-SymbolEntry* GetSymbolOfCurrentSample() EXPORT;
-CallChain* GetCallChainOfCurrentSample() EXPORT;
+bool SetLogSeverity(ReportLib* report_lib, const char* log_level) EXPORT;
+bool SetSymfs(ReportLib* report_lib, const char* symfs_dir) EXPORT;
+bool SetRecordFile(ReportLib* report_lib, const char* record_file) EXPORT;
+void ShowIpForUnknownSymbol(ReportLib* report_lib) EXPORT;
+
+Sample* GetNextSample(ReportLib* report_lib) EXPORT;
+Event* GetEventOfCurrentSample(ReportLib* report_lib) EXPORT;
+SymbolEntry* GetSymbolOfCurrentSample(ReportLib* report_lib) EXPORT;
+CallChain* GetCallChainOfCurrentSample(ReportLib* report_lib) EXPORT;
}
struct EventAttrWithName {
@@ -90,12 +97,9 @@ class ReportLib {
: log_severity_(
new android::base::ScopedLogSeverity(android::base::INFO)),
record_filename_("perf.data"),
- update_flag_(0) {}
-
- static ReportLib& GetInstance() {
- static ReportLib lib;
- return lib;
- }
+ current_thread_(nullptr),
+ update_flag_(0)
+ {}
bool SetLogSeverity(const char* log_level);
@@ -272,32 +276,43 @@ CallChain* ReportLib::GetCallChainOfCurrentSample() {
return &current_callchain_;
}
-bool SetLogSeverity(const char* log_level) {
- return ReportLib::GetInstance().SetLogSeverity(log_level);
+// Exported methods working with a client created instance
+ReportLib* CreateReportLib() {
+ return new ReportLib();
}
-bool SetSymfs(const char* symfs_dir) {
- return ReportLib::GetInstance().SetSymfs(symfs_dir);
+void DestroyReportLib(ReportLib* report_lib) {
+ delete report_lib;
}
-bool SetRecordFile(const char* record_file) {
- return ReportLib::GetInstance().SetRecordFile(record_file);
+bool SetLogSeverity(ReportLib* report_lib, const char* log_level) {
+ return report_lib->SetLogSeverity(log_level);
}
-void ShowIpForUnknownSymbol() {
- return ReportLib::GetInstance().ShowIpForUnknownSymbol();
+bool SetSymfs(ReportLib* report_lib, const char* symfs_dir) {
+ return report_lib->SetSymfs(symfs_dir);
}
-Sample* GetNextSample() { return ReportLib::GetInstance().GetNextSample(); }
+bool SetRecordFile(ReportLib* report_lib, const char* record_file) {
+ return report_lib->SetRecordFile(record_file);
+}
+
+void ShowIpForUnknownSymbol(ReportLib* report_lib) {
+ return report_lib->ShowIpForUnknownSymbol();
+}
+
+Sample* GetNextSample(ReportLib* report_lib) {
+ return report_lib->GetNextSample();
+}
-Event* GetEventOfCurrentSample() {
- return ReportLib::GetInstance().GetEventOfCurrentSample();
+Event* GetEventOfCurrentSample(ReportLib* report_lib) {
+ return report_lib->GetEventOfCurrentSample();
}
-SymbolEntry* GetSymbolOfCurrentSample() {
- return ReportLib::GetInstance().GetSymbolOfCurrentSample();
+SymbolEntry* GetSymbolOfCurrentSample(ReportLib* report_lib) {
+ return report_lib->GetSymbolOfCurrentSample();
}
-CallChain* GetCallChainOfCurrentSample() {
- return ReportLib::GetInstance().GetCallChainOfCurrentSample();
+CallChain* GetCallChainOfCurrentSample(ReportLib* report_lib) {
+ return report_lib->GetCallChainOfCurrentSample();
}