[PATCH] D109638: [CSSPGO] Truncate stack samples with invalid return address.
Hongtao Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 10 17:49:35 PDT 2021
hoy updated this revision to Diff 372042.
hoy edited the summary of this revision.
hoy added a comment.
Updating D109638 <https://reviews.llvm.org/D109638>: [CSSPGO] Truncate stack samples with invalid return address.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109638/new/
https://reviews.llvm.org/D109638
Files:
llvm/tools/llvm-profgen/PerfReader.cpp
Index: llvm/tools/llvm-profgen/PerfReader.cpp
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.cpp
+++ llvm/tools/llvm-profgen/PerfReader.cpp
@@ -7,15 +7,23 @@
//===----------------------------------------------------------------------===//
#include "PerfReader.h"
#include "ProfileGenerator.h"
+#include "llvm/ADT/Statistic.h"
#include "llvm/Support/FileSystem.h"
+#define DEBUG_TYPE "perf-reader"
+
+STATISTIC(NumStackSamplesWithInvalidReturnAddress,
+ "Number of stack samples with an invalid return address");
+
+STATISTIC(NumStackSamples, "Number of stack samples");
+
static cl::opt<bool> ShowMmapEvents("show-mmap-events", cl::ReallyHidden,
cl::init(false), cl::ZeroOrMore,
cl::desc("Print binary load events."));
cl::opt<bool> SkipSymbolization("skip-symbolization", cl::ReallyHidden,
cl::init(false), cl::ZeroOrMore,
- cl::desc("Dump the unsumbolized profile to the "
+ cl::desc("Dump the unsymbolized profile to the "
"output file. It will show unwinder "
"output for CS profile generation."));
@@ -510,15 +518,24 @@
if (!Binary->addressIsCode(FrameAddr))
break;
- // We need to translate return address to call address
- // for non-leaf frames
+ // We need to translate return address to call address for non-leaf frames.
if (!CallStack.empty()) {
- FrameAddr = Binary->getCallAddrFromFrameAddr(FrameAddr);
+ auto I = Binary->getIndexForAddr(FrameAddr);
+ FrameAddr = I ? Binary->getAddressforIndex(I - 1) : 0;
+ // Stop at an invalid return address caused by bad unwinding. This could
+ // happen to frame-pointer-based unwinding and the callee functions that
+ // do not have the frame pointer chain set up.
+ if (!FrameAddr || !Binary->addressIsCall(FrameAddr)) {
+ NumStackSamplesWithInvalidReturnAddress++;
+ break;
+ }
}
CallStack.emplace_back(FrameAddr);
}
+ NumStackSamples++;
+
// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109638.372042.patch
Type: text/x-patch
Size: 2447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210911/eb965eb4/attachment.bin>
More information about the llvm-commits
mailing list