[llvm-profgen][NFC] Reuse isLBRSample#191595
Merged
Merged
Conversation
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
Member
|
@llvm/pr-subscribers-pgo Author: Amir Ayupov (aaupov) ChangesReplace Full diff: https://github.com/llvm/llvm-project/pull/191595.diff 2 Files Affected:
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 9dda11a7ade50..b933a740ff55c 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -737,7 +737,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() && !TraceIt.getCurrentLine().starts_with(" 0x")) {
+ while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
uint64_t FrameAddr = 0;
if (parseAddress(FrameStr, FrameAddr)) {
@@ -785,7 +785,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() && !TraceIt.getCurrentLine().starts_with(" 0x")) {
+ while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
TraceIt.advance();
}
// Filter out broken stack sample. We may not have complete frame info
@@ -830,14 +830,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() && TraceIt.getCurrentLine().starts_with(" 0x"))
+ if (!TraceIt.isAtEoF() && isLBRSample(TraceIt.getCurrentLine(), true))
TraceIt.advance();
return;
}
warnIfMissingMMap();
- if (!TraceIt.isAtEoF() && TraceIt.getCurrentLine().starts_with(" 0x")) {
+ if (!TraceIt.isAtEoF() && isLBRSample(TraceIt.getCurrentLine(), true)) {
// Parsing LBR stack and populate into PerfSample.LBRStack
if (extractLBRStack(TraceIt, Sample->LBRStack)) {
if (IgnoreStackSamples) {
@@ -1162,13 +1162,18 @@ void PerfScriptReader::parseAndAggregateTrace() {
// 40062f 0x5c6313f/0x5c63170/P/-/-/0 0x5c630e7/0x5c63130/P/-/-/0 ...
// A heuristic for fast detection by checking whether a
// leading " 0x" and the '/' exist.
-bool PerfScriptReader::isLBRSample(StringRef Line) {
+bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
// Skip the leading instruction pointer
SmallVector<StringRef, 32> Records;
- Line.trim().split(Records, " ", 2, false);
+ if (!CheckLineStart)
+ Line = Line.trim();
+ Line.split(Records, " ", 2, CheckLineStart);
if (Records.size() < 2)
return false;
- if (Records[1].starts_with("0x") && Records[1].contains('/'))
+ StringRef Token = Records[1];
+ if (!Token.contains('/'))
+ return false;
+ if (Token.starts_with("0x"))
return true;
return false;
}
@@ -1213,7 +1218,7 @@ PerfContent PerfScriptReader::checkPerfScriptType(StringRef FileName) {
TraceIt.advance();
}
if (!TraceIt.isAtEoF()) {
- if (isLBRSample(TraceIt.getCurrentLine())) {
+ if (isLBRSample(TraceIt.getCurrentLine(), false)) {
if (Count > 0)
return HasAggCount ? PerfContent::AggLBRStack : PerfContent::LBRStack;
else
diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h
index 83c4fb0447c5c..358d61067a4ef 100644
--- a/llvm/tools/llvm-profgen/PerfReader.h
+++ b/llvm/tools/llvm-profgen/PerfReader.h
@@ -636,7 +636,7 @@ class PerfScriptReader : public PerfReaderBase {
protected:
// Check whether a given line is LBR sample
- static bool isLBRSample(StringRef Line);
+ static bool isLBRSample(StringRef Line, bool CheckLineStart);
// Check whether a given line is MMAP event
static bool isMMapEvent(StringRef Line);
// Update base address based on mmap events
|
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
HighW4y2H3ll
approved these changes
Apr 18, 2026
Created using spr 1.3.4 [skip ci]
enferex
pushed a commit
to enferex/llvm-project
that referenced
this pull request
May 5, 2026
Replace `StringRef::starts_with(" 0x")` calls with explicit
`isLBRSample` checks.
This is needed to support buildid-prefixed addresses in a follow-up
llvm#190863.
moar55
pushed a commit
to moar55/llvm-project
that referenced
this pull request
May 12, 2026
Replace `StringRef::starts_with(" 0x")` calls with explicit
`isLBRSample` checks.
This is needed to support buildid-prefixed addresses in a follow-up
llvm#190863.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace
StringRef::starts_with(" 0x")calls with explicitisLBRSamplechecks.This is needed to support buildid-prefixed addresses in a follow-up #190863.