summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2021-08-24 10:22:50 -0700
committerYabin Cui <yabinc@google.com>2021-08-24 10:22:50 -0700
commit8036c96373349698b35464db457679a03cd693a7 (patch)
treed2e934fbe36d8591015cc72d9f8752c3ab29414e
parent02af000e94f99f9c5fb46794b7268878cbc77fbd (diff)
downloadextras-8036c96373349698b35464db457679a03cd693a7.tar.gz
simpleperf: extend --percent-limit to report entries.
Bug: 197549395 Test: run simpleperf_unit_test Change-Id: Ie8f8603605dc59a92991546abe4c6233355d8dd5
-rw-r--r--simpleperf/SampleDisplayer.h11
-rw-r--r--simpleperf/cmd_report.cpp19
-rw-r--r--simpleperf/cmd_report_test.cpp11
3 files changed, 35 insertions, 6 deletions
diff --git a/simpleperf/SampleDisplayer.h b/simpleperf/SampleDisplayer.h
index cc27a46c..05724a04 100644
--- a/simpleperf/SampleDisplayer.h
+++ b/simpleperf/SampleDisplayer.h
@@ -20,6 +20,7 @@
#include <inttypes.h>
#include <functional>
+#include <optional>
#include <string>
#include <android-base/logging.h>
@@ -199,6 +200,9 @@ class SampleDisplayer {
public:
void SetInfo(const InfoT* info) { info_ = info; }
void SetReportFormat(bool report_csv) { report_csv_ = report_csv; }
+ void SetFilterFunction(const std::function<bool(const EntryT*, const InfoT*)>& filter) {
+ filter_func_ = filter;
+ }
void AddDisplayFunction(const std::string& name, display_sample_func_t func) {
Item item;
@@ -226,6 +230,9 @@ class SampleDisplayer {
if (report_csv_) {
return;
}
+ if (filter_func_ && !filter_func_.value()(sample, info_)) {
+ return;
+ }
for (auto& item : display_v_) {
std::string data =
(item.func != nullptr) ? item.func(sample) : item.func_with_info(sample, info_);
@@ -249,6 +256,9 @@ class SampleDisplayer {
}
void PrintSample(FILE* fp, const EntryT* sample) {
+ if (filter_func_ && !filter_func_.value()(sample, info_)) {
+ return;
+ }
for (size_t i = 0; i < display_v_.size(); ++i) {
auto& item = display_v_[i];
std::string data =
@@ -277,6 +287,7 @@ class SampleDisplayer {
const InfoT* info_;
std::vector<Item> display_v_;
std::vector<exclusive_display_sample_func_t> exclusive_display_v_;
+ std::optional<std::function<bool(const EntryT*, const InfoT*)>> filter_func_;
bool report_csv_ = false;
};
diff --git a/simpleperf/cmd_report.cpp b/simpleperf/cmd_report.cpp
index 399e4d82..0819b6e9 100644
--- a/simpleperf/cmd_report.cpp
+++ b/simpleperf/cmd_report.cpp
@@ -389,7 +389,7 @@ class ReportCommand : public Command {
"--no-demangle Don't demangle symbol names.\n"
"--no-show-ip Don't show vaddr in file for unknown symbols.\n"
"-o report_file_name Set report file name, default is stdout.\n"
-"--percent-limit <percent> Set min percentage shown when printing call graph.\n"
+"--percent-limit <percent> Set min percentage in report entries and call graphs.\n"
"--pids pid1,pid2,... Report only for selected pids.\n"
"--raw-period Report period count instead of period percentage.\n"
"--sort key1,key2,... Select keys used to sort and print the report. The\n"
@@ -425,7 +425,7 @@ class ReportCommand : public Command {
print_callgraph_(false),
callgraph_show_callee_(false),
callgraph_max_stack_(UINT32_MAX),
- callgraph_percent_limit_(0),
+ percent_limit_(0),
raw_period_(false),
brief_callgraph_(true),
trace_offcpu_(false),
@@ -466,7 +466,7 @@ class ReportCommand : public Command {
bool print_callgraph_;
bool callgraph_show_callee_;
uint32_t callgraph_max_stack_;
- double callgraph_percent_limit_;
+ double percent_limit_;
bool raw_period_;
bool brief_callgraph_;
bool trace_offcpu_;
@@ -597,7 +597,7 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) {
}
options.PullStringValue("-o", &report_filename_);
- if (!options.PullDoubleValue("--percent-limit", &callgraph_percent_limit_, 0)) {
+ if (!options.PullDoubleValue("--percent-limit", &percent_limit_, 0)) {
return false;
}
@@ -729,12 +729,19 @@ bool ReportCommand::BuildSampleComparatorAndDisplayer(bool print_sample_count,
if (has_vaddr_in_file_key) {
displayer.AddExclusiveDisplayFunction(ReportCmdCallgraphDisplayerWithVaddrInFile());
} else {
- displayer.AddExclusiveDisplayFunction(ReportCmdCallgraphDisplayer(
- callgraph_max_stack_, callgraph_percent_limit_, brief_callgraph_));
+ displayer.AddExclusiveDisplayFunction(
+ ReportCmdCallgraphDisplayer(callgraph_max_stack_, percent_limit_, brief_callgraph_));
}
}
}
+ if (percent_limit_ != 0.0) {
+ displayer.SetFilterFunction([this](const SampleEntry* sample, const SampleTree* sample_tree) {
+ uint64_t total_period = sample->period + sample->accumulated_period;
+ return total_period >= sample_tree->total_period * percent_limit_ / 100.0;
+ });
+ }
+
sample_tree_builder_options_.comparator = comparator;
sample_tree_builder_options_.thread_tree = &thread_tree_;
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp
index fb79c931..10ec2d76 100644
--- a/simpleperf/cmd_report_test.cpp
+++ b/simpleperf/cmd_report_test.cpp
@@ -443,6 +443,17 @@ TEST_F(ReportCommandTest, max_stack_and_percent_limit_option) {
ASSERT_NE(content.find("89.03"), std::string::npos);
}
+TEST_F(ReportCommandTest, percent_limit_option) {
+ Report(PERF_DATA);
+ ASSERT_TRUE(success);
+ ASSERT_NE(content.find("7.70%"), std::string::npos);
+ ASSERT_NE(content.find("3.23%"), std::string::npos);
+ Report(PERF_DATA, {"--percent-limit", "3.24"});
+ ASSERT_TRUE(success);
+ ASSERT_NE(content.find("7.70%"), std::string::npos);
+ ASSERT_EQ(content.find("3.23%"), std::string::npos);
+}
+
TEST_F(ReportCommandTest, kallsyms_option) {
Report(PERF_DATA, {"--kallsyms", GetTestData("kallsyms")});
ASSERT_TRUE(success);