Skip to content

Commit a429af4

Browse files
committed
align with ad-hoc parsing
Created using spr 1.3.4
2 parents 5548bc3 + 7b8a766 commit a429af4

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ class DataAggregator : public DataReader {
285285
/// everything
286286
bool hasData() const { return !ParsingBuf.empty(); }
287287

288-
/// Print heat map based on collected samples.
289-
std::error_code printHeatMap();
288+
/// Print heat map based on LBR samples.
289+
std::error_code printLBRHeatMap();
290290

291291
/// Parse a single perf sample containing a PID associated with a sequence of
292292
/// LBR entries. If the PID does not correspond to the binary we are looking

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
503503
errs() << "PERF2BOLT: failed to parse samples\n";
504504

505505
if (opts::HeatmapMode) {
506-
if (std::error_code EC = printHeatMap())
506+
if (std::error_code EC = printLBRHeatMap())
507507
return errorCodeToError(EC);
508508
exit(0);
509509
}
@@ -1327,7 +1327,7 @@ bool DataAggregator::ignoreKernelInterrupt(LBREntry &LBR) const {
13271327
(LBR.From >= KernelBaseAddr || LBR.To >= KernelBaseAddr);
13281328
}
13291329

1330-
std::error_code DataAggregator::printHeatMap() {
1330+
std::error_code DataAggregator::printLBRHeatMap() {
13311331
outs() << "PERF2BOLT: parse branch events...\n";
13321332
NamedRegionTimer T("parseBranch", "Parsing branch events", TimerGroupName,
13331333
TimerGroupDesc, opts::TimeAggregator);
@@ -1342,7 +1342,7 @@ std::error_code DataAggregator::printHeatMap() {
13421342
if (!NumTotalSamples) {
13431343
if (opts::BasicAggregation) {
13441344
errs() << "HEATMAP-ERROR: no basic event samples detected in profile. "
1345-
"Cannot build heatmap.";
1345+
"Cannot build heatmap.\n";
13461346
} else {
13471347
errs() << "HEATMAP-ERROR: no LBR traces detected in profile. "
13481348
"Cannot build heatmap. Use -nl for building heatmap from "
@@ -1353,13 +1353,10 @@ std::error_code DataAggregator::printHeatMap() {
13531353

13541354
outs() << "HEATMAP: building heat map...\n";
13551355

1356-
if (opts::BasicAggregation) {
1357-
for (const auto &[PC, Hits] : BasicSamples)
1358-
HM.registerAddress(PC, Hits);
1359-
} else {
1360-
for (const auto &[Trace, Info] : FallthroughLBRs)
1361-
HM.registerAddressRange(Trace.From, Trace.To, Info.InternCount);
1362-
}
1356+
for (const auto &[PC, Hits] : BasicSamples)
1357+
HM.registerAddress(PC, Hits);
1358+
for (const auto &[Trace, Info] : FallthroughLBRs)
1359+
HM.registerAddressRange(Trace.From, Trace.To, Info.InternCount);
13631360

13641361
if (HM.getNumInvalidRanges())
13651362
outs() << "HEATMAP: invalid traces: " << HM.getNumInvalidRanges() << '\n';
@@ -1404,7 +1401,10 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14041401
const uint64_t TraceTo = NextLBR->From;
14051402
const BinaryFunction *TraceBF =
14061403
getBinaryFunctionContainingAddress(TraceFrom);
1407-
if (TraceBF && TraceBF->containsAddress(TraceTo)) {
1404+
if (opts::HeatmapMode) {
1405+
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
1406+
++Info.InternCount;
1407+
} else if (TraceBF && TraceBF->containsAddress(TraceTo)) {
14081408
FTInfo &Info = FallthroughLBRs[Trace(TraceFrom, TraceTo)];
14091409
if (TraceBF->containsAddress(LBR.From))
14101410
++Info.InternCount;
@@ -1438,6 +1438,11 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14381438
}
14391439
NextLBR = &LBR;
14401440

1441+
if (opts::HeatmapMode) {
1442+
TakenBranchInfo &Info = BranchLBRs[Trace(LBR.From, LBR.To)];
1443+
++Info.TakenCount;
1444+
continue;
1445+
}
14411446
uint64_t From = getBinaryFunctionContainingAddress(LBR.From) ? LBR.From : 0;
14421447
uint64_t To = getBinaryFunctionContainingAddress(LBR.To) ? LBR.To : 0;
14431448
if (!From && !To)
@@ -1446,6 +1451,10 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14461451
++Info.TakenCount;
14471452
Info.MispredCount += LBR.Mispred;
14481453
}
1454+
if (opts::HeatmapMode && !Sample.LBR.empty()) {
1455+
++BasicSamples[Sample.LBR.front().To];
1456+
++BasicSamples[Sample.LBR.back().From];
1457+
}
14491458
}
14501459

14511460
void DataAggregator::printColdSamplesDiagnostic() const {
@@ -1622,13 +1631,15 @@ std::error_code DataAggregator::parseBasicEvents() {
16221631

16231632
if (!Sample->PC)
16241633
continue;
1634+
++NumTotalSamples;
16251635

16261636
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
16271637
BF->setHasProfileAvailable();
16281638

16291639
++BasicSamples[Sample->PC];
16301640
EventNames.insert(Sample->EventName);
16311641
}
1642+
outs() << "PERF2BOLT: read " << NumTotalSamples << " samples\n";
16321643

16331644
return std::error_code();
16341645
}
@@ -1638,19 +1649,11 @@ void DataAggregator::processBasicEvents() {
16381649
NamedRegionTimer T("processBasic", "Processing basic events", TimerGroupName,
16391650
TimerGroupDesc, opts::TimeAggregator);
16401651
uint64_t OutOfRangeSamples = 0;
1641-
for (auto &Sample : BasicSamples) {
1642-
const uint64_t PC = Sample.first;
1643-
const uint64_t HitCount = Sample.second;
1644-
NumTotalSamples += HitCount;
1645-
BinaryFunction *Func = getBinaryFunctionContainingAddress(PC);
1646-
if (!Func) {
1652+
for (const auto [PC, HitCount]: BasicSamples)
1653+
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(PC))
1654+
doSample(*Func, PC, HitCount);
1655+
else
16471656
OutOfRangeSamples += HitCount;
1648-
continue;
1649-
}
1650-
1651-
doSample(*Func, PC, HitCount);
1652-
}
1653-
outs() << "PERF2BOLT: read " << NumTotalSamples << " samples\n";
16541657

16551658
printBasicSamplesDiagnostics(OutOfRangeSamples);
16561659
}

bolt/lib/Profile/Heatmap.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,11 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
304304

305305
uint64_t UnmappedHotness = 0;
306306
auto RecordUnmappedBucket = [&](uint64_t Address, uint64_t Frequency) {
307-
errs() << "Couldn't map the address bucket [0x" << Twine::utohexstr(Address)
308-
<< ", 0x" << Twine::utohexstr(Address + BucketSize)
309-
<< "] containing " << Frequency
310-
<< " samples to a text section in the binary.";
307+
if (opts::Verbosity >= 1)
308+
errs() << "Couldn't map the address bucket ["
309+
<< formatv("{0:x}, {1:x}", Address, Address + BucketSize)
310+
<< "] containing " << Frequency
311+
<< " samples to a text section in the binary.\n";
311312
UnmappedHotness += Frequency;
312313
};
313314

0 commit comments

Comments
 (0)