public:
RawMemProfReader(std::unique_ptr<MemoryBuffer> 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.
static Expected<std::unique_ptr<RawMemProfReader>> 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<MemoryBuffer> DataBuffer;
};
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.
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
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
std::unique_ptr<llvm::memprof::RawMemProfReader> Reader(
ReaderOr.get().release());
- Reader->printSummaries(OS);
+
+ Reader->printYAML(OS);
return 0;
}