[llvm-branch-commits] [llvm] [llvm-profgen] Support [buildid:]0xaddr format in perfscript input (PR #190863)
Amir Ayupov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 1 16:05:46 PDT 2026
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/190863
>From a98cb95a1c3b46f242e6ffc30148d6c267ea9cf2 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Sun, 12 Apr 2026 12:15:02 -0700
Subject: [PATCH 1/2] reduce changes
Created using spr 1.3.4
---
llvm/tools/llvm-profgen/PerfReader.cpp | 20 ++++++++++----------
llvm/tools/llvm-profgen/PerfReader.h | 3 +++
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index becabe4ab37bd..785946188b0b6 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -747,9 +747,9 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
// For pre-aggregated input, filter by build ID.
if (IsPreAggregated) {
StringRef BinaryBuildID = getFilterBuildID(Binary);
- if (!SrcBuildID.empty() && SrcBuildID != BinaryBuildID)
+ if (SrcBuildID != BinaryBuildID)
SrcIsInternal = false;
- if (!DstBuildID.empty() && DstBuildID != BinaryBuildID)
+ if (DstBuildID != BinaryBuildID)
DstIsInternal = false;
}
if (!SrcIsInternal)
@@ -775,8 +775,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
// It's in bottom-up order with each frame in one line.
// Extract stack frames from sample
- while (!TraceIt.isAtEoF() &&
- !isLBRSample(TraceIt.getCurrentLine(), true, IsPreAggregated)) {
+ while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
uint64_t FrameAddr = 0;
StringRef FrameBuildID;
@@ -830,8 +829,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
// Skip other unrelated line, find the next valid LBR line
// Note that even for empty call stack, we should skip the address at the
// bottom, otherwise the following pass may generate a truncated callstack
- while (!TraceIt.isAtEoF() &&
- !isLBRSample(TraceIt.getCurrentLine(), true, IsPreAggregated)) {
+ while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
TraceIt.advance();
}
// Filter out broken stack sample. We may not have complete frame info
@@ -876,16 +874,14 @@ void HybridPerfReader::parseSample(TraceStream &TraceIt, uint64_t Count) {
// Parsing call stack and populate into PerfSample.CallStack
if (!extractCallstack(TraceIt, Sample->CallStack)) {
// Skip the next LBR line matched current call stack
- if (!TraceIt.isAtEoF() &&
- isLBRSample(TraceIt.getCurrentLine(), true, IsPreAggregated))
+ if (!TraceIt.isAtEoF() && isLBRSample(TraceIt.getCurrentLine(), true))
TraceIt.advance();
return;
}
warnIfMissingMMap();
- if (!TraceIt.isAtEoF() &&
- isLBRSample(TraceIt.getCurrentLine(), true, IsPreAggregated)) {
+ if (!TraceIt.isAtEoF() && isLBRSample(TraceIt.getCurrentLine(), true)) {
// Parsing LBR stack and populate into PerfSample.LBRStack
if (extractLBRStack(TraceIt, Sample->LBRStack)) {
if (IgnoreStackSamples) {
@@ -1227,6 +1223,10 @@ bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart,
return IsPreAggregated && Token.contains(":0x");
}
+bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
+ return isLBRSample(Line, CheckLineStart, IsPreAggregated);
+}
+
bool PerfScriptReader::isMMapEvent(StringRef Line) {
// Short cut to avoid string find is possible.
if (Line.empty() || Line.size() < 50)
diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h
index f06c06d038a7b..7feb02b8c94c6 100644
--- a/llvm/tools/llvm-profgen/PerfReader.h
+++ b/llvm/tools/llvm-profgen/PerfReader.h
@@ -634,6 +634,9 @@ class PerfScriptReader : public PerfReaderBase {
void setIsPreAggregated(bool V) { IsPreAggregated = V; }
+ // Check whether a given line is LBR sample
+ bool isLBRSample(StringRef Line, bool CheckLineStart);
+
protected:
// Check whether a given line is LBR sample
static bool isLBRSample(StringRef Line, bool CheckLineStart,
>From b251df355cfab48e5be9185847a24a57e788f2bd Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Fri, 1 May 2026 16:05:35 -0700
Subject: [PATCH 2/2] warn on mismatching buildid
Created using spr 1.3.4
---
llvm/tools/llvm-profgen/PerfReader.cpp | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index b23e983116216..e08ba5ea96035 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -676,12 +676,21 @@ static bool parseAddress(StringRef Str, uint64_t &Addr, bool HasPrefix,
}
/// Return the build ID to use for filtering perfscript addresses.
-/// If --filter-build-id is specified, use it as an override.
+/// If --filter-build-id is specified, use it as an override (with a warning
+/// if it doesn't match the binary's auto-detected build ID).
/// Otherwise, use the auto-detected value from the binary.
static StringRef getFilterBuildID(const ProfiledBinary *Binary) {
- if (FilterBuildID.getNumOccurrences() > 0)
- return FilterBuildID;
- return Binary->getFilterBuildID();
+ StringRef BinaryBuildID = Binary->getFilterBuildID();
+ if (FilterBuildID.getNumOccurrences() == 0)
+ return BinaryBuildID;
+ static bool Warned = false;
+ if (!Warned && !BinaryBuildID.empty() && FilterBuildID != BinaryBuildID) {
+ WithColor::warning() << "--filter-build-id=" << FilterBuildID
+ << " does not match binary build ID " << BinaryBuildID
+ << "\n";
+ Warned = true;
+ }
+ return FilterBuildID;
}
bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
More information about the llvm-branch-commits
mailing list