Skip to content

Commit 14f4f63

Browse files
author
Snehasish Kumar
committed
[memprof] Print out the summary in YAML format.
Print out the profile summary in YAML format to make it easier to for tools and tests to read in the contents of the raw profile. Differential Revision: https://reviews.llvm.org/D116783
1 parent d2df8d5 commit 14f4f63

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed

llvm/include/llvm/ProfileData/RawMemProfReader.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class RawMemProfReader {
2222
public:
2323
RawMemProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
2424
: DataBuffer(std::move(DataBuffer)) {}
25-
// Prints aggregate counts for each raw profile parsed from the DataBuffer.
26-
void printSummaries(raw_ostream &OS) const;
25+
// Prints the contents of the profile in YAML format.
26+
void printYAML(raw_ostream &OS);
2727

2828
// Return true if the \p DataBuffer starts with magic bytes indicating it is
2929
// a raw binary memprof profile.
@@ -34,6 +34,10 @@ class RawMemProfReader {
3434
static Expected<std::unique_ptr<RawMemProfReader>> create(const Twine &Path);
3535

3636
private:
37+
// Prints aggregate counts for each raw profile parsed from the DataBuffer in
38+
// YAML format.
39+
void printSummaries(raw_ostream &OS) const;
40+
3741
std::unique_ptr<MemoryBuffer> DataBuffer;
3842
};
3943

llvm/lib/ProfileData/RawMemProfReader.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,22 @@ bool RawMemProfReader::hasFormat(const MemoryBuffer &Buffer) {
9898
return Magic == MEMPROF_RAW_MAGIC_64;
9999
}
100100

101+
void RawMemProfReader::printYAML(raw_ostream &OS) {
102+
OS << "MemprofProfile:\n";
103+
printSummaries(OS);
104+
}
105+
101106
void RawMemProfReader::printSummaries(raw_ostream &OS) const {
102-
int Count = 0;
103107
const char *Next = DataBuffer->getBufferStart();
104108
while (Next < DataBuffer->getBufferEnd()) {
105109
auto Summary = computeSummary(Next);
106-
OS << "MemProf Profile " << ++Count << "\n";
107-
OS << " Version: " << Summary.Version << "\n";
108-
OS << " TotalSizeBytes: " << Summary.TotalSizeBytes << "\n";
109-
OS << " NumSegments: " << Summary.NumSegments << "\n";
110-
OS << " NumMIBInfo: " << Summary.NumMIBInfo << "\n";
111-
OS << " NumStackOffsets: " << Summary.NumStackOffsets << "\n";
110+
OS << " -\n";
111+
OS << " Header:\n";
112+
OS << " Version: " << Summary.Version << "\n";
113+
OS << " TotalSizeBytes: " << Summary.TotalSizeBytes << "\n";
114+
OS << " NumSegments: " << Summary.NumSegments << "\n";
115+
OS << " NumMibInfo: " << Summary.NumMIBInfo << "\n";
116+
OS << " NumStackOffsets: " << Summary.NumStackOffsets << "\n";
112117
// TODO: Print the build ids once we can record them using the
113118
// sanitizer_procmaps library for linux.
114119

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ RUN: llvm-profdata show --memory %p/Inputs/basic.memprofraw -o - | FileCheck %s
3434
We expect 3 MIB entries, 1 each for the malloc calls in the program and one
3535
additional entry from a realloc in glibc/libio/vasprintf.c.
3636

37-
CHECK: MemProf Profile 1
38-
CHECK: Version: 1
39-
CHECK: TotalSizeBytes: 1016
40-
CHECK: NumSegments: 9
41-
CHECK: NumMIBInfo: 3
42-
CHECK: NumStackOffsets: 3
37+
CHECK: MemprofProfile:
38+
CHECK-NEXT: -
39+
CHECK-NEXT: Header:
40+
CHECK-NEXT: Version: 1
41+
CHECK-NEXT: TotalSizeBytes: 1016
42+
CHECK-NEXT: NumSegments: 9
43+
CHECK-NEXT: NumMibInfo: 3
44+
CHECK-NEXT: NumStackOffsets: 3

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ RUN: llvm-profdata show --memory %p/Inputs/multi.memprofraw -o - | FileCheck %s
3636
We expect 2 MIB entries, 1 each for the malloc calls in the program. Unlike the
3737
memprof-basic.test we do not see any allocation from glibc.
3838

39-
CHECK: MemProf Profile 1
40-
CHECK: Version: 1
41-
CHECK: TotalSizeBytes: 864
42-
CHECK: NumSegments: 9
43-
CHECK: NumMIBInfo: 2
44-
CHECK: NumStackOffsets: 2
45-
CHECK: MemProf Profile 2
46-
CHECK: Version: 1
47-
CHECK: TotalSizeBytes: 864
48-
CHECK: NumSegments: 9
49-
CHECK: NumMIBInfo: 2
50-
CHECK: NumStackOffsets: 2
39+
CHECK: MemprofProfile:
40+
CHECK-NEXT: -
41+
CHECK-NEXT: Header:
42+
CHECK-NEXT: Version: 1
43+
CHECK-NEXT: TotalSizeBytes: 864
44+
CHECK-NEXT: NumSegments: 9
45+
CHECK-NEXT: NumMibInfo: 2
46+
CHECK-NEXT: NumStackOffsets: 2
47+
CHECK-NEXT: -
48+
CHECK-NEXT: Header:
49+
CHECK-NEXT: Version: 1
50+
CHECK-NEXT: TotalSizeBytes: 864
51+
CHECK-NEXT: NumSegments: 9
52+
CHECK-NEXT: NumMibInfo: 2
53+
CHECK-NEXT: NumStackOffsets: 2

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,8 @@ static int showMemProfProfile(const std::string &Filename, raw_fd_ostream &OS) {
24872487

24882488
std::unique_ptr<llvm::memprof::RawMemProfReader> Reader(
24892489
ReaderOr.get().release());
2490-
Reader->printSummaries(OS);
2490+
2491+
Reader->printYAML(OS);
24912492
return 0;
24922493
}
24932494

0 commit comments

Comments
 (0)