[PATCH] D123067: Allow building heatmaps from basic sampled events with `-nl`.

Rahman Lavaee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 4 12:59:18 PDT 2022


rahmanl created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
rahmanl requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

I find that this is useful for finding event hotspots.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123067

Files:
  bolt/lib/Profile/DataAggregator.cpp


Index: bolt/lib/Profile/DataAggregator.cpp
===================================================================
--- bolt/lib/Profile/DataAggregator.cpp
+++ bolt/lib/Profile/DataAggregator.cpp
@@ -1296,37 +1296,55 @@
   uint64_t NumTotalSamples = 0;
 
   while (hasData()) {
-    ErrorOr<PerfBranchSample> SampleRes = parseBranchSample();
-    if (std::error_code EC = SampleRes.getError()) {
-      if (EC == errc::no_such_process)
-        continue;
-      return EC;
-    }
-
-    PerfBranchSample &Sample = SampleRes.get();
+    if (opts::BasicAggregation) {
+      ErrorOr<PerfBasicSample> SampleRes = parseBasicSample();
+      if (std::error_code EC = SampleRes.getError()) {
+        if (EC == errc::no_such_process)
+          continue;
+        return EC;
+      }
+      PerfBasicSample &Sample = SampleRes.get();
+      HM.registerAddress(Sample.PC);
+      NumTotalSamples++;
+    } else {
+      ErrorOr<PerfBranchSample> SampleRes = parseBranchSample();
+      if (std::error_code EC = SampleRes.getError()) {
+        if (EC == errc::no_such_process)
+          continue;
+        return EC;
+      }
 
-    // LBRs are stored in reverse execution order. NextLBR refers to the next
-    // executed branch record.
-    const LBREntry *NextLBR = nullptr;
-    for (const LBREntry &LBR : Sample.LBR) {
-      if (NextLBR) {
-        // Record fall-through trace.
-        const uint64_t TraceFrom = LBR.To;
-        const uint64_t TraceTo = NextLBR->From;
-        ++FallthroughLBRs[Trace(TraceFrom, TraceTo)].InternCount;
+      PerfBranchSample &Sample = SampleRes.get();
+
+      // LBRs are stored in reverse execution order. NextLBR refers to the next
+      // executed branch record.
+      const LBREntry *NextLBR = nullptr;
+      for (const LBREntry &LBR : Sample.LBR) {
+        if (NextLBR) {
+          // Record fall-through trace.
+          const uint64_t TraceFrom = LBR.To;
+          const uint64_t TraceTo = NextLBR->From;
+          ++FallthroughLBRs[Trace(TraceFrom, TraceTo)].InternCount;
+        }
+        NextLBR = &LBR;
       }
-      NextLBR = &LBR;
-    }
-    if (!Sample.LBR.empty()) {
-      HM.registerAddress(Sample.LBR.front().To);
-      HM.registerAddress(Sample.LBR.back().From);
+      if (!Sample.LBR.empty()) {
+        HM.registerAddress(Sample.LBR.front().To);
+        HM.registerAddress(Sample.LBR.back().From);
+      }
+      NumTotalSamples += Sample.LBR.size();
     }
-    NumTotalSamples += Sample.LBR.size();
   }
 
   if (!NumTotalSamples) {
-    errs() << "HEATMAP-ERROR: no LBR traces detected in profile. "
-              "Cannot build heatmap.\n";
+    if (!opts::BasicAggregation) {
+      errs() << "HEATMAP-ERROR: no LBR traces detected in profile. "
+                "Cannot build heatmap. Use -nl for building heatmap from "
+                "basic events.\n";
+    } else {
+      errs() << "HEATMAP-ERROR: no samples detected in profile. "
+                "Cannot build heatmap."
+    }
     exit(1);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123067.420282.patch
Type: text/x-patch
Size: 2987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220404/dc4fd006/attachment.bin>


More information about the llvm-commits mailing list