Skip to content

Commit c5d8fcf

Browse files
resolve comments
1 parent f63fea6 commit c5d8fcf

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

llvm/include/llvm/ProfileData/MemProfYAML.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ template <> struct MappingTraits<memprof::YamlDataAccessProfData> {
264264
template <> struct MappingTraits<memprof::AllMemProfData> {
265265
static void mapping(IO &Io, memprof::AllMemProfData &Data) {
266266
Io.mapRequired("HeapProfileRecords", Data.HeapProfileRecords);
267-
Io.mapOptional("DataAccessProfiles", Data.YamlifiedDataAccessProfiles);
267+
// Map data access profiles if reading input, or if writing output &&
268+
// the struct is populated.
269+
if (!Io.outputting() || !Data.YamlifiedDataAccessProfiles.isEmpty())
270+
Io.mapOptional("DataAccessProfiles", Data.YamlifiedDataAccessProfiles);
268271
}
269272
};
270273

llvm/lib/ProfileData/IndexedMemProfData.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static Error writeMemProfRadixTreeBased(
228228
OS.write(0ULL); // Reserve space for the memprof call stack payload offset.
229229
OS.write(0ULL); // Reserve space for the memprof record payload offset.
230230
OS.write(0ULL); // Reserve space for the memprof record table offset.
231-
if (Version == memprof::Version4)
231+
if (Version >= memprof::Version4)
232232
OS.write(0ULL); // Reserve space for the data access profile offset.
233233

234234
auto Schema = memprof::getHotColdSchema();
@@ -258,6 +258,8 @@ static Error writeMemProfRadixTreeBased(
258258

259259
uint64_t DataAccessProfOffset = 0;
260260
if (DataAccessProfileData.has_value()) {
261+
assert(Version >= memprof::Version4 &&
262+
"Data access profiles are added starting from v4");
261263
DataAccessProfOffset = OS.tell();
262264
if (Error E = (*DataAccessProfileData).get().serialize(OS))
263265
return E;
@@ -274,7 +276,7 @@ static Error writeMemProfRadixTreeBased(
274276
RecordPayloadOffset,
275277
RecordTableOffset,
276278
};
277-
if (Version == memprof::Version4)
279+
if (Version >= memprof::Version4)
278280
Header.push_back(DataAccessProfOffset);
279281
OS.patch({{HeaderUpdatePos, Header}});
280282

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
; RUN: split-file %s %t
22
; COM: The text format only supports the latest version.
3+
4+
; Verify that the YAML output is identical to the YAML input.
5+
; memprof-in.yaml has both heap profile records and data access profiles.
36
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in.yaml -o %t/memprof-out.indexed
47
; RUN: llvm-profdata show --memory %t/memprof-out.indexed > %t/memprof-out.yaml
58
; RUN: diff -b %t/memprof-in.yaml %t/memprof-out.yaml
69

7-
; Verify that the YAML output is identical to the YAML input.
10+
; memprof-in-no-dap has empty data access profiles.
11+
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in-no-dap.yaml -o %t/memprof-out.indexed
12+
; RUN: llvm-profdata show --memory %t/memprof-out.indexed > %t/memprof-out-no-dap.yaml
13+
; RUN: diff -b %t/memprof-in-no-dap.yaml %t/memprof-out-no-dap.yaml
14+
815
;--- memprof-in.yaml
916
---
1017
HeapProfileRecords:
@@ -38,12 +45,48 @@ HeapProfileRecords:
3845
DataAccessProfiles:
3946
SampledRecords:
4047
- Symbol: abcde
48+
Locations:
49+
- FileName: file2.h
50+
Line: 123
51+
- FileName: file3.cpp
52+
Line: 456
4153
- Hash: 101010
4254
Locations:
43-
- FileName: file
55+
- FileName: file.cpp
4456
Line: 233
4557
KnownColdSymbols:
4658
- foo
4759
- bar
4860
KnownColdHashes: [ 999, 1001 ]
4961
...
62+
;--- memprof-in-no-dap.yaml
63+
---
64+
HeapProfileRecords:
65+
- GUID: 0xdeadbeef12345678
66+
AllocSites:
67+
- Callstack:
68+
- { Function: 0x1111111111111111, LineOffset: 11, Column: 10, IsInlineFrame: true }
69+
- { Function: 0x2222222222222222, LineOffset: 22, Column: 20, IsInlineFrame: false }
70+
MemInfoBlock:
71+
AllocCount: 111
72+
TotalSize: 222
73+
TotalLifetime: 333
74+
TotalLifetimeAccessDensity: 444
75+
- Callstack:
76+
- { Function: 0x3333333333333333, LineOffset: 33, Column: 30, IsInlineFrame: false }
77+
- { Function: 0x4444444444444444, LineOffset: 44, Column: 40, IsInlineFrame: true }
78+
MemInfoBlock:
79+
AllocCount: 555
80+
TotalSize: 666
81+
TotalLifetime: 777
82+
TotalLifetimeAccessDensity: 888
83+
CallSites:
84+
- Frames:
85+
- { Function: 0x5555555555555555, LineOffset: 55, Column: 50, IsInlineFrame: true }
86+
- { Function: 0x6666666666666666, LineOffset: 66, Column: 60, IsInlineFrame: false }
87+
CalleeGuids: [ 0x100, 0x200 ]
88+
- Frames:
89+
- { Function: 0x7777777777777777, LineOffset: 77, Column: 70, IsInlineFrame: true }
90+
- { Function: 0x8888888888888888, LineOffset: 88, Column: 80, IsInlineFrame: false }
91+
CalleeGuids: [ 0x300 ]
92+
...

0 commit comments

Comments
 (0)