[llvm] 14f4f63 - [memprof] Print out the summary in YAML format.

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 14:38:04 PST 2022


Author: Snehasish Kumar
Date: 2022-02-03T14:33:50-08:00
New Revision: 14f4f63af5ca501dd6cc7d766be6edb6f7c7d718

URL: https://github.com/llvm/llvm-project/commit/14f4f63af5ca501dd6cc7d766be6edb6f7c7d718
DIFF: https://github.com/llvm/llvm-project/commit/14f4f63af5ca501dd6cc7d766be6edb6f7c7d718.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/RawMemProfReader.h
    llvm/lib/ProfileData/RawMemProfReader.cpp
    llvm/test/tools/llvm-profdata/memprof-basic.test
    llvm/test/tools/llvm-profdata/memprof-multi.test
    llvm/tools/llvm-profdata/llvm-profdata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/RawMemProfReader.h b/llvm/include/llvm/ProfileData/RawMemProfReader.h
index 45544927a86f7..5041f54c46ad2 100644
--- a/llvm/include/llvm/ProfileData/RawMemProfReader.h
+++ b/llvm/include/llvm/ProfileData/RawMemProfReader.h
@@ -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 @@ class RawMemProfReader {
   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;
 };
 

diff  --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp
index f8d13c74fac39..f6c59cdf6663d 100644
--- a/llvm/lib/ProfileData/RawMemProfReader.cpp
+++ b/llvm/lib/ProfileData/RawMemProfReader.cpp
@@ -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.
 

diff  --git a/llvm/test/tools/llvm-profdata/memprof-basic.test b/llvm/test/tools/llvm-profdata/memprof-basic.test
index 321119ba566ae..8e4adaae5577e 100644
--- a/llvm/test/tools/llvm-profdata/memprof-basic.test
+++ b/llvm/test/tools/llvm-profdata/memprof-basic.test
@@ -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

diff  --git a/llvm/test/tools/llvm-profdata/memprof-multi.test b/llvm/test/tools/llvm-profdata/memprof-multi.test
index f1439556b1fc9..99c32a9bde5f2 100644
--- a/llvm/test/tools/llvm-profdata/memprof-multi.test
+++ b/llvm/test/tools/llvm-profdata/memprof-multi.test
@@ -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

diff  --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 6000460d3c23a..9a345b48a418f 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -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;
 }
 


        


More information about the llvm-commits mailing list