OSDN Git Service

simpleperf: dump all process maps for etm system wide recording.
authorYabin Cui <yabinc@google.com>
Sat, 11 Jan 2020 00:00:11 +0000 (16:00 -0800)
committerYabin Cui <yabinc@google.com>
Sat, 11 Jan 2020 00:02:13 +0000 (16:02 -0800)
If don't dump all process maps, we may miss mapping info needed
to decode etm data.

Bug: 79161490
Test: run simpleperf manually.
Test: run simpleperf_unit_test.
Change-Id: Ic98d1b461b2c11a51147c67e8f269d5be10e962b

simpleperf/cmd_record.cpp

index 2208503..23ffd24 100644 (file)
@@ -1174,21 +1174,29 @@ bool RecordCommand::DumpKernelMaps() {
 }
 
 bool RecordCommand::DumpUserSpaceMaps() {
-  // For system_wide profiling, maps of a process is dumped when needed (first time a sample hits
-  // that process).
-  if (system_wide_collection_) {
+  // For system_wide profiling:
+  //   If no aux tracing, maps of a process is dumped when needed (first time a sample hits
+  //     that process).
+  //   If aux tracing, we don't know which maps will be needed, so dump all process maps.
+  if (system_wide_collection_ && !event_selection_set_.HasAuxTrace()) {
     return true;
   }
   // Map from process id to a set of thread ids in that process.
   std::unordered_map<pid_t, std::unordered_set<pid_t>> process_map;
-  for (pid_t pid : event_selection_set_.GetMonitoredProcesses()) {
-    std::vector<pid_t> tids = GetThreadsInProcess(pid);
-    process_map[pid].insert(tids.begin(), tids.end());
-  }
-  for (pid_t tid : event_selection_set_.GetMonitoredThreads()) {
-    pid_t pid;
-    if (GetProcessForThread(tid, &pid)) {
-      process_map[pid].insert(tid);
+  if (system_wide_collection_) {
+    for (auto pid : GetAllProcesses()) {
+      process_map[pid] = std::unordered_set<pid_t>();
+    }
+  } else {
+    for (pid_t pid : event_selection_set_.GetMonitoredProcesses()) {
+      std::vector<pid_t> tids = GetThreadsInProcess(pid);
+      process_map[pid].insert(tids.begin(), tids.end());
+    }
+    for (pid_t tid : event_selection_set_.GetMonitoredThreads()) {
+      pid_t pid;
+      if (GetProcessForThread(tid, &pid)) {
+        process_map[pid].insert(tid);
+      }
     }
   }