Skip to content

Commit 4ded0d7

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.4 [skip ci]
1 parent a8644b3 commit 4ded0d7

File tree

2 files changed

+81
-114
lines changed

2 files changed

+81
-114
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class DataAggregator : public DataReader {
231231
/// for the source of the branch to avoid counting cold activity twice (one
232232
/// for source and another for destination).
233233
uint64_t NumColdSamples{0};
234+
uint64_t NumTotalSamples{0};
234235

235236
/// Looks into system PATH for Linux Perf and set up the aggregator to use it
236237
void findPerfExecutable();

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 80 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,12 +1490,86 @@ uint64_t DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14901490
return NumTraces;
14911491
}
14921492

1493+
static void printColdSamplesDiagnostic() {
1494+
if (NumColdSamples > 0) {
1495+
const float ColdSamples = NumColdSamples * 100.0f / NumTotalSamples;
1496+
outs() << "PERF2BOLT: " << NumColdSamples
1497+
<< format(" (%.1f%%)", ColdSamples)
1498+
<< " samples recorded in cold regions of split functions.\n";
1499+
if (ColdSamples > 5.0f)
1500+
outs()
1501+
<< "WARNING: The BOLT-processed binary where samples were collected "
1502+
"likely used bad data or your service observed a large shift in "
1503+
"profile. You may want to audit this.\n";
1504+
}
1505+
}
1506+
1507+
static void printLongRangeTracesDiagnostic() {
1508+
outs() << "PERF2BOLT: out of range traces involving unknown regions: "
1509+
<< NumLongRangeTraces;
1510+
if (NumTraces > 0)
1511+
outs() << format(" (%.1f%%)", NumLongRangeTraces * 100.0f / NumTraces);
1512+
outs() << "\n";
1513+
}
1514+
1515+
static float printColoredPct(uint64_t Numerator, uint64_t Denominator, float T1,
1516+
float T2) {
1517+
if (Denominator == 0) {
1518+
outs() << "\n";
1519+
return 0;
1520+
}
1521+
float Percent = Numerator * 100.0f / Denominator;
1522+
outs() << " (";
1523+
if (outs().has_colors()) {
1524+
if (Percent > T2)
1525+
outs().changeColor(raw_ostream::RED);
1526+
else if (Percent > T1)
1527+
outs().changeColor(raw_ostream::YELLOW);
1528+
else
1529+
outs().changeColor(raw_ostream::GREEN);
1530+
}
1531+
outs() << format("%.1f%%", Percent);
1532+
if (outs().has_colors())
1533+
outs().resetColor();
1534+
outs() << ")\n";
1535+
return Perc;
1536+
}
1537+
1538+
static void printBranchSamplesDiagnostics() {
1539+
outs() << "PERF2BOLT: traces mismatching disassembled function contents: "
1540+
<< NumInvalidTraces;
1541+
if (printColoredPct(NumInvalidTraces, NumTraces, 5, 10) > 10)
1542+
outs() << "\n !! WARNING !! This high mismatch ratio indicates the input "
1543+
"binary is probably not the same binary used during profiling "
1544+
"collection. The generated data may be ineffective for improving "
1545+
"performance.\n\n";
1546+
printLongRangeTracesDiagnostic();
1547+
printColdSamplesDiagnostic();
1548+
}
1549+
1550+
static void printBasicSamplesDiagnostics(uint64_t OutOfRangeSamples) {
1551+
outs() << "PERF2BOLT: out of range samples recorded in unknown regions: "
1552+
<< OutOfRangeSamples;
1553+
if (printColoredPct(OutOfRangeSamples, NumTotalSamples, 40, 60) > 80)
1554+
outs() << "\n !! WARNING !! This high mismatch ratio indicates the input "
1555+
"binary is probably not the same binary used during profiling "
1556+
"collection. The generated data may be ineffective for improving "
1557+
"performance.\n\n";
1558+
printColdSamplesDiagnostic();
1559+
}
1560+
1561+
static void printBranchStacksDiagnostics(uint64_t IgnoredSamples) {
1562+
outs() << "PERF2BOLT: ignored samples: " << IgnoredSamples;
1563+
if (printColoredPct(IgnoredSamples, NumTotalSamples, 20, 50) > 50)
1564+
errs() << "PERF2BOLT-WARNING: less than 50% of all recorded samples "
1565+
"were attributed to the input binary\n";
1566+
}
1567+
14931568
std::error_code DataAggregator::parseBranchEvents() {
14941569
outs() << "PERF2BOLT: parse branch events...\n";
14951570
NamedRegionTimer T("parseBranch", "Parsing branch events", TimerGroupName,
14961571
TimerGroupDesc, opts::TimeAggregator);
14971572

1498-
uint64_t NumTotalSamples = 0;
14991573
uint64_t NumEntries = 0;
15001574
uint64_t NumSamples = 0;
15011575
uint64_t NumSamplesNoLBR = 0;
@@ -1534,22 +1608,6 @@ std::error_code DataAggregator::parseBranchEvents() {
15341608
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
15351609
BF->setHasProfileAvailable();
15361610

1537-
auto printColored = [](raw_ostream &OS, float Percent, float T1, float T2) {
1538-
OS << " (";
1539-
if (OS.has_colors()) {
1540-
if (Percent > T2)
1541-
OS.changeColor(raw_ostream::RED);
1542-
else if (Percent > T1)
1543-
OS.changeColor(raw_ostream::YELLOW);
1544-
else
1545-
OS.changeColor(raw_ostream::GREEN);
1546-
}
1547-
OS << format("%.1f%%", Percent);
1548-
if (OS.has_colors())
1549-
OS.resetColor();
1550-
OS << ")";
1551-
};
1552-
15531611
outs() << "PERF2BOLT: read " << NumSamples << " samples and " << NumEntries
15541612
<< " LBR entries\n";
15551613
if (NumTotalSamples) {
@@ -1561,47 +1619,10 @@ std::error_code DataAggregator::parseBranchEvents() {
15611619
"in no-LBR mode with -nl (the performance improvement in -nl "
15621620
"mode may be limited)\n";
15631621
} else {
1564-
const uint64_t IgnoredSamples = NumTotalSamples - NumSamples;
1565-
const float PercentIgnored = 100.0f * IgnoredSamples / NumTotalSamples;
1566-
outs() << "PERF2BOLT: " << IgnoredSamples << " samples";
1567-
printColored(outs(), PercentIgnored, 20, 50);
1568-
outs() << " were ignored\n";
1569-
if (PercentIgnored > 50.0f)
1570-
errs() << "PERF2BOLT-WARNING: less than 50% of all recorded samples "
1571-
"were attributed to the input binary\n";
1622+
printBranchStacksDiagnostics(NumTotalSamples - NumSamples);
15721623
}
15731624
}
1574-
outs() << "PERF2BOLT: traces mismatching disassembled function contents: "
1575-
<< NumInvalidTraces;
1576-
float Perc = 0.0f;
1577-
if (NumTraces > 0) {
1578-
Perc = NumInvalidTraces * 100.0f / NumTraces;
1579-
printColored(outs(), Perc, 5, 10);
1580-
}
1581-
outs() << "\n";
1582-
if (Perc > 10.0f)
1583-
outs() << "\n !! WARNING !! This high mismatch ratio indicates the input "
1584-
"binary is probably not the same binary used during profiling "
1585-
"collection. The generated data may be ineffective for improving "
1586-
"performance.\n\n";
1587-
1588-
outs() << "PERF2BOLT: out of range traces involving unknown regions: "
1589-
<< NumLongRangeTraces;
1590-
if (NumTraces > 0)
1591-
outs() << format(" (%.1f%%)", NumLongRangeTraces * 100.0f / NumTraces);
1592-
outs() << "\n";
1593-
1594-
if (NumColdSamples > 0) {
1595-
const float ColdSamples = NumColdSamples * 100.0f / NumTotalSamples;
1596-
outs() << "PERF2BOLT: " << NumColdSamples
1597-
<< format(" (%.1f%%)", ColdSamples)
1598-
<< " samples recorded in cold regions of split functions.\n";
1599-
if (ColdSamples > 5.0f)
1600-
outs()
1601-
<< "WARNING: The BOLT-processed binary where samples were collected "
1602-
"likely used bad data or your service observed a large shift in "
1603-
"profile. You may want to audit this.\n";
1604-
}
1625+
printBranchSamplesDiagnostics();
16051626

16061627
return std::error_code();
16071628
}
@@ -1658,11 +1679,10 @@ void DataAggregator::processBasicEvents() {
16581679
NamedRegionTimer T("processBasic", "Processing basic events", TimerGroupName,
16591680
TimerGroupDesc, opts::TimeAggregator);
16601681
uint64_t OutOfRangeSamples = 0;
1661-
uint64_t NumSamples = 0;
16621682
for (auto &Sample : BasicSamples) {
16631683
const uint64_t PC = Sample.first;
16641684
const uint64_t HitCount = Sample.second;
1665-
NumSamples += HitCount;
1685+
NumTotalSamples += HitCount;
16661686
BinaryFunction *Func = getBinaryFunctionContainingAddress(PC);
16671687
if (!Func) {
16681688
OutOfRangeSamples += HitCount;
@@ -1673,31 +1693,7 @@ void DataAggregator::processBasicEvents() {
16731693
}
16741694
outs() << "PERF2BOLT: read " << NumSamples << " samples\n";
16751695

1676-
outs() << "PERF2BOLT: out of range samples recorded in unknown regions: "
1677-
<< OutOfRangeSamples;
1678-
float Perc = 0.0f;
1679-
if (NumSamples > 0) {
1680-
outs() << " (";
1681-
Perc = OutOfRangeSamples * 100.0f / NumSamples;
1682-
if (outs().has_colors()) {
1683-
if (Perc > 60.0f)
1684-
outs().changeColor(raw_ostream::RED);
1685-
else if (Perc > 40.0f)
1686-
outs().changeColor(raw_ostream::YELLOW);
1687-
else
1688-
outs().changeColor(raw_ostream::GREEN);
1689-
}
1690-
outs() << format("%.1f%%", Perc);
1691-
if (outs().has_colors())
1692-
outs().resetColor();
1693-
outs() << ")";
1694-
}
1695-
outs() << "\n";
1696-
if (Perc > 80.0f)
1697-
outs() << "\n !! WARNING !! This high mismatch ratio indicates the input "
1698-
"binary is probably not the same binary used during profiling "
1699-
"collection. The generated data may be ineffective for improving "
1700-
"performance.\n\n";
1696+
printBasicSamplesDiagnostics(OutOfRangeSamples);
17011697
}
17021698

17031699
std::error_code DataAggregator::parseMemEvents() {
@@ -1799,37 +1795,7 @@ void DataAggregator::processPreAggregated() {
17991795

18001796
outs() << "PERF2BOLT: read " << AggregatedLBRs.size()
18011797
<< " aggregated LBR entries\n";
1802-
outs() << "PERF2BOLT: traces mismatching disassembled function contents: "
1803-
<< NumInvalidTraces;
1804-
float Perc = 0.0f;
1805-
if (NumTraces > 0) {
1806-
outs() << " (";
1807-
Perc = NumInvalidTraces * 100.0f / NumTraces;
1808-
if (outs().has_colors()) {
1809-
if (Perc > 10.0f)
1810-
outs().changeColor(raw_ostream::RED);
1811-
else if (Perc > 5.0f)
1812-
outs().changeColor(raw_ostream::YELLOW);
1813-
else
1814-
outs().changeColor(raw_ostream::GREEN);
1815-
}
1816-
outs() << format("%.1f%%", Perc);
1817-
if (outs().has_colors())
1818-
outs().resetColor();
1819-
outs() << ")";
1820-
}
1821-
outs() << "\n";
1822-
if (Perc > 10.0f)
1823-
outs() << "\n !! WARNING !! This high mismatch ratio indicates the input "
1824-
"binary is probably not the same binary used during profiling "
1825-
"collection. The generated data may be ineffective for improving "
1826-
"performance.\n\n";
1827-
1828-
outs() << "PERF2BOLT: Out of range traces involving unknown regions: "
1829-
<< NumLongRangeTraces;
1830-
if (NumTraces > 0)
1831-
outs() << format(" (%.1f%%)", NumLongRangeTraces * 100.0f / NumTraces);
1832-
outs() << "\n";
1798+
printBranchSamplesDiagnostics();
18331799
}
18341800

18351801
std::optional<int32_t> DataAggregator::parseCommExecEvent() {

0 commit comments

Comments
 (0)