[PATCH] D109115: [llvm-profgen] Deduplicate and improve warning for truncated context

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 1 17:35:55 PDT 2021


wenlei created this revision.
wenlei added reviewers: hoy, wmi, wlei.
Herald added subscribers: modimo, lxfind.
wenlei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This change improves the warning for truncated context by: 1) deduplicate them as one call without probe can appear in many different context leading to duplicated warnings , 2) rephrase the message to make it easier to understand. The term "untracked frame" can be confusing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109115

Files:
  llvm/tools/llvm-profgen/PerfReader.cpp
  llvm/tools/llvm-profgen/PerfReader.h


Index: llvm/tools/llvm-profgen/PerfReader.h
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.h
+++ llvm/tools/llvm-profgen/PerfReader.h
@@ -13,6 +13,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Regex.h"
+#include <cstdint>
 #include <fstream>
 #include <list>
 #include <map>
@@ -411,13 +412,8 @@
     // Callsite merging may cause the loss of original probe IDs.
     // Cutting off the context from here since the inliner will
     // not know how to consume a context with unknown callsites.
-    if (!CallProbe) {
-      if (!Cur->isLeafFrame())
-        WithColor::warning()
-            << "Untracked frame at " << format("%" PRIx64, Cur->Address)
-            << " due to missing call probe\n";
+    if (!CallProbe)
       return false;
-    }
     Stack.push_back(CallProbe);
     return true;
   }
@@ -464,6 +460,7 @@
   VirtualUnwinder(ContextSampleCounterMap *Counter, const ProfiledBinary *B)
       : CtxCounterMap(Counter), Binary(B) {}
   bool unwind(const PerfSample *Sample, uint64_t Repeat);
+  std::set<uint64_t> &getUntrackedCallsites() { return UntrackedCallsites; }
 
 private:
   bool isCallState(UnwindState &State) const {
@@ -498,6 +495,8 @@
   ContextSampleCounterMap *CtxCounterMap;
   // Profiled binary that current frame address belongs to
   const ProfiledBinary *Binary;
+  // Keep track of all untracked callsites
+  std::set<uint64_t> UntrackedCallsites;
 };
 
 // Read perf trace to parse the events and samples.
Index: llvm/tools/llvm-profgen/PerfReader.cpp
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.cpp
+++ llvm/tools/llvm-profgen/PerfReader.cpp
@@ -153,6 +153,12 @@
       for (const auto &Item : Cur->Children) {
         collectSamplesFromFrameTrie(Item.second.get(), EmptyStack);
       }
+
+      // Keep note of untracked call site and deduplicate them
+      // for warning later.
+      if (!Cur->isLeafFrame())
+        UntrackedCallsites.insert(Cur->Address);
+
       return;
     }
   }
@@ -368,12 +374,22 @@
 }
 
 void HybridPerfReader::unwindSamples() {
+  std::set<uint64_t> AllUntrackedCallsites;
   for (const auto &Item : AggregatedSamples) {
     const PerfSample *Sample = Item.first.getPtr();
     VirtualUnwinder Unwinder(&SampleCounters, Binary);
     Unwinder.unwind(Sample, Item.second);
+    auto &CurrUntrackedCallsites = Unwinder.getUntrackedCallsites();
+    AllUntrackedCallsites.insert(CurrUntrackedCallsites.begin(),
+                                 CurrUntrackedCallsites.end());
   }
 
+  // Warn about untracked frames due to missing probes.
+  for (auto Address : AllUntrackedCallsites)
+    WithColor::warning() << "Profile context truncated due to missing probe "
+                         << "for call instructions at "
+                         << format("%" PRIx64, Address) << "\n";
+
   if (SkipSymbolization)
     PerfReaderBase::writeRawProfile(OutputFilename);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109115.370122.patch
Type: text/x-patch
Size: 3030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210902/76d6fe01/attachment.bin>


More information about the llvm-commits mailing list