Skip to content

Commit 7f06318

Browse files
committed
[MemProf] Add option to print function GUIDs during matching
For debugging, add -memprof-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 50916a4 commit 7f06318

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
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-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"),
@@ -562,6 +567,9 @@ static void readMemprof(Module &M, Function &F,
562567
// linkage function.
563568
auto FuncName = F.getName();
564569
auto FuncGUID = Function::getGUIDAssumingExternalLinkage(FuncName);
570+
if (PrintFunctionGuids)
571+
errs() << "MemProf: Function GUID " << FuncGUID << " is " << FuncName
572+
<< "\n";
565573
std::optional<memprof::MemProfRecord> MemProfRec;
566574
auto Err = MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec);
567575
if (Err) {

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

Lines changed: 8 additions & 1 deletion
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 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-function-guids -S 2>&1 | FileCheck %s
3030

3131
;--- memprof-dump-matched-alloc-site.yaml
3232
---
@@ -77,6 +77,13 @@ HeapProfileRecords:
7777
# Kept empty here because this section is irrelevant for this test.
7878
...
7979
;--- memprof-dump-matched-alloc-site.ll
80+
81+
;; From -memprof-function-guids
82+
; CHECK: MemProf: Function GUID 4708092051066754107 is _Z2f1v
83+
; CHECK: MemProf: Function GUID 14255129117669598641 is _Z2f2v
84+
; CHECK: MemProf: Function GUID 2771528421763978342 is _Z2f3v
85+
86+
;; From -memprof-print-match-info
8087
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 1 frames
8188
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 2 frames
8289
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 3 frames

0 commit comments

Comments
 (0)