aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-profdata/llvm-profdata.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2025-05-28 13:12:41 -0700
committerGitHub <noreply@github.com>2025-05-28 13:12:41 -0700
commitcc6f446d3865a5e3a6e50e16e670c307a479a110 (patch)
tree27abc677ea98e7f0c4855f62024b1355bb280ae1 /llvm/tools/llvm-profdata/llvm-profdata.cpp
parent02916a432ca6465e2e45f67be94f1c89c9cd425d (diff)
downloadllvm-cc6f446d3865a5e3a6e50e16e670c307a479a110.zip
llvm-cc6f446d3865a5e3a6e50e16e670c307a479a110.tar.gz
llvm-cc6f446d3865a5e3a6e50e16e670c307a479a110.tar.bz2
[MemProf] Add basic summary section support (#141805)
This patch adds support for a basic MemProf summary section, which is built along with the indexed MemProf profile (e.g. when reading the raw or YAML profiles), and serialized through the indexed profile just after the header. Currently only 6 fields are written, specifically the number of contexts (total, cold, hot), and the max context size (cold, warm, hot). To support forwards and backwards compatibility for added fields in the indexed profile, the number of fields serialized first. The code is written to support forwards compatibility (reading newer profiles with additional summary fields), and comments indicate how to implement backwards compatibility (reading older profiles with fewer summary fields) as needed. Support is added to print the summary as YAML comments when displaying both the raw and indexed profiles via `llvm-profdata show`. Because they are YAML comments, the YAML reader ignores these (the summary is always recomputed when building the indexed profile as described above). This necessitated moving some options and a couple of interfaces out of Analysis/MemoryProfileInfo.cpp and into the new ProfileData/MemProfSummary.cpp file, as we need to classify context hotness earlier and also compute context ids to build the summary from older indexed profiles.
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r--llvm/tools/llvm-profdata/llvm-profdata.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 8660eed..a7cbd4b 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -22,6 +22,7 @@
#include "llvm/ProfileData/InstrProfWriter.h"
#include "llvm/ProfileData/MemProf.h"
#include "llvm/ProfileData/MemProfReader.h"
+#include "llvm/ProfileData/MemProfSummaryBuilder.h"
#include "llvm/ProfileData/MemProfYAML.h"
#include "llvm/ProfileData/ProfileCommon.h"
#include "llvm/ProfileData/SampleProfReader.h"
@@ -3312,6 +3313,18 @@ static int showMemProfProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
auto Reader = std::move(ReaderOrErr.get());
memprof::AllMemProfData Data = Reader->getAllMemProfData();
+
+ // For v4 and above the summary is serialized in the indexed profile, and can
+ // be accessed from the reader. Earlier versions build the summary below.
+ // The summary is emitted as YAML comments at the start of the output.
+ if (auto *MemProfSum = Reader->getMemProfSummary()) {
+ MemProfSum->printSummaryYaml(OS);
+ } else {
+ memprof::MemProfSummaryBuilder MemProfSumBuilder;
+ for (auto &Pair : Data.HeapProfileRecords)
+ MemProfSumBuilder.addRecord(Pair.Record);
+ MemProfSumBuilder.getSummary()->printSummaryYaml(OS);
+ }
// Construct yaml::Output with the maximum column width of 80 so that each
// Frame fits in one line.
yaml::Output Yout(OS, nullptr, 80);