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
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
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
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";
+ }
+}
# 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.
--- /dev/null
+; 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.
}
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;
}
}
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) {
ReaderList->dump(OS);
}
+ if (ShowDetailedSummary) {
+ auto &PS = Reader->getSummary();
+ PS.printSummary(OS);
+ PS.printDetailedSummary(OS);
+ }
+
return 0;
}
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[]) {