From 2d6efe4b167da4e6b77f168b1820239ee65599e2 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Fri, 1 Apr 2016 20:22:35 -0700 Subject: simpleperf: support reporting more than one event type. When sampling kernel trace points, it is like to sample more than one even type. Like `simpleperf record -e kmem:mm_page_alloc,kmem:mm_page_free`. 1. change record command to dump event_id for all records. 2. change report command and record reader to support multiple event attrs. 3. hide record_cache inside EventSelectionSet. 4. add test to report multiple event types. Bug: 27403614 Change-Id: Ic22a5527d68e7a843e3cf95e85381f8ad6bcb196 --- simpleperf/cmd_report.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'simpleperf/cmd_report.cpp') diff --git a/simpleperf/cmd_report.cpp b/simpleperf/cmd_report.cpp index b9c3d6f7..db7f8a35 100644 --- a/simpleperf/cmd_report.cpp +++ b/simpleperf/cmd_report.cpp @@ -306,7 +306,7 @@ class ReportCommand : public Command { std::string record_filename_; ArchType record_file_arch_; std::unique_ptr record_file_reader_; - perf_event_attr event_attr_; + std::vector event_attrs_; std::vector> displayable_items_; std::vector comparable_items_; ThreadTree thread_tree_; @@ -515,15 +515,22 @@ bool ReportCommand::ParseOptions(const std::vector& args) { } bool ReportCommand::ReadEventAttrFromRecordFile() { - const std::vector& attrs = record_file_reader_->AttrSection(); - if (attrs.size() != 1) { - LOG(ERROR) << "record file contains " << attrs.size() << " attrs"; - return false; - } - event_attr_ = attrs[0].attr; - if (use_branch_address_ && (event_attr_.sample_type & PERF_SAMPLE_BRANCH_STACK) == 0) { - LOG(ERROR) << record_filename_ << " is not recorded with branch stack sampling option."; - return false; + const std::vector& file_attrs = record_file_reader_->AttrSection(); + for (const auto& attr : file_attrs) { + event_attrs_.push_back(attr.attr); + } + if (use_branch_address_) { + bool has_branch_stack = true; + for (const auto& attr : event_attrs_) { + if ((attr.sample_type & PERF_SAMPLE_BRANCH_STACK) == 0) { + has_branch_stack = false; + break; + } + } + if (!has_branch_stack) { + LOG(ERROR) << record_filename_ << " is not recorded with branch stack sampling option."; + return false; + } } return true; } @@ -706,19 +713,18 @@ bool ReportCommand::PrintReport() { } void ReportCommand::PrintReportContext() { - const EventType* event_type = FindEventTypeByConfig(event_attr_.type, event_attr_.config); - std::string event_type_name; - if (event_type != nullptr) { - event_type_name = event_type->name; - } else { - event_type_name = - android::base::StringPrintf("(type %u, config %llu)", event_attr_.type, event_attr_.config); - } if (!record_cmdline_.empty()) { fprintf(report_fp_, "Cmdline: %s\n", record_cmdline_.c_str()); } - fprintf(report_fp_, "Samples: %" PRIu64 " of event '%s'\n", sample_tree_->TotalSamples(), - event_type_name.c_str()); + for (const auto& attr : event_attrs_) { + const EventType* event_type = FindEventTypeByConfig(attr.type, attr.config); + std::string name; + if (event_type != nullptr) { + name = event_type->name; + } + fprintf(report_fp_, "Event: %s (type %u, config %llu)\n", name.c_str(), attr.type, attr.config); + } + fprintf(report_fp_, "Samples: %" PRIu64 "\n", sample_tree_->TotalSamples()); fprintf(report_fp_, "Event count: %" PRIu64 "\n\n", sample_tree_->TotalPeriod()); } -- cgit v1.2.3