diff options
author | Yabin Cui <yabinc@google.com> | 2020-07-15 11:58:41 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2020-07-17 13:20:06 -0700 |
commit | b60b33ca21a367f4b5e40406a6d26f2c5ca61b0d (patch) | |
tree | 2656bb2e7bc26ccee27d08e82bfadc2a34252b0c /simpleperf/cmd_record_test.cpp | |
parent | 3c5ea31c4dcd8b8f5d34cb97caa91692e4ca680b (diff) | |
download | extras-b60b33ca21a367f4b5e40406a6d26f2c5ca61b0d.tar.gz |
simpleperf: replace --include-filter with --addr-filter.
Add --addr-filter to use all filter functions provided by
the kernel and etm hardware. It supports:
1) starting/stopping tracing at selected instruction addresses.
2) only tracing instructions in selected addr ranges.
3) Both vaddrs in ELF files and kernel addrs can be used.
Bug: 161181704
Test: run simpleperf_unit_test.
Change-Id: Ie503fd0c35634a1bc006b67cc7a8faa64d58a421
Diffstat (limited to 'simpleperf/cmd_record_test.cpp')
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index e6656a2b..0c67e217 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -34,6 +34,7 @@ #include <regex> #include <thread> +#include "cmd_record_impl.h" #include "command.h" #include "environment.h" #include "ETMRecorder.h" @@ -44,6 +45,8 @@ #include "test_util.h" #include "thread_tree.h" +using android::base::Realpath; +using android::base::StringPrintf; using namespace simpleperf; using namespace PerfFileFormat; @@ -984,7 +987,7 @@ TEST(record_cmd, aux_buffer_size_option) { ASSERT_FALSE(RunRecordCmd({"-e", "cs-etm", "--aux-buffer-size", "12k"})); } -TEST(record_cmd, include_filter_option) { +TEST(record_cmd, addr_filter_option) { TEST_REQUIRE_HW_COUNTER(); if (!ETMRecorder::GetInstance().CheckEtmSupport()) { GTEST_LOG_(INFO) << "Omit this test since etm isn't supported on this device"; @@ -997,12 +1000,12 @@ TEST(record_cmd, include_filter_option) { pclose(fp); path = android::base::Trim(path); std::string sleep_exec_path; - ASSERT_TRUE(android::base::Realpath(path, &sleep_exec_path)); - // --include-filter doesn't apply to cpu-cycles. - ASSERT_FALSE(RunRecordCmd({"--include-filter", sleep_exec_path})); + ASSERT_TRUE(Realpath(path, &sleep_exec_path)); + // --addr-filter doesn't apply to cpu-cycles. + ASSERT_FALSE(RunRecordCmd({"--addr-filter", "filter " + sleep_exec_path})); TemporaryFile record_file; - ASSERT_TRUE( - RunRecordCmd({"-e", "cs-etm", "--include-filter", sleep_exec_path}, record_file.path)); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", "filter " + sleep_exec_path}, + record_file.path)); TemporaryFile inject_file; ASSERT_TRUE( CreateCommandInstance("inject")->Run({"-i", record_file.path, "-o", inject_file.path})); @@ -1015,6 +1018,36 @@ TEST(record_cmd, include_filter_option) { ASSERT_EQ(dso, sleep_exec_path); } } + + // Test if different filter types are accepted by the kernel. + auto elf = ElfFile::Open(sleep_exec_path); + uint64_t off; + uint64_t addr = elf->ReadMinExecutableVaddr(&off); + // file start + std::string filter = StringPrintf("start 0x%" PRIx64 "@%s", addr, sleep_exec_path.c_str()); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", filter})); + // file stop + filter = StringPrintf("stop 0x%" PRIx64 "@%s", addr, sleep_exec_path.c_str()); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", filter})); + // file range + filter = StringPrintf("filter 0x%" PRIx64 "-0x%" PRIx64 "@%s", addr, addr + 4, + sleep_exec_path.c_str()); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", filter})); + // TODO: enable kernel addr test after getting "perf/core: Fix crash when using HW tracing kernel + // filters" to android kernel 4.14. + if (false) { + // kernel start + uint64_t fake_kernel_addr = (1ULL << 63); + filter = StringPrintf("start 0x%" PRIx64, fake_kernel_addr); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", filter})); + // kernel stop + filter = StringPrintf("stop 0x%" PRIx64, fake_kernel_addr); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", filter})); + // kernel range + filter = + StringPrintf("filter 0x%" PRIx64 "-0x%" PRIx64, fake_kernel_addr, fake_kernel_addr + 4); + ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "--addr-filter", filter})); + } } TEST(record_cmd, pmu_event_option) { @@ -1070,3 +1103,30 @@ TEST(record_cmd, tp_filter_option) { ASSERT_EQ(data.find("prev_comm: sleep"), std::string::npos) << filter; } } + +TEST(record_cmd, ParseAddrFilterOption) { + auto option_to_str = [](const std::string& option) { + auto filters = ParseAddrFilterOption(option); + std::string s; + for (auto& filter : filters) { + if (!s.empty()) { + s += ','; + } + s += filter.ToString(); + } + return s; + }; + std::string path; + ASSERT_TRUE(Realpath(GetTestData(ELF_FILE), &path)); + + + // Test file filters. + ASSERT_EQ(option_to_str("filter " + path), "filter 0x0/0x73c@" + path); + ASSERT_EQ(option_to_str("filter 0x400502-0x400527@" + path), "filter 0x502/0x25@" + path); + ASSERT_EQ(option_to_str("start 0x400502@" + path + ",stop 0x400527@" + path), + "start 0x502@" + path + ",stop 0x527@" + path); + + // Test kernel filters. + ASSERT_EQ(option_to_str("filter 0x12345678-0x1234567a"), "filter 0x12345678/0x2"); + ASSERT_EQ(option_to_str("start 0x12345678,stop 0x1234567a"), "start 0x12345678,stop 0x1234567a"); +} |