Skip to content

Commit 202eea6

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.4 [skip ci]
1 parent a3c4a5c commit 202eea6

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
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: --heatmap-zoom-out 128,1024 --line-size 64 \
67
RUN: 2>&1 | FileCheck --check-prefix CHECK-HEATMAP %s
78
RUN: FileCheck %s --check-prefix CHECK-SEC-HOT --input-file %t-section-hotness.csv
9+
RUN: FileCheck %s --check-prefix CHECK-HM-64 --input-file %t
10+
RUN: FileCheck %s --check-prefix CHECK-HM-128 --input-file %t-128
11+
RUN: FileCheck %s --check-prefix CHECK-HM-1024 --input-file %t-1024
812

913
## BOLTed input binary
1014
RUN: llvm-bolt %t.exe -o %t.out --pa -p %p/Inputs/blarge_new.preagg.txt \
@@ -24,6 +28,29 @@ CHECK-SEC-HOT-NEXT: .plt, 0x401020, 0x4010b0, 4.7583, 66.6667, 0.0317
2428
CHECK-SEC-HOT-NEXT: .text, 0x4010b0, 0x401c25, 78.3872, 85.1064, 0.6671
2529
CHECK-SEC-HOT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000, 0.0000
2630

31+
# Only check x scales – can't check colors, and FileCheck doesn't strip color
32+
# codes by default.
33+
CHECK-HM-64: (299, 937]
34+
CHECK-HM-64-NEXT: 0
35+
CHECK-HM-64-NEXT: 0
36+
CHECK-HM-64-NEXT: 0 1 2 3 4 5 6 7 8 9 a b c d e f
37+
CHECK-HM-64-NEXT: 048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c
38+
CHECK-HM-64-NEXT: 0
39+
40+
CHECK-HM-128: (299, 937]
41+
CHECK-HM-128-NEXT: 0
42+
CHECK-HM-128-NEXT: 0 1
43+
CHECK-HM-128-NEXT: 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2 3 4 5 6 7 8 9 a b c d e f
44+
CHECK-HM-128-NEXT: 0808080808080808080808080808080808080808080808080808080808080808
45+
CHECK-HM-128-NEXT: 0
46+
47+
CHECK-HM-1024: (483, 1663]
48+
CHECK-HM-1024-NEXT: 0
49+
CHECK-HM-1024-NEXT: 0 1 2 3 4 5 6 7 8 9 a b c d e f
50+
CHECK-HM-1024-NEXT: 048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c
51+
CHECK-HM-1024-NEXT: 0
52+
CHECK-HM-1024-NEXT: 0
53+
2754
CHECK-HEATMAP-BAT: PERF2BOLT: read 79 aggregated LBR entries
2855
CHECK-HEATMAP-BAT: HEATMAP: invalid traces: 2
2956

0 commit comments

Comments
 (0)