Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,12 @@ memprof::AllMemProfData IndexedMemProfReader::getAllMemProfData() const {
}
// Populate the data access profiles for yaml output.
if (DataAccessProfileData != nullptr) {
AllMemProfData.YamlifiedDataAccessProfiles.Records.reserve(
DataAccessProfileData->getRecords().size());
AllMemProfData.YamlifiedDataAccessProfiles.KnownColdSymbols.reserve(
DataAccessProfileData->getKnownColdSymbols().size());
AllMemProfData.YamlifiedDataAccessProfiles.KnownColdStrHashes.reserve(
DataAccessProfileData->getKnownColdHashes().size());
for (const auto &[SymHandleRef, RecordRef] :
DataAccessProfileData->getRecords())
AllMemProfData.YamlifiedDataAccessProfiles.Records.push_back(
Expand All @@ -1565,6 +1571,19 @@ memprof::AllMemProfData IndexedMemProfReader::getAllMemProfData() const {
for (uint64_t Hash : DataAccessProfileData->getKnownColdHashes())
AllMemProfData.YamlifiedDataAccessProfiles.KnownColdStrHashes.push_back(
Hash);
llvm::stable_sort(AllMemProfData.YamlifiedDataAccessProfiles.Records,
[](const llvm::memprof::DataAccessProfRecord &lhs,
const llvm::memprof::DataAccessProfRecord &rhs) {
return lhs.AccessCount > rhs.AccessCount;
});
llvm::stable_sort(
AllMemProfData.YamlifiedDataAccessProfiles.KnownColdSymbols,
[](const std::string &lhs, const std::string &rhs) {
return lhs < rhs;
});
llvm::stable_sort(
AllMemProfData.YamlifiedDataAccessProfiles.KnownColdStrHashes,
[](const uint64_t &lhs, const uint64_t &rhs) { return lhs < rhs; });
}
return AllMemProfData;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/MemProfSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace llvm::memprof;
void MemProfSummary::printSummaryYaml(raw_ostream &OS) const {
// For now emit as YAML comments, since they aren't read on input.
OS << "---\n";
OS << "# MemProfSummary:\n";
OS << "# MemProfHeapSummary:\n";
OS << "# Total contexts: " << NumContexts << "\n";
OS << "# Total cold contexts: " << NumColdContexts << "\n";
OS << "# Total hot contexts: " << NumHotContexts << "\n";
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/PGOProfile/memprof.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
;; Check that the summary can be shown (and is identical) for both the raw and indexed profiles.
; RUN: llvm-profdata show --memory %S/Inputs/memprof.memprofraw --profiled-binary %S/Inputs/memprof.exe | FileCheck %s --check-prefixes=SUMMARY
; RUN: llvm-profdata show --memory %t.memprofdata | FileCheck %s --check-prefixes=SUMMARY
; SUMMARY: # MemProfSummary:
; SUMMARY: # MemProfHeapSummary:
; SUMMARY: # Total contexts: 8
; SUMMARY: # Total cold contexts: 5
; SUMMARY: # Total hot contexts: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof_max_cold_threshold.yaml -o %t/memprof_max_cold_threshold.memprofdata

; RUN: llvm-profdata show --memory %t/memprof_max_cold_threshold.memprofdata | FileCheck %s --check-prefixes=SUMMARY
; SUMMARY: # MemProfSummary:
; SUMMARY: # MemProfHeapSummary:
; SUMMARY: # Total contexts: 5
; SUMMARY: # Total cold contexts: 4
; SUMMARY: # Total hot contexts: 0
Expand Down
32 changes: 21 additions & 11 deletions llvm/test/tools/llvm-profdata/memprof-yaml.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@

;--- memprof-in.yaml
---
# MemProfSummary:
# MemProfHeapSummary:
# Total contexts: 2
# Total cold contexts: 0
# Total hot contexts: 0
# Maximum cold context total size: 0
# Maximum warm context total size: 666
# Maximum hot context total size: 0
#
# DataAccessProfileSummary:
# Num hot symbols and string literals: 2
# Num known cold symbols: 2
# Num known cold string literals: 2
---
HeapProfileRecords:
- GUID: 0xdeadbeef12345678
Expand Down Expand Up @@ -76,25 +81,25 @@ HeapProfileRecords:
DataAccessProfiles:
SampledRecords:
- Symbol: abcde
AccessCount: 100
AccessCount: 202
Locations:
- FileName: file2.h
Line: 123
- FileName: file3.cpp
Line: 456
Line: 456
- Hash: 101010
AccessCount: 200
Locations:
- FileName: file.cpp
Line: 233
KnownColdSymbols:
- foo
- bar
- foo
KnownColdStrHashes: [ 999, 1001 ]
...
;--- memprof-in-v3.yaml
---
# MemProfSummary:
# MemProfHeapSummary:
# Total contexts: 2
# Total cold contexts: 0
# Total hot contexts: 0
Expand Down Expand Up @@ -131,7 +136,7 @@ HeapProfileRecords:
...
;--- memprof-in-alloc-sites-only.yaml
---
# MemProfSummary:
# MemProfHeapSummary:
# Total contexts: 2
# Total cold contexts: 0
# Total hot contexts: 0
Expand Down Expand Up @@ -161,7 +166,7 @@ HeapProfileRecords:
...
;--- memprof-in-call-sites-only.yaml
---
# MemProfSummary:
# MemProfHeapSummary:
# Total contexts: 0
# Total cold contexts: 0
# Total hot contexts: 0
Expand All @@ -183,7 +188,7 @@ HeapProfileRecords:
...
;--- memprof-in-no-dap.yaml
---
# MemProfSummary:
# MemProfHeapSummary:
# Total contexts: 2
# Total cold contexts: 0
# Total hot contexts: 0
Expand Down Expand Up @@ -222,18 +227,23 @@ HeapProfileRecords:
...
;--- memprof-in-no-heap.yaml
---
# MemProfSummary:
# MemProfHeapSummary:
# Total contexts: 0
# Total cold contexts: 0
# Total hot contexts: 0
# Maximum cold context total size: 0
# Maximum warm context total size: 0
# Maximum hot context total size: 0
#
# DataAccessProfileSummary:
# Num hot symbols and string literals: 2
# Num known cold symbols: 2
# Num known cold string literals: 2
---
DataAccessProfiles:
SampledRecords:
- Symbol: abcde
AccessCount: 100
AccessCount: 202
Locations:
- FileName: file2.h
Line: 123
Expand All @@ -245,7 +255,7 @@ DataAccessProfiles:
- FileName: file.cpp
Line: 233
KnownColdSymbols:
- foo
- bar
- foo
KnownColdStrHashes: [ 999, 1001 ]
...
10 changes: 10 additions & 0 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,16 @@ static int showMemProfProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
MemProfSumBuilder.addRecord(Pair.Record);
MemProfSumBuilder.getSummary()->printSummaryYaml(OS);
}
if (!Data.YamlifiedDataAccessProfiles.isEmpty()) {
OS << "#\n";
OS << "# DataAccessProfileSummary: \n";
OS << "# Num hot symbols and string literals: "
<< Data.YamlifiedDataAccessProfiles.Records.size() << "\n";
OS << "# Num known cold symbols: "
<< Data.YamlifiedDataAccessProfiles.KnownColdSymbols.size() << "\n";
OS << "# Num known cold string literals: "
<< Data.YamlifiedDataAccessProfiles.KnownColdStrHashes.size() << "\n";
}
// Construct yaml::Output with the maximum column width of 80 so that each
// Frame fits in one line.
yaml::Output Yout(OS, nullptr, 80);
Expand Down