1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[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
This commit is contained in:
Wenlei He 2020-05-02 08:34:10 -07:00
parent 5db772cd7b
commit e88b44e49c
5 changed files with 56 additions and 11 deletions

View File

@ -21,6 +21,7 @@ namespace llvm {
class LLVMContext;
class Metadata;
class raw_ostream;
// The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
// The semantics of counts depend on the type of profile. For instrumentation
@ -85,6 +86,8 @@ public:
uint64_t getMaxInternalCount() { return MaxInternalCount; }
void setPartialProfile(bool PP) { Partial = PP; }
bool isPartialProfile() { return Partial; }
void printSummary(raw_ostream &OS);
void printDetailedSummary(raw_ostream &OS);
};
} // end namespace llvm

View File

@ -205,3 +205,21 @@ ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) {
MaxCount, MaxInternalCount, MaxFunctionCount,
NumCounts, NumFunctions, IsPartialProfile);
}
void ProfileSummary::printSummary(raw_ostream &OS) {
OS << "Total functions: " << NumFunctions << "\n";
OS << "Maximum function count: " << MaxFunctionCount << "\n";
OS << "Maximum block count: " << MaxCount << "\n";
OS << "Total number of blocks: " << NumCounts << "\n";
OS << "Total count: " << TotalCount << "\n";
}
void ProfileSummary::printDetailedSummary(raw_ostream &OS) {
OS << "Detailed summary:\n";
for (auto Entry : DetailedSummary) {
OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount
<< " account for "
<< format("%0.6g", (float)Entry.Cutoff / Scale * 100)
<< " percentage of the total counts.\n";
}
}

View File

@ -68,9 +68,9 @@ hex_hash
# SUMMARY: Maximum internal block count: 1152921504606846976
# RUN: llvm-profdata show --detailed-summary %t.profdata.dense | FileCheck %s -check-prefix=DETAILED-SUMMARY
# DETAILED-SUMMARY: Detailed summary:
# DETAILED-SUMMARY: Total number of blocks: 10
# DETAILED-SUMMARY: Total count: 4539628424389557499
# DETAILED-SUMMARY: Detailed summary:
# DETAILED-SUMMARY: 3 blocks with count >= 576460752303423488 account for 80 percentage of the total counts.
# DETAILED-SUMMARY: 4 blocks with count >= 288230376151711744 account for 90 percentage of the total counts.
# DETAILED-SUMMARY: 4 blocks with count >= 288230376151711744 account for 95 percentage of the total counts.

View File

@ -0,0 +1,24 @@
; RUN: llvm-profdata show -sample -detailed-summary %S/Inputs/sample-profile.proftext | FileCheck %s
; CHECK: Total functions: 3
; CHECK-NEXT: Maximum function count: 1437
; CHECK-NEXT: Maximum block count: 2080
; CHECK-NEXT: Total number of blocks: 11
; CHECK-NEXT: Total count: 12943
; CHECK-NEXT: Detailed summary:
; CHECK-NEXT: 1 blocks with count >= 2080 account for 1 percentage of the total counts.
; CHECK-NEXT: 1 blocks with count >= 2080 account for 10 percentage of the total counts.
; CHECK-NEXT: 2 blocks with count >= 2064 account for 20 percentage of the total counts.
; CHECK-NEXT: 2 blocks with count >= 2064 account for 30 percentage of the total counts.
; CHECK-NEXT: 3 blocks with count >= 2000 account for 40 percentage of the total counts.
; CHECK-NEXT: 4 blocks with count >= 1437 account for 50 percentage of the total counts.
; CHECK-NEXT: 6 blocks with count >= 1075 account for 60 percentage of the total counts.
; CHECK-NEXT: 6 blocks with count >= 1075 account for 70 percentage of the total counts.
; CHECK-NEXT: 7 blocks with count >= 1000 account for 80 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 90 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 95 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 99 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.9 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.99 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.999 percentage of the total counts.
; CHECK-NEXT: 11 blocks with count >= 534 account for 99.9999 percentage of the total counts.

View File

@ -1010,15 +1010,9 @@ static int showInstrProfile(const std::string &Filename, bool ShowCounts,
}
if (ShowDetailedSummary) {
OS << "Detailed summary:\n";
OS << "Total number of blocks: " << PS->getNumCounts() << "\n";
OS << "Total count: " << PS->getTotalCount() << "\n";
for (auto Entry : PS->getDetailedSummary()) {
OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount
<< " account for "
<< format("%0.6g", (float)Entry.Cutoff / ProfileSummary::Scale * 100)
<< " percentage of the total counts.\n";
}
PS->printDetailedSummary(OS);
}
return 0;
}
@ -1034,7 +1028,7 @@ static void showSectionInfo(sampleprof::SampleProfileReader *Reader,
}
static int showSampleProfile(const std::string &Filename, bool ShowCounts,
bool ShowAllFunctions,
bool ShowAllFunctions, bool ShowDetailedSummary,
const std::string &ShowFunction,
bool ShowProfileSymbolList,
bool ShowSectionInfoOnly, raw_fd_ostream &OS) {
@ -1065,6 +1059,12 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts,
ReaderList->dump(OS);
}
if (ShowDetailedSummary) {
auto &PS = Reader->getSummary();
PS.printSummary(OS);
PS.printDetailedSummary(OS);
}
return 0;
}
@ -1153,8 +1153,8 @@ static int show_main(int argc, const char *argv[]) {
OnlyListBelow, ShowFunction, TextFormat, OS);
else
return showSampleProfile(Filename, ShowCounts, ShowAllFunctions,
ShowFunction, ShowProfileSymbolList,
ShowSectionInfoOnly, OS);
ShowDetailedSummary, ShowFunction,
ShowProfileSymbolList, ShowSectionInfoOnly, OS);
}
int main(int argc, const char *argv[]) {