summaryrefslogtreecommitdiff
path: root/simpleperf
diff options
context:
space:
mode:
authorWei-Ning Huang <wnhuang@google.com>2024-03-22 00:49:18 +0800
committerWei-Ning Huang <wnhuang@google.com>2024-03-26 17:30:38 +0800
commitb3f184f5c87c6fd150770cb9ba7cfb40f8bdbc75 (patch)
tree8346a7bae2e842cb9aebf820af50f75f50c0bb1b /simpleperf
parent68d41126d5bb7931a5753da7effbf1d6f7482863 (diff)
downloadextras-b3f184f5c87c6fd150770cb9ba7cfb40f8bdbc75.tar.gz
simpleperf: report: add an option to specify symbol searching directory
Allow user to specify a directory containing symbols instead of needing a directory structure matching the dso path. This is useful for specifying symbols for dynamic libraries included in APKs such as libmonochrome_x64.so for chromium. Bug: none Test: `simpleperf report --lib DIR_WITH_SYMBOLS ...` `simpleperf_unit_test` Change-Id: Ifb1bef62899cfbe25594d1de4cf2f17574706926
Diffstat (limited to 'simpleperf')
-rw-r--r--simpleperf/cmd_report.cpp7
-rw-r--r--simpleperf/cmd_report_test.cpp24
2 files changed, 26 insertions, 5 deletions
diff --git a/simpleperf/cmd_report.cpp b/simpleperf/cmd_report.cpp
index 524174e4..f2fb527f 100644
--- a/simpleperf/cmd_report.cpp
+++ b/simpleperf/cmd_report.cpp
@@ -449,6 +449,7 @@ class ReportCommand : public Command {
" The default sort keys are:\n"
" comm,pid,tid,dso,symbol\n"
"--symfs <dir> Look for files with symbols relative to this directory.\n"
+"--symdir <dir> Look for files with symbols in a directory recursively.\n"
"--vmlinux <file> Parse kernel symbols from <file>.\n"
"\n"
"Sample filter options:\n"
@@ -585,6 +586,7 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) {
{"--sort", {OptionValueType::STRING, OptionType::SINGLE}},
{"--symbols", {OptionValueType::STRING, OptionType::MULTIPLE}},
{"--symfs", {OptionValueType::STRING, OptionType::SINGLE}},
+ {"--symdir", {OptionValueType::STRING, OptionType::SINGLE}},
{"--vmlinux", {OptionValueType::STRING, OptionType::SINGLE}},
};
OptionFormatMap record_filter_options = GetRecordFilterOptionFormats(false);
@@ -692,6 +694,11 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) {
return false;
}
}
+ if (auto value = options.PullValue("--symdir"); value) {
+ if (!Dso::AddSymbolDir(*value->str_value)) {
+ return false;
+ }
+ }
if (auto value = options.PullValue("--vmlinux"); value) {
Dso::SetVmlinux(*value->str_value);
}
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp
index 6dfbae5c..fcb9fac4 100644
--- a/simpleperf/cmd_report_test.cpp
+++ b/simpleperf/cmd_report_test.cpp
@@ -40,16 +40,23 @@ static std::unique_ptr<Command> ReportCmd() {
class ReportCommandTest : public ::testing::Test {
protected:
void Report(const std::string& perf_data,
- const std::vector<std::string>& add_args = std::vector<std::string>()) {
- ReportRaw(GetTestData(perf_data), add_args);
+ const std::vector<std::string>& add_args = std::vector<std::string>(),
+ bool with_symfs = true) {
+ ReportRaw(GetTestData(perf_data), add_args, with_symfs);
}
void ReportRaw(const std::string& perf_data,
- const std::vector<std::string>& add_args = std::vector<std::string>()) {
+ const std::vector<std::string>& add_args = std::vector<std::string>(),
+ bool with_symfs = true) {
success = false;
TemporaryFile tmp_file;
- std::vector<std::string> args = {"-i", perf_data, "--symfs", GetTestDataDir(),
- "-o", tmp_file.path};
+ std::vector<std::string> args = {"-i", perf_data, "-o", tmp_file.path};
+
+ if (with_symfs) {
+ args.emplace_back("--symfs");
+ args.emplace_back(GetTestDataDir());
+ }
+
args.insert(args.end(), add_args.begin(), add_args.end());
ASSERT_TRUE(ReportCmd()->Run(args));
ASSERT_TRUE(android::base::ReadFileToString(tmp_file.path, &content));
@@ -365,6 +372,13 @@ TEST_F(ReportCommandTest, report_dumped_symbols_with_symfs_dir) {
ASSERT_NE(content.find("main"), std::string::npos);
}
+TEST_F(ReportCommandTest, report_dumped_symbols_with_symdir) {
+ // Check if we can report symbols by specifying symdir.
+ Report(PERF_DATA, {"--symdir", GetTestDataDir()}, false);
+ ASSERT_TRUE(success);
+ ASSERT_NE(content.find("GlobalFunc"), std::string::npos);
+}
+
TEST_F(ReportCommandTest, report_without_symfs_dir) {
TemporaryFile tmpfile;
ASSERT_TRUE(ReportCmd()->Run({"-i", GetTestData(PERF_DATA), "-o", tmpfile.path}));