summaryrefslogtreecommitdiff
path: root/simpleperf/cmd_report_test.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2021-12-22 11:45:30 -0800
committerYabin Cui <yabinc@google.com>2021-12-22 13:39:39 -0800
commit32b962795f47b97614242febbb37e939beeb20c7 (patch)
treefd09e510d2d6f8f49610eae6ef3d2c81e8946fbf /simpleperf/cmd_report_test.cpp
parent69bfaa797822101a20b0059b0a5e390aa88d4dbb (diff)
downloadextras-32b962795f47b97614242febbb37e939beeb20c7.tar.gz
simpleperf: add --print-event-count in report cmd.
--print-event-count is used to print event counts associated with each sample. The event counts can be added by --add-counter in record cmd. Bug: 211001574 Test: run simpleperf_unit_test Change-Id: I93f0760de0a8b10bb9ca4fa3dc4c71c0a2e80624
Diffstat (limited to 'simpleperf/cmd_report_test.cpp')
-rw-r--r--simpleperf/cmd_report_test.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp
index e7ce9c44..5104e8c7 100644
--- a/simpleperf/cmd_report_test.cpp
+++ b/simpleperf/cmd_report_test.cpp
@@ -564,6 +564,39 @@ TEST_F(ReportCommandTest, cpu_option) {
ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData("perf.data"), "--cpu", "-2"}));
}
+TEST_F(ReportCommandTest, print_event_count_option) {
+ // Report record file not recorded with --add-counter.
+ Report("perf.data", {"--print-event-count"});
+ ASSERT_TRUE(success);
+ ASSERT_NE(content.find("EventCount"), std::string::npos);
+ ASSERT_TRUE(std::regex_search(
+ content, std::regex(R"(325005586\s+elf\s+26083\s+26083\s+/elf\s+GlobalFunc)")));
+
+ // Report record file recorded with --add-counter.
+ const std::string record_file = "perf_with_add_counter.data";
+ Report(record_file, {"--print-event-count"});
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(
+ std::regex_search(content, std::regex(R"(EventCount_cpu-cycles\s+EventCount_instructions)")));
+ ASSERT_TRUE(std::regex_search(
+ content, std::regex(R"(175099\s+140443\s+sleep\s+689664\s+689664.+_dl_addr)")));
+
+ // Report accumulated event counts.
+ Report(record_file, {"--print-event-count", "--children"});
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(std::regex_search(
+ content,
+ std::regex(
+ R"(AccEventCount_cpu-cycles\s+SelfEventCount_cpu-cycles\s+AccEventCount_instructions\s+)"
+ R"(SelfEventCount_instructions)")));
+ ASSERT_TRUE(std::regex_search(
+ content,
+ std::regex(R"(175099\s+175099\s+140443\s+140443\s+sleep\s+689664\s+689664.+_dl_addr)")));
+ ASSERT_TRUE(std::regex_search(
+ content,
+ std::regex(R"(366116\s+0\s+297474\s+0\s+sleep\s+689664\s+689664.+__libc_start_main)")));
+}
+
#if defined(__linux__)
#include "event_selection_set.h"