[llvm] 49c048a - [memprof] Add a test to verify callstack order.
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 16 10:11:22 PDT 2022
Author: Snehasish Kumar
Date: 2022-03-16T10:10:57-07:00
New Revision: 49c048add4c980936fc2918838288ae2d795587d
URL: https://github.com/llvm/llvm-project/commit/49c048add4c980936fc2918838288ae2d795587d
DIFF: https://github.com/llvm/llvm-project/commit/49c048add4c980936fc2918838288ae2d795587d.diff
LOG: [memprof] Add a test to verify callstack order.
We add to ensure that we are observing the correct callstack order in memprof
during symbolization. There was some confusion whether the order of
DIFrame objects were reversed but in reality the leaf function is at
index 0 so no code changes are required.
Differential Revision: https://reviews.llvm.org/D121759
Added:
llvm/test/tools/llvm-profdata/Inputs/inline.memprofraw
llvm/test/tools/llvm-profdata/Inputs/memprof-inline.exe
llvm/test/tools/llvm-profdata/memprof-inline.test
Modified:
llvm/lib/ProfileData/RawMemProfReader.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp
index 72c6f2f4a68f0..71e6629856807 100644
--- a/llvm/lib/ProfileData/RawMemProfReader.cpp
+++ b/llvm/lib/ProfileData/RawMemProfReader.cpp
@@ -327,6 +327,11 @@ Error RawMemProfReader::symbolizeAndFilterStackFrames() {
for (size_t I = 0; I < DI.getNumberOfFrames(); I++) {
const auto &Frame = DI.getFrame(I);
+ LLVM_DEBUG(
+ // Print out the name to guid mapping for debugging.
+ llvm::dbgs() << "FunctionName: " << Frame.FunctionName << " GUID: "
+ << Function::getGUID(trimSuffix(Frame.FunctionName))
+ << "\n";);
SymbolizedFrame[VAddr].emplace_back(
// We use the function guid which we expect to be a uint64_t. At
// this time, it is the lower 64 bits of the md5 of the function
diff --git a/llvm/test/tools/llvm-profdata/Inputs/inline.memprofraw b/llvm/test/tools/llvm-profdata/Inputs/inline.memprofraw
new file mode 100644
index 0000000000000..813ee6e47045c
Binary files /dev/null and b/llvm/test/tools/llvm-profdata/Inputs/inline.memprofraw
diff er
diff --git a/llvm/test/tools/llvm-profdata/Inputs/memprof-inline.exe b/llvm/test/tools/llvm-profdata/Inputs/memprof-inline.exe
new file mode 100755
index 0000000000000..9b6fd16e9a272
Binary files /dev/null and b/llvm/test/tools/llvm-profdata/Inputs/memprof-inline.exe
diff er
diff --git a/llvm/test/tools/llvm-profdata/memprof-inline.test b/llvm/test/tools/llvm-profdata/memprof-inline.test
new file mode 100644
index 0000000000000..ecf4f178a9743
--- /dev/null
+++ b/llvm/test/tools/llvm-profdata/memprof-inline.test
@@ -0,0 +1,106 @@
+REQUIRES: x86_64-linux
+
+The input raw profile test has been generated from the following source code:
+
+```
+#include <stdlib.h>
+#include <string.h>
+
+__attribute__((always_inline))
+void qux(int x) {
+ char *ptr = malloc(x);
+ memset(ptr, 0, x);
+ free(ptr);
+}
+
+__attribute__((noinline))
+void foo(int x){ qux(x); }
+
+__attribute__((noinline))
+void bar(int x) { foo(x); }
+
+int main(int argc, char **argv) {
+ bar(argc);
+ return 0;
+}
+```
+
+Compile and run with the following commands:
+
+```
+bin/clang -fuse-ld=lld -Wl,--no-rosegment -gmlt -fdebug-info-for-profiling \
+ -fmemory-profile -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer \
+ -fno-optimize-sibling-calls -m64 -Wl,-build-id inline.c -o memprof-inline.exe
+
+env MEMPROF_OPTIONS=log_path=stdout ./memprof-inline.exe > inline.memprofraw
+```
+
+From a debug run we collect the name to guid mappings to ensure that the
+ordering we observe is as expected.
+
+```
+build-dbg/bin/llvm-profdata show --memory --debug-only=memprof \
+ inline.memprofraw --profiled-binary memprof-inline.exe
+
+FunctionName: qux GUID: 15505678318020221912
+FunctionName: foo GUID: 6699318081062747564
+FunctionName: bar GUID: 16434608426314478903
+FunctionName: main GUID: 15822663052811949562
+
+[..omit output here which is checked below..]
+```
+
+RUN: llvm-profdata show --memory %p/Inputs/inline.memprofraw --profiled-binary %p/Inputs/memprof-inline.exe
+
+CHECK: MemprofProfile:
+CHECK-NEXT: -
+CHECK-NEXT: Header:
+CHECK-NEXT: Version: 1
+CHECK-NEXT: TotalSizeBytes: 880
+CHECK-NEXT: NumSegments: 9
+CHECK-NEXT: NumMibInfo: 2
+CHECK-NEXT: NumStackOffsets: 2
+CHECK-NEXT: Records:
+CHECK-NEXT: -
+CHECK-NEXT: Callstack:
+CHECK-NEXT: -
+CHECK-NEXT: Function: 15505678318020221912
+CHECK-NEXT: LineOffset: 1
+CHECK-NEXT: Column: 15
+CHECK-NEXT: Inline: 0
+CHECK-NEXT: -
+CHECK-NEXT: Function: 6699318081062747564
+CHECK-NEXT: LineOffset: 0
+CHECK-NEXT: Column: 18
+CHECK-NEXT: Inline: 1
+CHECK-NEXT: -
+CHECK-NEXT: Function: 16434608426314478903
+CHECK-NEXT: LineOffset: 0
+CHECK-NEXT: Column: 19
+CHECK-NEXT: Inline: 0
+CHECK-NEXT: -
+CHECK-NEXT: Function: 15822663052811949562
+CHECK-NEXT: LineOffset: 1
+CHECK-NEXT: Column: 3
+CHECK-NEXT: Inline: 0
+CHECK-NEXT: MemInfoBlock:
+CHECK-NEXT: AllocCount: 1
+CHECK-NEXT: TotalAccessCount: 1
+CHECK-NEXT: MinAccessCount: 1
+CHECK-NEXT: MaxAccessCount: 1
+CHECK-NEXT: TotalSize: 1
+CHECK-NEXT: MinSize: 1
+CHECK-NEXT: MaxSize: 1
+CHECK-NEXT: AllocTimestamp: 894
+CHECK-NEXT: DeallocTimestamp: 894
+CHECK-NEXT: TotalLifetime: 0
+CHECK-NEXT: MinLifetime: 0
+CHECK-NEXT: MaxLifetime: 0
+CHECK-NEXT: AllocCpuId: 23
+CHECK-NEXT: DeallocCpuId: 23
+CHECK-NEXT: NumMigratedCpu: 0
+CHECK-NEXT: NumLifetimeOverlaps: 0
+CHECK-NEXT: NumSameAllocCpu: 0
+CHECK-NEXT: NumSameDeallocCpu: 0
+CHECK-NEXT: DataTypeId: {{[0-9]+}}
+
More information about the llvm-commits
mailing list