From 8a87f42fc6ca14d13454465490dbf47333918907 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar Date: Wed, 1 Jun 2022 22:20:53 +0000 Subject: [PATCH] [memprof] Print out the segment information in YAML format. This change prints out the segment information in the raw profile in YAML format for testing. Since we don't capture build ids yet, we print out for now. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D126840 --- llvm/lib/ProfileData/RawMemProfReader.cpp | 25 ++++++++++ .../tools/llvm-profdata/memprof-basic.test | 46 +++++++++++++++++++ .../tools/llvm-profdata/memprof-inline.test | 46 +++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp index aa9291203201..2c9977c75568 100644 --- a/llvm/lib/ProfileData/RawMemProfReader.cpp +++ b/llvm/lib/ProfileData/RawMemProfReader.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" #include "llvm/DebugInfo/Symbolize/SymbolizableObjectFile.h" @@ -150,6 +151,21 @@ bool isRuntimePath(const StringRef Path) { return StringRef(llvm::sys::path::convert_to_slash(Path)) .contains("memprof/memprof_"); } + +std::string getBuildIdString(const SegmentEntry &Entry) { + constexpr size_t Size = sizeof(Entry.BuildId) / sizeof(uint8_t); + constexpr uint8_t Zeros[Size] = {0}; + // If the build id is unset print a helpful string instead of all zeros. + if (memcmp(Entry.BuildId, Zeros, Size) == 0) + return ""; + + std::string Str; + raw_string_ostream OS(Str); + for (size_t I = 0; I < Size; I++) { + OS << format_hex_no_prefix(Entry.BuildId[I], 2); + } + return OS.str(); +} } // namespace Expected> @@ -217,6 +233,15 @@ void RawMemProfReader::printYAML(raw_ostream &OS) { OS << " NumMibInfo: " << NumMibInfo << "\n"; OS << " NumAllocFunctions: " << NumAllocFunctions << "\n"; OS << " NumStackOffsets: " << StackMap.size() << "\n"; + // Print out the segment information. + OS << " Segments:\n"; + for (const auto &Entry : SegmentInfo) { + OS << " -\n"; + OS << " BuildId: " << getBuildIdString(Entry) << "\n"; + OS << " Start: 0x" << llvm::utohexstr(Entry.Start) << "\n"; + OS << " End: 0x" << llvm::utohexstr(Entry.End) << "\n"; + OS << " Offset: 0x" << llvm::utohexstr(Entry.Offset) << "\n"; + } // Print out the merged contents of the profiles. OS << " Records:\n"; for (const auto &Entry : *this) { diff --git a/llvm/test/tools/llvm-profdata/memprof-basic.test b/llvm/test/tools/llvm-profdata/memprof-basic.test index cd2b607ff5eb..b0086fbc7ea3 100644 --- a/llvm/test/tools/llvm-profdata/memprof-basic.test +++ b/llvm/test/tools/llvm-profdata/memprof-basic.test @@ -43,6 +43,52 @@ CHECK-NEXT: NumSegments: 9 CHECK-NEXT: NumMibInfo: 2 CHECK-NEXT: NumAllocFunctions: 1 CHECK-NEXT: NumStackOffsets: 2 +CHECK-NEXT: Segments: +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x200000 +CHECK-NEXT: End: 0x298000 +CHECK-NEXT: Offset: 0x0 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7C7C000 +CHECK-NEXT: End: 0x7FFFF7DC5000 +CHECK-NEXT: Offset: 0x26000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7E1E000 +CHECK-NEXT: End: 0x7FFFF7E30000 +CHECK-NEXT: Offset: 0x3000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7E36000 +CHECK-NEXT: End: 0x7FFFF7E38000 +CHECK-NEXT: Offset: 0x1000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7E4A000 +CHECK-NEXT: End: 0x7FFFF7EE5000 +CHECK-NEXT: Offset: 0xF000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7F83000 +CHECK-NEXT: End: 0x7FFFF7F87000 +CHECK-NEXT: Offset: 0x3000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7F92000 +CHECK-NEXT: End: 0x7FFFF7FA1000 +CHECK-NEXT: Offset: 0x7000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7FD0000 +CHECK-NEXT: End: 0x7FFFF7FD2000 +CHECK-NEXT: Offset: 0x0 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFF7FD3000 +CHECK-NEXT: End: 0x7FFFF7FF3000 +CHECK-NEXT: Offset: 0x1000 CHECK-NEXT: Records: CHECK-NEXT: - CHECK-NEXT: FunctionGUID: {{[0-9]+}} diff --git a/llvm/test/tools/llvm-profdata/memprof-inline.test b/llvm/test/tools/llvm-profdata/memprof-inline.test index 49f39ac65a33..a08af1d4873c 100644 --- a/llvm/test/tools/llvm-profdata/memprof-inline.test +++ b/llvm/test/tools/llvm-profdata/memprof-inline.test @@ -44,6 +44,52 @@ CHECK-NEXT: NumSegments: 9 CHECK-NEXT: NumMibInfo: 2 CHECK-NEXT: NumAllocFunctions: 2 CHECK-NEXT: NumStackOffsets: 1 +CHECK-NEXT: Segments: +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x200000 +CHECK-NEXT: End: 0x29B000 +CHECK-NEXT: Offset: 0x0 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F5871485000 +CHECK-NEXT: End: 0x7F58715CD000 +CHECK-NEXT: Offset: 0x26000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F587162D000 +CHECK-NEXT: End: 0x7F587163F000 +CHECK-NEXT: Offset: 0x3000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F5871646000 +CHECK-NEXT: End: 0x7F5871648000 +CHECK-NEXT: Offset: 0x2000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F587165A000 +CHECK-NEXT: End: 0x7F58716F4000 +CHECK-NEXT: Offset: 0xF000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F5871791000 +CHECK-NEXT: End: 0x7F5871795000 +CHECK-NEXT: Offset: 0x3000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F58717A0000 +CHECK-NEXT: End: 0x7F58717AF000 +CHECK-NEXT: Offset: 0x7000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7F58717D6000 +CHECK-NEXT: End: 0x7F58717FA000 +CHECK-NEXT: Offset: 0x1000 +CHECK-NEXT: - +CHECK-NEXT: BuildId: +CHECK-NEXT: Start: 0x7FFFC77BD000 +CHECK-NEXT: End: 0x7FFFC77BF000 +CHECK-NEXT: Offset: 0x0 CHECK-NEXT: Records: CHECK-NEXT: - CHECK-NEXT: FunctionGUID: 15505678318020221912