-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[StaticDataLayout][llvm-profdata] Print data access profile summary in text profiles and sort records before printing #172592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mingmingl-llvm
wants to merge
1
commit into
main
Choose a base branch
from
users/mingmingl-llvm/llvm-profdata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−14
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-pgo @llvm/pr-subscribers-llvm-transforms Author: Mingming Liu (mingmingl-llvm) ChangesThis change proposes to print data access profile summary in its text format and sort records before printing. This gives some aggregated information about the data access profiles. Full diff: https://github.com/llvm/llvm-project/pull/172592.diff 6 Files Affected:
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index d2ae4b5226ff6..8147ee8d0e816 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -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(
@@ -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;
}
diff --git a/llvm/lib/ProfileData/MemProfSummary.cpp b/llvm/lib/ProfileData/MemProfSummary.cpp
index f620b7a74b244..c72d0a9e5353a 100644
--- a/llvm/lib/ProfileData/MemProfSummary.cpp
+++ b/llvm/lib/ProfileData/MemProfSummary.cpp
@@ -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";
diff --git a/llvm/test/Transforms/PGOProfile/memprof.ll b/llvm/test/Transforms/PGOProfile/memprof.ll
index f6a89a8ceb86a..00175b2f3984c 100644
--- a/llvm/test/Transforms/PGOProfile/memprof.ll
+++ b/llvm/test/Transforms/PGOProfile/memprof.ll
@@ -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
diff --git a/llvm/test/Transforms/PGOProfile/memprof_max_cold_threshold.test b/llvm/test/Transforms/PGOProfile/memprof_max_cold_threshold.test
index 8f1cabf9a4e87..d1dcc86eac8e8 100644
--- a/llvm/test/Transforms/PGOProfile/memprof_max_cold_threshold.test
+++ b/llvm/test/Transforms/PGOProfile/memprof_max_cold_threshold.test
@@ -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
diff --git a/llvm/test/tools/llvm-profdata/memprof-yaml.test b/llvm/test/tools/llvm-profdata/memprof-yaml.test
index 6fbfbdb507f27..f6201816927f6 100644
--- a/llvm/test/tools/llvm-profdata/memprof-yaml.test
+++ b/llvm/test/tools/llvm-profdata/memprof-yaml.test
@@ -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
@@ -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
@@ -131,7 +136,7 @@ HeapProfileRecords:
...
;--- memprof-in-alloc-sites-only.yaml
---
-# MemProfSummary:
+# MemProfHeapSummary:
# Total contexts: 2
# Total cold contexts: 0
# Total hot contexts: 0
@@ -161,7 +166,7 @@ HeapProfileRecords:
...
;--- memprof-in-call-sites-only.yaml
---
-# MemProfSummary:
+# MemProfHeapSummary:
# Total contexts: 0
# Total cold contexts: 0
# Total hot contexts: 0
@@ -183,7 +188,7 @@ HeapProfileRecords:
...
;--- memprof-in-no-dap.yaml
---
-# MemProfSummary:
+# MemProfHeapSummary:
# Total contexts: 2
# Total cold contexts: 0
# Total hot contexts: 0
@@ -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
@@ -245,7 +255,7 @@ DataAccessProfiles:
- FileName: file.cpp
Line: 233
KnownColdSymbols:
- - foo
- bar
+ - foo
KnownColdStrHashes: [ 999, 1001 ]
...
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index e186c5a198027..a8cc69f83038c 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -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);
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change proposes to print data access profile summary in its text format and sort records before printing. This gives some aggregated information about the data access profiles.