diff --git a/llvm/include/llvm/ProfileData/RawMemProfReader.h b/llvm/include/llvm/ProfileData/RawMemProfReader.h --- a/llvm/include/llvm/ProfileData/RawMemProfReader.h +++ b/llvm/include/llvm/ProfileData/RawMemProfReader.h @@ -22,8 +22,8 @@ public: RawMemProfReader(std::unique_ptr DataBuffer) : DataBuffer(std::move(DataBuffer)) {} - // Prints aggregate counts for each raw profile parsed from the DataBuffer. - void printSummaries(raw_ostream &OS) const; + // Prints the contents of the profile in YAML format. + void printYAML(raw_ostream &OS); // Return true if the \p DataBuffer starts with magic bytes indicating it is // a raw binary memprof profile. @@ -34,6 +34,10 @@ static Expected> create(const Twine &Path); private: + // Prints aggregate counts for each raw profile parsed from the DataBuffer in + // YAML format. + void printSummaries(raw_ostream &OS) const; + std::unique_ptr DataBuffer; }; diff --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp --- a/llvm/lib/ProfileData/RawMemProfReader.cpp +++ b/llvm/lib/ProfileData/RawMemProfReader.cpp @@ -98,17 +98,22 @@ return Magic == MEMPROF_RAW_MAGIC_64; } +void RawMemProfReader::printYAML(raw_ostream &OS) { + OS << "MemprofProfile:\n"; + printSummaries(OS); +} + void RawMemProfReader::printSummaries(raw_ostream &OS) const { - int Count = 0; const char *Next = DataBuffer->getBufferStart(); while (Next < DataBuffer->getBufferEnd()) { auto Summary = computeSummary(Next); - OS << "MemProf Profile " << ++Count << "\n"; - OS << " Version: " << Summary.Version << "\n"; - OS << " TotalSizeBytes: " << Summary.TotalSizeBytes << "\n"; - OS << " NumSegments: " << Summary.NumSegments << "\n"; - OS << " NumMIBInfo: " << Summary.NumMIBInfo << "\n"; - OS << " NumStackOffsets: " << Summary.NumStackOffsets << "\n"; + OS << " -\n"; + OS << " Header:\n"; + OS << " Version: " << Summary.Version << "\n"; + OS << " TotalSizeBytes: " << Summary.TotalSizeBytes << "\n"; + OS << " NumSegments: " << Summary.NumSegments << "\n"; + OS << " NumMibInfo: " << Summary.NumMIBInfo << "\n"; + OS << " NumStackOffsets: " << Summary.NumStackOffsets << "\n"; // TODO: Print the build ids once we can record them using the // sanitizer_procmaps library for linux. diff --git a/llvm/test/tools/llvm-profdata/memprof-basic.test b/llvm/test/tools/llvm-profdata/memprof-basic.test --- a/llvm/test/tools/llvm-profdata/memprof-basic.test +++ b/llvm/test/tools/llvm-profdata/memprof-basic.test @@ -34,9 +34,11 @@ We expect 3 MIB entries, 1 each for the malloc calls in the program and one additional entry from a realloc in glibc/libio/vasprintf.c. -CHECK: MemProf Profile 1 -CHECK: Version: 1 -CHECK: TotalSizeBytes: 1016 -CHECK: NumSegments: 9 -CHECK: NumMIBInfo: 3 -CHECK: NumStackOffsets: 3 +CHECK: MemprofProfile: +CHECK-NEXT: - +CHECK-NEXT: Header: +CHECK-NEXT: Version: 1 +CHECK-NEXT: TotalSizeBytes: 1016 +CHECK-NEXT: NumSegments: 9 +CHECK-NEXT: NumMibInfo: 3 +CHECK-NEXT: NumStackOffsets: 3 diff --git a/llvm/test/tools/llvm-profdata/memprof-multi.test b/llvm/test/tools/llvm-profdata/memprof-multi.test --- a/llvm/test/tools/llvm-profdata/memprof-multi.test +++ b/llvm/test/tools/llvm-profdata/memprof-multi.test @@ -36,15 +36,18 @@ We expect 2 MIB entries, 1 each for the malloc calls in the program. Unlike the memprof-basic.test we do not see any allocation from glibc. -CHECK: MemProf Profile 1 -CHECK: Version: 1 -CHECK: TotalSizeBytes: 864 -CHECK: NumSegments: 9 -CHECK: NumMIBInfo: 2 -CHECK: NumStackOffsets: 2 -CHECK: MemProf Profile 2 -CHECK: Version: 1 -CHECK: TotalSizeBytes: 864 -CHECK: NumSegments: 9 -CHECK: NumMIBInfo: 2 -CHECK: NumStackOffsets: 2 +CHECK: MemprofProfile: +CHECK-NEXT: - +CHECK-NEXT: Header: +CHECK-NEXT: Version: 1 +CHECK-NEXT: TotalSizeBytes: 864 +CHECK-NEXT: NumSegments: 9 +CHECK-NEXT: NumMibInfo: 2 +CHECK-NEXT: NumStackOffsets: 2 +CHECK-NEXT: - +CHECK-NEXT: Header: +CHECK-NEXT: Version: 1 +CHECK-NEXT: TotalSizeBytes: 864 +CHECK-NEXT: NumSegments: 9 +CHECK-NEXT: NumMibInfo: 2 +CHECK-NEXT: NumStackOffsets: 2 diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -2480,7 +2480,8 @@ std::unique_ptr Reader( ReaderOr.get().release()); - Reader->printSummaries(OS); + + Reader->printYAML(OS); return 0; }