OSDN Git Service

simpleperf: fix a bug setting symfs dir.
authorYabin Cui <yabinc@google.com>
Tue, 13 Nov 2018 19:09:20 +0000 (11:09 -0800)
committerYabin Cui <yabinc@google.com>
Tue, 13 Nov 2018 19:38:05 +0000 (11:38 -0800)
Bug: 119438870
Test: run simpleperf_unit_test.
Test: run simpleperf manually.

Change-Id: I2f7ca659dc3a9833650f326ff5560fef44e769a5

simpleperf/cmd_report.cpp
simpleperf/cmd_report_test.cpp

index 1a4cb4c..e6f5dab 100644 (file)
@@ -508,7 +508,6 @@ bool ReportCommand::Run(const std::vector<std::string>& args) {
 bool ReportCommand::ParseOptions(const std::vector<std::string>& args) {
   bool demangle = true;
   bool show_ip_for_unknown_symbol = true;
-  std::string symfs_dir;
   std::string vmlinux;
   bool print_sample_count = false;
   std::vector<std::string> sort_keys = {"comm", "pid", "tid", "dso", "symbol"};
@@ -613,8 +612,9 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) {
       if (!NextArgumentOrError(args, &i)) {
         return false;
       }
-      symfs_dir = args[i];
-
+      if (!Dso::SetSymFsDir(args[i])) {
+        return false;
+      }
     } else if (args[i] == "--vmlinux") {
       if (!NextArgumentOrError(args, &i)) {
         return false;
@@ -627,9 +627,6 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) {
   }
 
   Dso::SetDemangle(demangle);
-  if (!Dso::SetSymFsDir(symfs_dir)) {
-    return false;
-  }
   if (!vmlinux.empty()) {
     Dso::SetVmlinux(vmlinux);
   }
index 03a67bd..a767030 100644 (file)
@@ -351,6 +351,11 @@ TEST_F(ReportCommandTest, report_dumped_symbols_with_symfs_dir) {
   ASSERT_NE(content.find("main"), std::string::npos);
 }
 
+TEST_F(ReportCommandTest, report_without_symfs_dir) {
+  TemporaryFile tmpfile;
+  ASSERT_TRUE(ReportCmd()->Run({"-i", GetTestData(PERF_DATA), "-o", tmpfile.path}));
+}
+
 TEST_F(ReportCommandTest, report_sort_vaddr_in_file) {
   Report(PERF_DATA, {"--sort", "vaddr_in_file"});
   ASSERT_TRUE(success);