Skip to content

Commit 34fbf1f

Browse files
[memprof] Make the AllocSites and CallSites sections optional in YAML (#156226)
This patch makes the AllocSites and CallSites sections optional in the YAML format. This is useful for situations where a function has only one section.
1 parent e3512fb commit 34fbf1f

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

llvm/include/llvm/ProfileData/MemProfYAML.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ template <> struct MappingTraits<memprof::CallSiteInfo> {
217217
template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
218218
static void mapping(IO &Io, memprof::GUIDMemProfRecordPair &Pair) {
219219
Io.mapRequired("GUID", Pair.GUID);
220-
Io.mapRequired("AllocSites", Pair.Record.AllocSites);
221-
Io.mapRequired("CallSites", Pair.Record.CallSites);
220+
Io.mapOptional("AllocSites", Pair.Record.AllocSites);
221+
Io.mapOptional("CallSites", Pair.Record.CallSites);
222222
}
223223
};
224224

llvm/test/tools/llvm-profdata/memprof-yaml.test

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
; RUN: llvm-profdata show --memory %t/memprof-out-v3.indexed > %t/memprof-out-v3.yaml
1414
; RUN: diff -b %t/memprof-out-v3.yaml %t/memprof-in-v3.yaml
1515

16+
; Make sure we can ingest a YAML profile containing AllocSites only.
17+
; That is, CallSites are missing.
18+
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in-alloc-sites-only.yaml -o %t/memprof-out-alloc-sites-only.indexed
19+
; RUN: llvm-profdata show --memory %t/memprof-out-alloc-sites-only.indexed > %t/memprof-out-alloc-sites-only.yaml
20+
; RUN: diff -b %t/memprof-out-alloc-sites-only.yaml %t/memprof-in-alloc-sites-only.yaml
21+
22+
; Make sure we can ingest a YAML profile containing CallSites only.
23+
; That is, AllocSites are missing.
24+
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in-call-sites-only.yaml -o %t/memprof-out-call-sites-only.indexed
25+
; RUN: llvm-profdata show --memory %t/memprof-out-call-sites-only.indexed > %t/memprof-out-call-sites-only.yaml
26+
; RUN: diff -b %t/memprof-out-call-sites-only.yaml %t/memprof-in-call-sites-only.yaml
27+
1628
; memprof-in-no-dap.yaml has empty data access profiles.
1729
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in-no-dap.yaml -o %t/memprof-out.indexed
1830
; RUN: llvm-profdata show --memory %t/memprof-out.indexed > %t/memprof-out-no-dap.yaml
@@ -117,6 +129,58 @@ HeapProfileRecords:
117129
- { Function: 0x7777777777777777, LineOffset: 77, Column: 70, IsInlineFrame: true }
118130
- { Function: 0x8888888888888888, LineOffset: 88, Column: 80, IsInlineFrame: false }
119131
...
132+
;--- memprof-in-alloc-sites-only.yaml
133+
---
134+
# MemProfSummary:
135+
# Total contexts: 2
136+
# Total cold contexts: 0
137+
# Total hot contexts: 0
138+
# Maximum cold context total size: 0
139+
# Maximum warm context total size: 666
140+
# Maximum hot context total size: 0
141+
---
142+
HeapProfileRecords:
143+
- GUID: 0xdeadbeef12345678
144+
AllocSites:
145+
- Callstack:
146+
- { Function: 0x1111111111111111, LineOffset: 11, Column: 10, IsInlineFrame: true }
147+
- { Function: 0x2222222222222222, LineOffset: 22, Column: 20, IsInlineFrame: false }
148+
MemInfoBlock:
149+
AllocCount: 111
150+
TotalSize: 222
151+
TotalLifetime: 333
152+
TotalLifetimeAccessDensity: 444
153+
- Callstack:
154+
- { Function: 0x3333333333333333, LineOffset: 33, Column: 30, IsInlineFrame: false }
155+
- { Function: 0x4444444444444444, LineOffset: 44, Column: 40, IsInlineFrame: true }
156+
MemInfoBlock:
157+
AllocCount: 555
158+
TotalSize: 666
159+
TotalLifetime: 777
160+
TotalLifetimeAccessDensity: 888
161+
...
162+
;--- memprof-in-call-sites-only.yaml
163+
---
164+
# MemProfSummary:
165+
# Total contexts: 0
166+
# Total cold contexts: 0
167+
# Total hot contexts: 0
168+
# Maximum cold context total size: 0
169+
# Maximum warm context total size: 0
170+
# Maximum hot context total size: 0
171+
---
172+
HeapProfileRecords:
173+
- GUID: 0xdeadbeef12345678
174+
CallSites:
175+
- Frames:
176+
- { Function: 0x5555555555555555, LineOffset: 55, Column: 50, IsInlineFrame: true }
177+
- { Function: 0x6666666666666666, LineOffset: 66, Column: 60, IsInlineFrame: false }
178+
CalleeGuids: [ 0x100, 0x200 ]
179+
- Frames:
180+
- { Function: 0x7777777777777777, LineOffset: 77, Column: 70, IsInlineFrame: true }
181+
- { Function: 0x8888888888888888, LineOffset: 88, Column: 80, IsInlineFrame: false }
182+
CalleeGuids: [ 0x300 ]
183+
...
120184
;--- memprof-in-no-dap.yaml
121185
---
122186
# MemProfSummary:

0 commit comments

Comments
 (0)