Skip to content

Commit b889df3

Browse files
[MemProf] Add option to print function GUIDs during matching (#170946)
For debugging, add -memprof-print-function-guids option that will cause memprof matching to emit the computed function GUID for every function definition in the module to stderr. This is helpful because the profile only contains the function GUID and not the names.
1 parent 90e3ac6 commit b889df3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/lib/Transforms/Instrumentation/MemProfUse.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ static cl::opt<bool>
6262
"context in this module's profiles"),
6363
cl::Hidden, cl::init(false));
6464

65+
static cl::opt<bool>
66+
PrintFunctionGuids("memprof-print-function-guids",
67+
cl::desc("Print function GUIDs computed for matching"),
68+
cl::Hidden, cl::init(false));
69+
6570
static cl::opt<bool>
6671
SalvageStaleProfile("memprof-salvage-stale-profile",
6772
cl::desc("Salvage stale MemProf profile"),
@@ -577,6 +582,9 @@ static void readMemprof(Module &M, Function &F,
577582
// linkage function.
578583
auto FuncName = F.getName();
579584
auto FuncGUID = Function::getGUIDAssumingExternalLinkage(FuncName);
585+
if (PrintFunctionGuids)
586+
errs() << "MemProf: Function GUID " << FuncGUID << " is " << FuncName
587+
<< "\n";
580588
std::optional<memprof::MemProfRecord> MemProfRec;
581589
auto Err = MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec);
582590
if (Err) {

llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
; REQUIRES: x86_64-linux
2727
; RUN: split-file %s %t
2828
; RUN: llvm-profdata merge %t/memprof-dump-matched-alloc-site.yaml -o %t/memprof-dump-matched-alloc-site.memprofdata
29-
; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -S -pass-remarks=memprof 2>&1 | FileCheck %s
29+
; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -memprof-print-function-guids -S -pass-remarks=memprof 2>&1 | FileCheck %s
3030

3131
;--- memprof-dump-matched-alloc-site.yaml
3232
---
@@ -78,9 +78,12 @@ HeapProfileRecords:
7878
...
7979
;--- memprof-dump-matched-alloc-site.ll
8080

81-
;; From -pass-remarks=memprof
81+
;; From -pass-remarks=memprof and -memprof-print-function-guids
82+
; CHECK: MemProf: Function GUID 4708092051066754107 is _Z2f1v
8283
; CHECK: remark: memprof-dump-matched-alloc-site.cc:1:21: call in function _Z2f1v matched alloc context with alloc type notcold total size 3 full context id 5736731103568718490 frame count 1
84+
; CHECK: MemProf: Function GUID 14255129117669598641 is _Z2f2v
8385
; CHECK: remark: memprof-dump-matched-alloc-site.cc:1:21: call in function _Z2f2v matched alloc context with alloc type notcold total size 3 full context id 5736731103568718490 frame count 2
86+
; CHECK: MemProf: Function GUID 2771528421763978342 is _Z2f3v
8487
; CHECK: remark: memprof-dump-matched-alloc-site.cc:1:21: call in function _Z2f3v matched alloc context with alloc type notcold total size 3 full context id 5736731103568718490 frame count 3
8588

8689
;; From -memprof-print-match-info

0 commit comments

Comments
 (0)