[PATCH] D133068: [BOLT] Distinguish sections in heatmap

Fabian Parzefall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 7 16:35:14 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG05aa2a16f3ea: [BOLT] Distinguish sections in heatmap (authored by FPar).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133068/new/

https://reviews.llvm.org/D133068

Files:
  bolt/lib/Profile/Heatmap.cpp


Index: bolt/lib/Profile/Heatmap.cpp
===================================================================
--- bolt/lib/Profile/Heatmap.cpp
+++ bolt/lib/Profile/Heatmap.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
+#include <cctype>
 #include <cmath>
 #include <vector>
 
@@ -141,7 +142,7 @@
   Range[NumRanges - 1] = std::max((uint64_t)NumRanges, MaxValue);
 
   // Print scaled value
-  auto printValue = [&](uint64_t Value, bool ResetColor = false) {
+  auto printValue = [&](uint64_t Value, char Character, bool ResetColor) {
     assert(Value && "should only print positive values");
     for (unsigned I = 0; I < sizeof(Range) / sizeof(Range[0]); ++I) {
       if (Value <= Range[I]) {
@@ -150,9 +151,9 @@
       }
     }
     if (Value <= Range[0])
-      OS << 'o';
+      OS << static_cast<char>(std::tolower(Character));
     else
-      OS << 'O';
+      OS << static_cast<char>(std::toupper(Character));
 
     if (ResetColor)
       changeColor(DefaultColor);
@@ -168,7 +169,7 @@
   for (unsigned I = 0; I < sizeof(Range) / sizeof(Range[0]); ++I) {
     const uint64_t Value = Range[I];
     OS << "  ";
-    printValue(Value, true);
+    printValue(Value, 'o', /*ResetColor=*/true);
     OS << " : (" << PrevValue << ", " << Value << "]\n";
     PrevValue = Value;
   }
@@ -193,17 +194,31 @@
   for (unsigned I = 5; I > 0; --I)
     printHeader(I);
 
+  auto SectionStart = TextSections.begin();
   uint64_t PrevAddress = 0;
   for (auto MI = Map.begin(), ME = Map.end(); MI != ME; ++MI) {
     const std::pair<const uint64_t, uint64_t> &Entry = *MI;
     uint64_t Address = Entry.first * BucketSize;
+    char Character = 'o';
+
+    // Check if address is in the current or any later section.
+    auto Section = std::find_if(
+        SectionStart, TextSections.end(), [&](const SectionNameAndRange &S) {
+          return Address >= S.BeginAddress && Address < S.EndAddress;
+        });
+    if (Section != TextSections.end()) {
+      // Shift the section forward (if SectionStart is different from Section).
+      // This works, because TextSections is sorted by start address.
+      SectionStart = Section;
+      Character = 'a' + ((Section - TextSections.begin()) % 26);
+    }
 
     if (PrevAddress)
       fillRange(PrevAddress, Address);
     else
       startLine(Address);
 
-    printValue(Entry.second);
+    printValue(Entry.second, Character, /*ResetColor=*/false);
 
     PrevAddress = Address;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133068.458602.patch
Type: text/x-patch
Size: 2510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220907/2a086ed0/attachment.bin>


More information about the llvm-commits mailing list