Skip to content

Commit 17fc651

Browse files
committed
[llvm-profdata] Support -detailed-summary for Sample Profile
Summary: Add -detailed-summary support for sample profile dump to match that of instrumentation profile. Reviewers: wmi, davidxl, hoyFB Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79291
1 parent 89c7451 commit 17fc651

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

llvm/include/llvm/IR/ProfileSummary.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace llvm {
2121

2222
class LLVMContext;
2323
class Metadata;
24+
class raw_ostream;
2425

2526
// The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
2627
// The semantics of counts depend on the type of profile. For instrumentation
@@ -85,6 +86,8 @@ class ProfileSummary {
8586
uint64_t getMaxInternalCount() { return MaxInternalCount; }
8687
void setPartialProfile(bool PP) { Partial = PP; }
8788
bool isPartialProfile() { return Partial; }
89+
void printSummary(raw_ostream &OS);
90+
void printDetailedSummary(raw_ostream &OS);
8891
};
8992

9093
} // end namespace llvm

llvm/lib/IR/ProfileSummary.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,21 @@ ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) {
205205
MaxCount, MaxInternalCount, MaxFunctionCount,
206206
NumCounts, NumFunctions, IsPartialProfile);
207207
}
208+
209+
void ProfileSummary::printSummary(raw_ostream &OS) {
210+
OS << "Total functions: " << NumFunctions << "\n";
211+
OS << "Maximum function count: " << MaxFunctionCount << "\n";
212+
OS << "Maximum block count: " << MaxCount << "\n";
213+
OS << "Total number of blocks: " << NumCounts << "\n";
214+
OS << "Total count: " << TotalCount << "\n";
215+
}
216+
217+
void ProfileSummary::printDetailedSummary(raw_ostream &OS) {
218+
OS << "Detailed summary:\n";
219+
for (auto Entry : DetailedSummary) {
220+
OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount
221+
<< " account for "
222+
<< format("%0.6g", (float)Entry.Cutoff / Scale * 100)
223+
<< " percentage of the total counts.\n";
224+
}
225+
}

llvm/test/tools/llvm-profdata/general.proftext

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ hex_hash
6868
# SUMMARY: Maximum internal block count: 1152921504606846976
6969

7070
# RUN: llvm-profdata show --detailed-summary %t.profdata.dense | FileCheck %s -check-prefix=DETAILED-SUMMARY
71-
# DETAILED-SUMMARY: Detailed summary:
7271
# DETAILED-SUMMARY: Total number of blocks: 10
7372
# DETAILED-SUMMARY: Total count: 4539628424389557499
73+
# DETAILED-SUMMARY: Detailed summary:
7474
# DETAILED-SUMMARY: 3 blocks with count >= 576460752303423488 account for 80 percentage of the total counts.
7575
# DETAILED-SUMMARY: 4 blocks with count >= 288230376151711744 account for 90 percentage of the total counts.
7676
# DETAILED-SUMMARY: 4 blocks with count >= 288230376151711744 account for 95 percentage of the total counts.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llvm-profdata show -sample -detailed-summary %S/Inputs/sample-profile.proftext | FileCheck %s
2+
3+
; CHECK: Total functions: 3
4+
; CHECK-NEXT: Maximum function count: 1437
5+
; CHECK-NEXT: Maximum block count: 2080
6+
; CHECK-NEXT: Total number of blocks: 11
7+
; CHECK-NEXT: Total count: 12943
8+
; CHECK-NEXT: Detailed summary:
9+
; CHECK-NEXT: 1 blocks with count >= 2080 account for 1 percentage of the total counts.
10+
; CHECK-NEXT: 1 blocks with count >= 2080 account for 10 percentage of the total counts.
11+
; CHECK-NEXT: 2 blocks with count >= 2064 account for 20 percentage of the total counts.
12+
; CHECK-NEXT: 2 blocks with count >= 2064 account for 30 percentage of the total counts.
13+
; CHECK-NEXT: 3 blocks with count >= 2000 account for 40 percentage of the total counts.
14+
; CHECK-NEXT: 4 blocks with count >= 1437 account for 50 percentage of the total counts.
15+
; CHECK-NEXT: 6 blocks with count >= 1075 account for 60 percentage of the total counts.
16+
; CHECK-NEXT: 6 blocks with count >= 1075 account for 70 percentage of the total counts.
17+
; CHECK-NEXT: 7 blocks with count >= 1000 account for 80 percentage of the total counts.
18+
; CHECK-NEXT: 11 blocks with count >= 534 account for 90 percentage of the total counts.
19+
; CHECK-NEXT: 11 blocks with count >= 534 account for 95 percentage of the total counts.
20+
; CHECK-NEXT: 11 blocks with count >= 534 account for 99 percentage of the total counts.
21+
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.9 percentage of the total counts.
22+
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.99 percentage of the total counts.
23+
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.999 percentage of the total counts.
24+
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.9999 percentage of the total counts.

llvm/tools/llvm-profdata/llvm-profdata.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -1010,15 +1010,9 @@ static int showInstrProfile(const std::string &Filename, bool ShowCounts,
10101010
}
10111011

10121012
if (ShowDetailedSummary) {
1013-
OS << "Detailed summary:\n";
10141013
OS << "Total number of blocks: " << PS->getNumCounts() << "\n";
10151014
OS << "Total count: " << PS->getTotalCount() << "\n";
1016-
for (auto Entry : PS->getDetailedSummary()) {
1017-
OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount
1018-
<< " account for "
1019-
<< format("%0.6g", (float)Entry.Cutoff / ProfileSummary::Scale * 100)
1020-
<< " percentage of the total counts.\n";
1021-
}
1015+
PS->printDetailedSummary(OS);
10221016
}
10231017
return 0;
10241018
}
@@ -1034,7 +1028,7 @@ static void showSectionInfo(sampleprof::SampleProfileReader *Reader,
10341028
}
10351029

10361030
static int showSampleProfile(const std::string &Filename, bool ShowCounts,
1037-
bool ShowAllFunctions,
1031+
bool ShowAllFunctions, bool ShowDetailedSummary,
10381032
const std::string &ShowFunction,
10391033
bool ShowProfileSymbolList,
10401034
bool ShowSectionInfoOnly, raw_fd_ostream &OS) {
@@ -1065,6 +1059,12 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts,
10651059
ReaderList->dump(OS);
10661060
}
10671061

1062+
if (ShowDetailedSummary) {
1063+
auto &PS = Reader->getSummary();
1064+
PS.printSummary(OS);
1065+
PS.printDetailedSummary(OS);
1066+
}
1067+
10681068
return 0;
10691069
}
10701070

@@ -1153,8 +1153,8 @@ static int show_main(int argc, const char *argv[]) {
11531153
OnlyListBelow, ShowFunction, TextFormat, OS);
11541154
else
11551155
return showSampleProfile(Filename, ShowCounts, ShowAllFunctions,
1156-
ShowFunction, ShowProfileSymbolList,
1157-
ShowSectionInfoOnly, OS);
1156+
ShowDetailedSummary, ShowFunction,
1157+
ShowProfileSymbolList, ShowSectionInfoOnly, OS);
11581158
}
11591159

11601160
int main(int argc, const char *argv[]) {

0 commit comments

Comments
 (0)