OSDN Git Service

Simpleperf: always use the latest comm.
authorYabin Cui <yabinc@google.com>
Thu, 11 Jun 2015 20:49:59 +0000 (13:49 -0700)
committerYabin Cui <yabinc@google.com>
Thu, 11 Jun 2015 20:49:59 +0000 (13:49 -0700)
Bug: 19483574
Change-Id: Ie314bdce7a61aeda679ea9d1bbe5e05436a22edc

simpleperf/sample_tree.cpp

index 5c359e8..12df6d5 100644 (file)
@@ -37,6 +37,11 @@ bool SampleTree::MapComparator::operator()(const MapEntry* map1, const MapEntry*
 }
 
 void SampleTree::AddProcess(int pid, const std::string& comm) {
+  auto it = process_tree_.find(pid);
+  if (it != process_tree_.end()) {
+    it->second->comm = comm;
+    return;
+  }
   ProcessEntry* process = new ProcessEntry{
       .pid = pid, .comm = comm,
   };
@@ -111,12 +116,8 @@ void SampleTree::RemoveOverlappedUserMap(const MapEntry* map) {
 const ProcessEntry* SampleTree::FindProcessEntryOrNew(int pid) {
   auto it = process_tree_.find(pid);
   if (it == process_tree_.end()) {
-    ProcessEntry* process = new ProcessEntry{
-        .pid = pid, .comm = "unknown",
-    };
-    auto pair = process_tree_.insert(std::make_pair(pid, std::unique_ptr<ProcessEntry>(process)));
-    it = pair.first;
-    CHECK(pair.second);
+    AddProcess(pid, "unknown");
+    it = process_tree_.find(pid);
   }
   return it->second.get();
 }