Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 bolt/include/bolt/Profile/Heatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class Heatmap {
: BucketSize(BucketSize), MinAddress(MinAddress), MaxAddress(MaxAddress),
TextSections(TextSections) {}

uint64_t HotStart{0};
uint64_t HotEnd{0};

inline bool ignoreAddress(uint64_t Address) const {
return (Address > MaxAddress) || (Address < MinAddress);
}
Expand Down
8 changes: 8 additions & 0 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,14 @@ std::error_code DataAggregator::printLBRHeatMap() {
}
Heatmap HM(opts::HeatmapBlock, opts::HeatmapMinAddress,
opts::HeatmapMaxAddress, getTextSections(BC));
auto getSymbolValue = [&](const MCSymbol *Symbol) -> uint64_t {
if (Symbol)
if (ErrorOr<uint64_t> SymValue = BC->getSymbolValue(*Symbol))
return SymValue.get();
return 0;
};
HM.HotStart = getSymbolValue(BC->getHotTextStartSymbol());
HM.HotEnd = getSymbolValue(BC->getHotTextEndSymbol());

if (!NumTotalSamples) {
if (opts::BasicAggregation) {
Expand Down
15 changes: 14 additions & 1 deletion bolt/lib/Profile/Heatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "bolt/Profile/Heatmap.h"
#include "bolt/Utils/CommandLineOpts.h"
#include "llvm/ADT/AddressRanges.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Debug.h"
Expand Down Expand Up @@ -313,6 +314,9 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
UnmappedHotness += Frequency;
};

AddressRange HotTextRange(HotStart, HotEnd);
StringRef HotTextName = "[hot text]";

for (const std::pair<const uint64_t, uint64_t> &KV : Map) {
NumTotalCounts += KV.second;
// We map an address bucket to the first section (lowest address)
Expand All @@ -328,15 +332,24 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
}
SectionHotness[TextSections[TextSectionIndex].Name] += KV.second;
++BucketUtilization[TextSections[TextSectionIndex].Name];
if (HotTextRange.contains(Address)) {
SectionHotness[HotTextName] += KV.second;
++BucketUtilization[HotTextName];
}
}

std::vector<SectionNameAndRange> Sections(TextSections);
// Append synthetic hot text section to TextSections
if (!HotTextRange.empty())
Sections.emplace_back(SectionNameAndRange{HotTextName, HotStart, HotEnd});

assert(NumTotalCounts > 0 &&
"total number of heatmap buckets should be greater than 0");

OS << "Section Name, Begin Address, End Address, Percentage Hotness, "
<< "Utilization Pct, Partition Score\n";
const uint64_t MappedCounts = NumTotalCounts - UnmappedHotness;
for (const auto [Name, Begin, End] : TextSections) {
for (const auto [Name, Begin, End] : Sections) {
const float Hotness = 1. * SectionHotness[Name] / NumTotalCounts;
const float MappedHotness =
MappedCounts ? 1. * SectionHotness[Name] / MappedCounts : 0;
Expand Down
5 changes: 3 additions & 2 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,9 @@ void RewriteInstance::discoverFileObjects() {
continue;
}

// Ignore input hot markers
if (SymName == "__hot_start" || SymName == "__hot_end")
// Ignore input hot markers unless in heatmap mode
if ((SymName == "__hot_start" || SymName == "__hot_end") &&
!opts::HeatmapMode)
continue;

FileSymRefs.emplace(SymbolAddress, Symbol);
Expand Down
4 changes: 4 additions & 0 deletions bolt/test/X86/heatmap-preagg.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN: --reorder-functions=cdsort --enable-bat --dyno-stats --skip-funcs=main
RUN: llvm-bolt-heatmap %t.out -o %t2 --pa -p %p/Inputs/blarge_new_bat.preagg.txt \
RUN: 2>&1 | FileCheck --check-prefix CHECK-HEATMAP-BAT %s
RUN: FileCheck %s --check-prefix CHECK-SEC-HOT-BAT --input-file %t2-section-hotness.csv
RUN: llvm-nm -n %t.out | FileCheck %s --check-prefix=CHECK-HOT-SYMS

CHECK-HEATMAP: PERF2BOLT: read 81 aggregated LBR entries
CHECK-HEATMAP: HEATMAP: invalid traces: 1
Expand All @@ -33,3 +34,6 @@ CHECK-SEC-HOT-BAT-NEXT: .bolt.org.text, 0x4010b0, 0x401c25, 38.3385, 51.0638, 0.
CHECK-SEC-HOT-BAT-NEXT: .fini, 0x401c28, 0x401c35, 0.0000, 0.0000, 0.0000
CHECK-SEC-HOT-BAT-NEXT: .text, 0x800000, 0x8002cc, 38.7595, 91.6667, 0.3553
CHECK-SEC-HOT-BAT-NEXT: .text.cold, 0x800300, 0x800415, 0.0000, 0.0000, 0.0000
CHECK-SEC-HOT-BAT-NEXT: [hot text], 0x800000, 0x8002cc, 38.7595, 91.6667, 0.3553
CHECK-HOT-SYMS: 800000 W __hot_start
CHECK-HOT-SYMS: 8002cc W __hot_end
Loading