Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[BOLT][heatmap] Produce zoomed-out heatmaps #140153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 3 bolt/include/bolt/Profile/Heatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class Heatmap {
void printSectionHotness(raw_ostream &OS) const;

size_t size() const { return Map.size(); }

/// Increase bucket size to \p TargetSize, recomputing the heatmap.
bool resizeBucket(uint64_t TargetSize);
};

} // namespace bolt
Expand Down
15 changes: 15 additions & 0 deletions 15 bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ FilterPID("pid",
cl::Optional,
cl::cat(AggregatorCategory));

static cl::list<uint64_t>
HeatmapZoomOut("heatmap-zoom-out", cl::CommaSeparated,
cl::desc("print secondary heatmaps with given bucket sizes"),
cl::value_desc("bucket_size"), cl::Optional,
cl::cat(HeatmapCategory));

static cl::opt<bool>
IgnoreBuildID("ignore-build-id",
cl::desc("continue even if build-ids in input binary and perf.data mismatch"),
Expand Down Expand Up @@ -1365,6 +1371,15 @@ std::error_code DataAggregator::printLBRHeatMap() {
HM.printCDF(opts::HeatmapOutput + ".csv");
HM.printSectionHotness(opts::HeatmapOutput + "-section-hotness.csv");
}
// Provide coarse-grained heatmap if requested via --heatmap-zoom-out
for (const uint64_t NewBucketSize : opts::HeatmapZoomOut) {
if (!HM.resizeBucket(NewBucketSize))
break;
if (opts::HeatmapOutput == "-")
HM.print(opts::HeatmapOutput);
else
HM.print(formatv("{0}-{1}", opts::HeatmapOutput, NewBucketSize).str());
}

return std::error_code();
}
Expand Down
13 changes: 13 additions & 0 deletions 13 bolt/lib/Profile/Heatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,18 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
OS << formatv("[unmapped], 0x0, 0x0, {0:f4}, 0, 0\n",
100.0 * UnmappedHotness / NumTotalCounts);
}

bool Heatmap::resizeBucket(uint64_t TargetSize) {
if (TargetSize <= BucketSize)
return false;
std::map<uint64_t, uint64_t> NewMap;
for (const auto [Bucket, Count] : Map) {
const uint64_t Address = Bucket * BucketSize;
NewMap[Address / TargetSize] += Count;
}
Map = NewMap;
BucketSize = TargetSize;
return true;
}
} // namespace bolt
} // namespace llvm
27 changes: 27 additions & 0 deletions 27 bolt/test/X86/heatmap-preagg.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
RUN: yaml2obj %p/Inputs/blarge_new.yaml &> %t.exe
## Non-BOLTed input binary
RUN: llvm-bolt-heatmap %t.exe -o %t --pa -p %p/Inputs/blarge_new.preagg.txt \
RUN: --heatmap-zoom-out 128,1024 --line-size 64 \
RUN: 2>&1 | FileCheck --check-prefix CHECK-HEATMAP %s
RUN: FileCheck %s --check-prefix CHECK-SEC-HOT --input-file %t-section-hotness.csv
RUN: FileCheck %s --check-prefix CHECK-HM-64 --input-file %t
RUN: FileCheck %s --check-prefix CHECK-HM-128 --input-file %t-128
RUN: FileCheck %s --check-prefix CHECK-HM-1024 --input-file %t-1024

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

# Only check x scales – can't check colors, and FileCheck doesn't strip color
# codes by default.
CHECK-HM-64: (299, 937]
CHECK-HM-64-NEXT: 0
CHECK-HM-64-NEXT: 0
CHECK-HM-64-NEXT: 0 1 2 3 4 5 6 7 8 9 a b c d e f
CHECK-HM-64-NEXT: 048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c
CHECK-HM-64-NEXT: 0

CHECK-HM-128: (299, 937]
CHECK-HM-128-NEXT: 0
CHECK-HM-128-NEXT: 0 1
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
CHECK-HM-128-NEXT: 0808080808080808080808080808080808080808080808080808080808080808
CHECK-HM-128-NEXT: 0

CHECK-HM-1024: (483, 1663]
CHECK-HM-1024-NEXT: 0
CHECK-HM-1024-NEXT: 0 1 2 3 4 5 6 7 8 9 a b c d e f
CHECK-HM-1024-NEXT: 048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c048c
CHECK-HM-1024-NEXT: 0
CHECK-HM-1024-NEXT: 0

CHECK-HEATMAP-BAT: PERF2BOLT: read 79 aggregated LBR entries
CHECK-HEATMAP-BAT: HEATMAP: invalid traces: 2

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.