simpleperf: support tracing offcpu time.
1. Add --trace-offcpu option in record command, to record the callstack
when a thread is scheduled off cpu.
2. Change the report command to report time spent not running on cpu
when --trace-offcpu option is used for recording.
3. Add related unittests and runtests.
Bug: http://b/37572306
Test: run simpleperf_unit_test.
Change-Id: Ia50cc39c8dde0c8fb1b1facbcb26bbd0a7ab1351
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp
index f1f5b1f..f1a9eb6 100644
--- a/simpleperf/cmd_report_test.cpp
+++ b/simpleperf/cmd_report_test.cpp
@@ -471,6 +471,21 @@
ASSERT_EQ(content.find("skipped in brief callgraph mode"), std::string::npos);
}
+TEST_F(ReportCommandTest, report_offcpu_time) {
+ Report(PERF_DATA_WITH_TRACE_OFFCPU, {"--children"});
+ ASSERT_TRUE(success);
+ ASSERT_NE(content.find("Time in ns"), std::string::npos);
+ bool found = false;
+ for (auto& line : lines) {
+ if (line.find("SleepFunction") != std::string::npos) {
+ ASSERT_NE(line.find("46.29%"), std::string::npos);
+ found = true;
+ break;
+ }
+ }
+ ASSERT_TRUE(found);
+}
+
#if defined(__linux__)
#include "event_selection_set.h"