[BOLT] Report input staleness (#79496)

It's beneficial to have uniform reporting in both `infer-stale-profile`
on and off cases, primarily for logging purposes.

Without this change, BOLT would report "input" staleness in
`infer-stale-profile=0` case (without matching), and "output" staleness
in `infer-stale-profile=1` case (after matching).

This change makes BOLT report "input" staleness in both cases. "Output"
staleness information is printed separately with "BOLT-INFO: inferred
profile..."
This commit is contained in:
Amir Ayupov
2024-01-25 14:15:13 -08:00
committed by GitHub
parent 887783e0ca
commit e9309b27d7
2 changed files with 18 additions and 7 deletions

View File

@@ -1417,9 +1417,9 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
<< (NumNonSimpleProfiledFunctions == 1 ? "" : "s")
<< " with profile could not be optimized\n";
}
if (NumStaleProfileFunctions) {
if (NumAllStaleFunctions) {
const float PctStale =
NumStaleProfileFunctions / (float)NumAllProfiledFunctions * 100.0f;
NumAllStaleFunctions / (float)NumAllProfiledFunctions * 100.0f;
auto printErrorOrWarning = [&]() {
if (PctStale > opts::StaleThreshold)
errs() << "BOLT-ERROR: ";
@@ -1427,16 +1427,18 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
errs() << "BOLT-WARNING: ";
};
printErrorOrWarning();
errs() << NumStaleProfileFunctions
errs() << NumAllStaleFunctions
<< format(" (%.1f%% of all profiled)", PctStale) << " function"
<< (NumStaleProfileFunctions == 1 ? "" : "s")
<< (NumAllStaleFunctions == 1 ? "" : "s")
<< " have invalid (possibly stale) profile."
" Use -report-stale to see the list.\n";
if (TotalSampleCount > 0) {
printErrorOrWarning();
errs() << StaleSampleCount << " out of " << TotalSampleCount
<< " samples in the binary ("
<< format("%.1f", ((100.0f * StaleSampleCount) / TotalSampleCount))
errs() << (StaleSampleCount + InferredSampleCount) << " out of "
<< TotalSampleCount << " samples in the binary ("
<< format("%.1f",
((100.0f * (StaleSampleCount + InferredSampleCount)) /
TotalSampleCount))
<< "%) belong to functions with invalid"
" (possibly stale) profile.\n";
}

View File

@@ -3,6 +3,9 @@
REQUIRES: asserts
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
RUN: --infer-stale-profile=0 --profile-ignore-hash=1 --profile-use-dfs=0 \
RUN: 2>&1 | FileCheck %s -check-prefix=CHECK0
# Testing "usqrt"
RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
RUN: --print-cfg --print-only=usqrt --infer-stale-profile=1 \
@@ -12,6 +15,10 @@ RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
RUN: --print-cfg --print-only=SolveCubic --infer-stale-profile=1 \
RUN: --profile-ignore-hash=1 --profile-use-dfs=0 --debug-only=bolt-prof 2>&1 | FileCheck %s -check-prefix=CHECK2
CHECK0: BOLT-INFO: 2 out of 7 functions in the binary (28.6%) have non-empty execution profile
CHECK0: BOLT-WARNING: 2 (100.0% of all profiled) functions have invalid (possibly stale) profile
CHECK0: BOLT-WARNING: 1192 out of 1192 samples in the binary (100.0%) belong to functions with invalid (possibly stale) profile
# Function "usqrt" has stale profile, since the number of blocks in the profile
# (nblocks=6) does not match the size of the CFG in the binary. The entry
# block (bid=0) has an incorrect (missing) count, which should be inferred by
@@ -51,6 +58,8 @@ CHECK1: Successors: .Ltmp[[#BB13:]] (mispreds: 0, count: 300), .LFT[[#BB1:]
CHECK1: .LFT[[#BB1:]] (2 instructions, align : 1)
# Check the overall inference stats.
CHECK1: 2 out of 7 functions in the binary (28.6%) have non-empty execution profile
CHECK1: BOLT-WARNING: 2 (100.0% of all profiled) functions have invalid (possibly stale) profile
CHECK1: BOLT-WARNING: 1192 out of 1192 samples in the binary (100.0%) belong to functions with invalid (possibly stale) profile
CHECK1: inferred profile for 2 (100.00% of profiled, 100.00% of stale) functions responsible for {{.*}} samples ({{.*}} out of {{.*}})