forked from OSchip/llvm-project
[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
This commit is contained in:
parent
d2df8d5a78
commit
14f4f63af5
|
@ -22,8 +22,8 @@ class RawMemProfReader {
|
|||
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.
|
||||
|
@ -34,6 +34,10 @@ public:
|
|||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -98,17 +98,22 @@ bool RawMemProfReader::hasFormat(const MemoryBuffer &Buffer) {
|
|||
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.
|
||||
|
||||
|
|
|
@ -34,9 +34,11 @@ RUN: llvm-profdata show --memory %p/Inputs/basic.memprofraw -o - | FileCheck %s
|
|||
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
|
||||
|
|
|
@ -36,15 +36,18 @@ RUN: llvm-profdata show --memory %p/Inputs/multi.memprofraw -o - | FileCheck %s
|
|||
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
|
||||
|
|
|
@ -2487,7 +2487,8 @@ static int showMemProfProfile(const std::string &Filename, raw_fd_ostream &OS) {
|
|||
|
||||
std::unique_ptr<llvm::memprof::RawMemProfReader> Reader(
|
||||
ReaderOr.get().release());
|
||||
Reader->printSummaries(OS);
|
||||
|
||||
Reader->printYAML(OS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue