summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwlei <wlei@fb.com>2021-01-20 17:54:03 -0800
committerTom Stellard <tstellar@redhat.com>2021-02-19 21:21:12 -0800
commitdb88d92217f185d9ab5b8f0a0eddc5dc9ad30659 (patch)
treeee486de04a9a64cd3811649aeaa9370358961280
parent87c27020cc6466ae33550f1f1f55d5989afaca2e (diff)
downloadllvm-db88d92217f185d9ab5b8f0a0eddc5dc9ad30659.tar.gz
[CSSPGO][llvm-profgen] Fix bug with parsing hybrid sample trace line
when we skip the call stack starting with an external address, we should also skip the bottom LBR entry, otherwise it will cause a truncated context issue. Reviewed By: hoy, wenlei Differential Revision: https://reviews.llvm.org/D95480
-rw-r--r--llvm/test/tools/llvm-profgen/Inputs/inline-cs-noprobe.perfscript6
-rw-r--r--llvm/tools/llvm-profgen/PerfReader.cpp12
2 files changed, 13 insertions, 5 deletions
diff --git a/llvm/test/tools/llvm-profgen/Inputs/inline-cs-noprobe.perfscript b/llvm/test/tools/llvm-profgen/Inputs/inline-cs-noprobe.perfscript
index 7ef76dcd3884..116bd0a2c4c1 100644
--- a/llvm/test/tools/llvm-profgen/Inputs/inline-cs-noprobe.perfscript
+++ b/llvm/test/tools/llvm-profgen/Inputs/inline-cs-noprobe.perfscript
@@ -1,5 +1,11 @@
PERF_RECORD_MMAP2 2854748/2854748: [0x400000(0x1000) @ 0 00:1d 123291722 526021]: r-xp /home/inline-cs-noprobe.perfbin
+; test for an external or invalid top address, should skip the whole sample
+
+ ffffffff
+ 40067e
+ 5541f689495641d7
+ 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x40069b/0x400670/M/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0 0x4006c8/0x40067e/P/-/-/0
40067e
5541f689495641d7
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 787bde28400f..e59d8d93381b 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -437,11 +437,12 @@ bool PerfReader::extractCallstack(TraceStream &TraceIt,
ProfiledBinary *Binary = nullptr;
while (!TraceIt.isAtEoF() && !TraceIt.getCurrentLine().startswith(" 0x")) {
StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
- // We might get an empty line at the beginning or comments, skip it
uint64_t FrameAddr = 0;
if (FrameStr.getAsInteger(16, FrameAddr)) {
+ // We might parse a non-perf sample line like empty line and comments,
+ // skip it
TraceIt.advance();
- break;
+ return false;
}
TraceIt.advance();
if (!Binary) {
@@ -468,9 +469,9 @@ bool PerfReader::extractCallstack(TraceStream &TraceIt,
CallStack.emplace_back(FrameAddr);
}
- if (CallStack.empty())
- return false;
// 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().startswith(" 0x")) {
TraceIt.advance();
}
@@ -482,7 +483,8 @@ bool PerfReader::extractCallstack(TraceStream &TraceIt,
// of such case - when sample landed in prolog/epilog, somehow stack
// walking will be broken in an unexpected way that higher frames will be
// missing.
- return !Binary->addressInPrologEpilog(CallStack.front());
+ return !CallStack.empty() &&
+ !Binary->addressInPrologEpilog(CallStack.front());
}
void PerfReader::parseHybridSample(TraceStream &TraceIt) {