Skip to content

Commit 1e1ef44

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
1 parent e8b2c31 commit 1e1ef44

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

bolt/include/bolt/Profile/Heatmap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class Heatmap {
8585
void printSectionHotness(raw_ostream &OS) const;
8686

8787
size_t size() const { return Map.size(); }
88+
89+
/// Increase bucket size to \p TargetSize, recomputing the heatmap.
90+
bool resizeBucket(uint64_t TargetSize);
8891
};
8992

9093
} // namespace bolt

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ FilterPID("pid",
6868
cl::Optional,
6969
cl::cat(AggregatorCategory));
7070

71+
static cl::list<uint64_t>
72+
HeatmapZoomOut("heatmap-zoom-out", cl::CommaSeparated,
73+
cl::desc("print secondary heatmaps with given bucket sizes"),
74+
cl::value_desc("bucket_size"), cl::Optional,
75+
cl::cat(HeatmapCategory));
76+
7177
static cl::opt<bool>
7278
IgnoreBuildID("ignore-build-id",
7379
cl::desc("continue even if build-ids in input binary and perf.data mismatch"),
@@ -1365,6 +1371,15 @@ std::error_code DataAggregator::printLBRHeatMap() {
13651371
HM.printCDF(opts::HeatmapOutput + ".csv");
13661372
HM.printSectionHotness(opts::HeatmapOutput + "-section-hotness.csv");
13671373
}
1374+
// Provide coarse-grained heatmap if requested via --heatmap-zoom-out
1375+
for (const uint64_t NewBucketSize : opts::HeatmapZoomOut) {
1376+
if (!HM.resizeBucket(NewBucketSize))
1377+
break;
1378+
if (opts::HeatmapOutput == "-")
1379+
HM.print(opts::HeatmapOutput);
1380+
else
1381+
HM.print(formatv("{0}-{1}", opts::HeatmapOutput, NewBucketSize).str());
1382+
}
13681383

13691384
return std::error_code();
13701385
}

bolt/lib/Profile/Heatmap.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void Heatmap::print(raw_ostream &OS) const {
8181
// the Address.
8282
auto startLine = [&](uint64_t Address, bool Empty = false) {
8383
changeColor(DefaultColor);
84-
const uint64_t LineAddress = Address / BytesPerLine * BytesPerLine;
84+
const uint64_t LineAddress = alignTo(Address, BytesPerLine);
8585

8686
if (MaxAddress > 0xffffffff)
8787
OS << format("0x%016" PRIx64 ": ", LineAddress);
@@ -364,5 +364,18 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
364364
OS << formatv("[unmapped], 0x0, 0x0, {0:f4}, 0, 0\n",
365365
100.0 * UnmappedHotness / NumTotalCounts);
366366
}
367+
368+
bool Heatmap::resizeBucket(uint64_t TargetSize) {
369+
if (TargetSize <= BucketSize)
370+
return false;
371+
std::map<uint64_t, uint64_t> NewMap;
372+
for (const auto [Bucket, Count] : Map) {
373+
const uint64_t Address = Bucket * BucketSize;
374+
NewMap[Address / TargetSize] += Count;
375+
}
376+
Map = NewMap;
377+
BucketSize = TargetSize;
378+
return true;
379+
}
367380
} // namespace bolt
368381
} // namespace llvm

bolt/test/X86/heatmap-preagg.test

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
RUN: yaml2obj %p/Inputs/blarge_new.yaml &> %t.exe
44
## Non-BOLTed input binary
55
RUN: llvm-bolt-heatmap %t.exe -o %t --pa -p %p/Inputs/blarge_new.preagg.txt \
6-
RUN: 2>&1 | FileCheck --check-prefix CHECK-HEATMAP %s
6+
RUN: --heatmap-zoom-out 128,1024 2>&1 | FileCheck --check-prefix CHECK-HEATMAP %s
77
RUN: FileCheck %s --check-prefix CHECK-SEC-HOT --input-file %t-section-hotness.csv
8+
RUN: FileCheck %s --check-prefix CHECK-HM-64 --input-file %t
9+
RUN: FileCheck %s --check-prefix CHECK-HM-128 --input-file %t-128
10+
RUN: FileCheck %s --check-prefix CHECK-HM-1024 --input-file %t-1024
811

912
## BOLTed input binary
1013
RUN: llvm-bolt %t.exe -o %t.out --pa -p %p/Inputs/blarge_new.preagg.txt \
@@ -24,6 +27,15 @@ CHECK-SEC-HOT-NEXT: .plt, 0x401020, 0x4010b0, 4.7583, 66.6667, 0.0317
2427
CHECK-SEC-HOT-NEXT: .text, 0x4010b0, 0x401c25, 78.3872, 85.1064, 0.6671
2528
CHECK-SEC-HOT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000, 0.0000
2629

30+
# Only check start addresses – can't check colors, and FileCheck doesn't strip
31+
# color codes by default. Reference output:
32+
# HM-64: 0x00404000: ABBcccccccccccccccCCCCCCCCCccccCCCCCCCCcc....CC
33+
# HM-128: 0x00408000: ABCCCCCCCCCCCCCCCCCCc.CC
34+
# HM-1024: 0x00440000: ACC
35+
CHECK-HM-64: 0x00404000:
36+
CHECK-HM-128: 0x00408000:
37+
CHECK-HM-1024: 0x00440000:
38+
2739
CHECK-HEATMAP-BAT: PERF2BOLT: read 79 aggregated LBR entries
2840
CHECK-HEATMAP-BAT: HEATMAP: invalid traces: 2
2941

0 commit comments

Comments
 (0)