Skip to content

Commit

Permalink
[llvm-profdata] Support -detailed-summary for Sample Profile
Browse files Browse the repository at this point in the history
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
  • Loading branch information
WenleiHe committed May 6, 2020
1 parent 89c7451 commit 17fc651
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
3 changes: 3 additions & 0 deletions llvm/include/llvm/IR/ProfileSummary.h
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +86,8 @@ class ProfileSummary {
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
Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/IR/ProfileSummary.cpp
Expand Up @@ -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";
}
}
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-profdata/general.proftext
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/tools/llvm-profdata/sample-summary.test
@@ -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.
20 changes: 10 additions & 10 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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[]) {
Expand Down

0 comments on commit 17fc651

Please sign in to comment.