From 6bf8ca070ef6e2834b21cd0a4271fbc1b6fb92d2 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 16 Jul 2015 10:20:55 -0700 Subject: Simpleperf: dump thread comm/mmaps for selected threads. Bug: 22511834 Change-Id: I2775b3a4cd393d75d5c6ebcd8a46e366ceb4ff76 --- simpleperf/cmd_record.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'simpleperf') diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 71c4e4cd..dd77ec3c 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -119,7 +119,7 @@ class RecordCommand : public Command { bool SetEventSelection(); bool WriteData(const char* data, size_t size); bool DumpKernelAndModuleMmaps(); - bool DumpThreadCommAndMmaps(); + bool DumpThreadCommAndMmaps(bool all_threads, const std::vector& selected_threads); bool DumpAdditionalFeatures(const std::vector& args); bool DumpBuildIdFeature(); @@ -207,7 +207,7 @@ bool RecordCommand::Run(const std::vector& args) { if (!DumpKernelAndModuleMmaps()) { return false; } - if (system_wide_collection_ && !DumpThreadCommAndMmaps()) { + if (!DumpThreadCommAndMmaps(system_wide_collection_, monitored_threads_)) { return false; } @@ -431,11 +431,24 @@ bool RecordCommand::DumpKernelAndModuleMmaps() { return true; } -bool RecordCommand::DumpThreadCommAndMmaps() { +bool RecordCommand::DumpThreadCommAndMmaps(bool all_threads, + const std::vector& selected_threads) { std::vector thread_comms; if (!GetThreadComms(&thread_comms)) { return false; } + // Decide which processes and threads to dump. + std::set dump_processes; + std::set dump_threads; + for (auto& tid : selected_threads) { + dump_threads.insert(tid); + } + for (auto& thread : thread_comms) { + if (dump_threads.find(thread.tid) != dump_threads.end()) { + dump_processes.insert(thread.pid); + } + } + const perf_event_attr& attr = event_selection_set_.FindEventAttrByType(measured_event_type_modifier_->event_type); @@ -444,6 +457,9 @@ bool RecordCommand::DumpThreadCommAndMmaps() { if (thread.pid != thread.tid) { continue; } + if (!all_threads && dump_processes.find(thread.pid) == dump_processes.end()) { + continue; + } CommRecord record = CreateCommRecord(attr, thread.pid, thread.tid, thread.comm); if (!record_file_writer_->WriteData(record.BinaryFormat())) { return false; @@ -471,6 +487,9 @@ bool RecordCommand::DumpThreadCommAndMmaps() { if (thread.pid == thread.tid) { continue; } + if (!all_threads && dump_threads.find(thread.tid) == dump_threads.end()) { + continue; + } ForkRecord fork_record = CreateForkRecord(attr, thread.pid, thread.tid, thread.pid, thread.pid); if (!record_file_writer_->WriteData(fork_record.BinaryFormat())) { return false; -- cgit v1.2.3