summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2023-05-01 16:19:03 -0700
committerYabin Cui <yabinc@google.com>2023-05-03 17:23:53 -0700
commite1ee3530c6399da8f60a12e50a4150ee975da070 (patch)
tree1210df935fdb8153fd688e0c6f25f15a37660821
parentadbb6341047d414fe1f7c373f7d4a246de13471b (diff)
downloadextras-e1ee3530c6399da8f60a12e50a4150ee975da070.tar.gz
simpleperf: Support --exclude-perf when recording with --decode-etm
Bug: 279094308 Test: run simpleperf_unit_test Test: run simpleperf manually (cherry picked from https://android-review.googlesource.com/q/commit:4574ead0dfa02fb3c94d19593f2c267318b09d47) Merged-In: Ia17ab3359e6e2dd81b7667adb558503661990d22 Change-Id: Ia17ab3359e6e2dd81b7667adb558503661990d22
-rw-r--r--simpleperf/ETMBranchListFile.cpp7
-rw-r--r--simpleperf/ETMBranchListFile.h1
-rw-r--r--simpleperf/cmd_record.cpp6
-rw-r--r--simpleperf/cmd_record_test.cpp1
4 files changed, 15 insertions, 0 deletions
diff --git a/simpleperf/ETMBranchListFile.cpp b/simpleperf/ETMBranchListFile.cpp
index a3dd8fda..a5b78252 100644
--- a/simpleperf/ETMBranchListFile.cpp
+++ b/simpleperf/ETMBranchListFile.cpp
@@ -166,6 +166,7 @@ class ETMThreadTreeWhenRecording : public ETMThreadTree {
: dump_maps_from_proc_(dump_maps_from_proc) {}
ThreadTree& GetThreadTree() { return thread_tree_; }
+ void ExcludePid(pid_t pid) { exclude_pid_ = pid; }
const ThreadEntry* FindThread(int tid) override {
const ThreadEntry* thread = thread_tree_.FindThread(tid);
@@ -177,6 +178,9 @@ class ETMThreadTreeWhenRecording : public ETMThreadTree {
return nullptr;
}
}
+ if (exclude_pid_ && exclude_pid_ == thread->pid) {
+ return nullptr;
+ }
if (dump_maps_from_proc_) {
DumpMapsFromProc(thread->pid);
@@ -213,12 +217,15 @@ class ETMThreadTreeWhenRecording : public ETMThreadTree {
ThreadTree thread_tree_;
bool dump_maps_from_proc_;
std::unordered_set<int> dumped_processes_;
+ std::optional<pid_t> exclude_pid_;
};
class ETMBranchListGeneratorImpl : public ETMBranchListGenerator {
public:
ETMBranchListGeneratorImpl(bool dump_maps_from_proc) : thread_tree_(dump_maps_from_proc) {}
+ void SetExcludePid(pid_t pid) override { thread_tree_.ExcludePid(pid); }
+
bool ProcessRecord(const Record& r, bool& consumed) override;
BranchListBinaryMap GetBranchListBinaryMap() override;
diff --git a/simpleperf/ETMBranchListFile.h b/simpleperf/ETMBranchListFile.h
index bb6d7335..ba30fcd1 100644
--- a/simpleperf/ETMBranchListFile.h
+++ b/simpleperf/ETMBranchListFile.h
@@ -110,6 +110,7 @@ class ETMBranchListGenerator {
static std::unique_ptr<ETMBranchListGenerator> Create(bool dump_maps_from_proc);
virtual ~ETMBranchListGenerator();
+ virtual void SetExcludePid(pid_t pid) = 0;
virtual bool ProcessRecord(const Record& r, bool& consumed) = 0;
virtual BranchListBinaryMap GetBranchListBinaryMap() = 0;
};
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index 21b5e50d..04c0448c 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -754,6 +754,12 @@ bool RecordCommand::PrepareRecording(Workload* workload) {
if (!loop->AddPeriodicEvent(SecondToTimeval(kDefaultEtmDataFlushPeriodInSec), etm_flush)) {
return false;
}
+
+ if (etm_branch_list_generator_) {
+ if (exclude_perf_) {
+ etm_branch_list_generator_->SetExcludePid(getpid());
+ }
+ }
}
return true;
}
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index 4e06cd68..630931c6 100644
--- a/simpleperf/cmd_record_test.cpp
+++ b/simpleperf/cmd_record_test.cpp
@@ -1062,6 +1062,7 @@ TEST(record_cmd, decode_etm_option) {
return;
}
ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--decode-etm"}));
+ ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--decode-etm", "--exclude-perf"}));
}
TEST(record_cmd, pmu_event_option) {