Skip to content

Commit 3c64b24

Browse files
authored
[BOLT] Add extra staleness logging (#80225)
Report two extra metrics: - # of stale functions with matching block count, - # of stale blocks with matching instruction count.
1 parent 62ae7d9 commit 3c64b24

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,11 @@ class BinaryContext {
671671
uint64_t StaleSampleCount{0};
672672
/// the count of matched samples
673673
uint64_t MatchedSampleCount{0};
674+
/// the number of stale functions that have matching number of blocks in
675+
/// the profile
676+
uint64_t NumStaleFuncsWithEqualBlockCount{0};
677+
/// the number of blocks that have matching size but a differing hash
678+
uint64_t NumStaleBlocksWithEqualIcount{0};
674679
} Stats;
675680

676681
// Address of the first allocated segment.

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,12 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
14201420
if (NumAllStaleFunctions) {
14211421
const float PctStale =
14221422
NumAllStaleFunctions / (float)NumAllProfiledFunctions * 100.0f;
1423+
const float PctStaleFuncsWithEqualBlockCount =
1424+
(float)BC.Stats.NumStaleFuncsWithEqualBlockCount /
1425+
NumAllStaleFunctions * 100.0f;
1426+
const float PctStaleBlocksWithEqualIcount =
1427+
(float)BC.Stats.NumStaleBlocksWithEqualIcount /
1428+
BC.Stats.NumStaleBlocks * 100.0f;
14231429
auto printErrorOrWarning = [&]() {
14241430
if (PctStale > opts::StaleThreshold)
14251431
errs() << "BOLT-ERROR: ";
@@ -1442,6 +1448,16 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
14421448
<< "%) belong to functions with invalid"
14431449
" (possibly stale) profile.\n";
14441450
}
1451+
outs() << "BOLT-INFO: " << BC.Stats.NumStaleFuncsWithEqualBlockCount
1452+
<< " stale function"
1453+
<< (BC.Stats.NumStaleFuncsWithEqualBlockCount == 1 ? "" : "s")
1454+
<< format(" (%.1f%% of all stale)", PctStaleFuncsWithEqualBlockCount)
1455+
<< " have matching block count.\n";
1456+
outs() << "BOLT-INFO: " << BC.Stats.NumStaleBlocksWithEqualIcount
1457+
<< " stale block"
1458+
<< (BC.Stats.NumStaleBlocksWithEqualIcount == 1 ? "" : "s")
1459+
<< format(" (%.1f%% of all stale)", PctStaleBlocksWithEqualIcount)
1460+
<< " have matching icount.\n";
14451461
if (PctStale > opts::StaleThreshold) {
14461462
errs() << "BOLT-ERROR: stale functions exceed specified threshold of "
14471463
<< opts::StaleThreshold << "%. Exiting.\n";

bolt/lib/Profile/StaleProfileMatching.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ void matchWeightsByHashes(BinaryContext &BC,
418418
if (MatchedBlock == nullptr && YamlBB.Index == 0)
419419
MatchedBlock = Blocks[0];
420420
if (MatchedBlock != nullptr) {
421+
const BinaryBasicBlock *BB = BlockOrder[MatchedBlock->Index - 1];
421422
MatchedBlocks[YamlBB.Index] = MatchedBlock;
422423
BlendedBlockHash BinHash = BlendedHashes[MatchedBlock->Index - 1];
423424
LLVM_DEBUG(dbgs() << "Matched yaml block (bid = " << YamlBB.Index << ")"
@@ -433,6 +434,8 @@ void matchWeightsByHashes(BinaryContext &BC,
433434
} else {
434435
LLVM_DEBUG(dbgs() << " loose match\n");
435436
}
437+
if (YamlBB.NumInstructions == BB->size())
438+
++BC.Stats.NumStaleBlocksWithEqualIcount;
436439
} else {
437440
LLVM_DEBUG(
438441
dbgs() << "Couldn't match yaml block (bid = " << YamlBB.Index << ")"

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,20 @@ bool YAMLProfileReader::parseFunctionProfile(
246246

247247
ProfileMatched &= !MismatchedBlocks && !MismatchedCalls && !MismatchedEdges;
248248

249-
if (ProfileMatched)
250-
BF.markProfiled(YamlBP.Header.Flags);
249+
if (!ProfileMatched) {
250+
if (opts::Verbosity >= 1)
251+
errs() << "BOLT-WARNING: " << MismatchedBlocks << " blocks, "
252+
<< MismatchedCalls << " calls, and " << MismatchedEdges
253+
<< " edges in profile did not match function " << BF << '\n';
251254

252-
if (!ProfileMatched && opts::Verbosity >= 1)
253-
errs() << "BOLT-WARNING: " << MismatchedBlocks << " blocks, "
254-
<< MismatchedCalls << " calls, and " << MismatchedEdges
255-
<< " edges in profile did not match function " << BF << '\n';
255+
if (YamlBF.NumBasicBlocks != BF.size())
256+
++BC.Stats.NumStaleFuncsWithEqualBlockCount;
256257

257-
if (!ProfileMatched && opts::InferStaleProfile) {
258-
if (inferStaleProfile(BF, YamlBF)) {
258+
if (opts::InferStaleProfile && inferStaleProfile(BF, YamlBF))
259259
ProfileMatched = true;
260-
BF.markProfiled(YamlBP.Header.Flags);
261-
}
262260
}
261+
if (ProfileMatched)
262+
BF.markProfiled(YamlBP.Header.Flags);
263263

264264
return ProfileMatched;
265265
}

0 commit comments

Comments
 (0)