llvm.org GIT mirror llvm / dcb98bd
[ProfileData] Add new option to dump topn hottest functions Differential Revision: http://reviews.llvm.org/D35155 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307702 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 2 years ago
3 changed file(s) with 56 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
191191 information is dumped in a more human readable form (also in text) with
192192 annotations.
193193
194 .. option:: -topn=n
195
196 Instruct the profile dumper to show the top ``n`` functions with the
197 hottest basic blocks in the summary section. By default, the topn functions
198 are not dumped.
199
194200 .. option:: -sample
195201
196202 Specify that the input profile is a sample-based profile.
99 REGENERATE: $ LLVM_PROFILE_FILE=$TESTDIR/Inputs/c-general.profraw ./a.out
1010
1111 RUN: llvm-profdata show %p/Inputs/c-general.profraw -o - | FileCheck %s
12 RUN: llvm-profdata show %p/Inputs/c-general.profraw --topn=3 -o - | FileCheck %s --check-prefix=TOPN
1213 RUN: llvm-profdata show %p/Inputs/c-general.profraw -o - --function=switches | FileCheck %s -check-prefix=SWITCHES -check-prefix=CHECK
1314
1415 SWITCHES-LABEL: Counters:
2122 CHECK-LABEL: Total functions: 12
2223 CHECK-NEXT: Maximum function count: 1
2324 CHECK-NEXT: Maximum internal block count: 100
25 TOPN: boolean_operators, max count = 100
26 TOPN-NEXT: simple_loops, max count = 100
27 TOPN-NEXT: conditionals, max count = 100
511511 }
512512
513513 static int showInstrProfile(const std::string &Filename, bool ShowCounts,
514 bool ShowIndirectCallTargets, bool ShowMemOPSizes,
515 bool ShowDetailedSummary,
514 uint32_t TopN, bool ShowIndirectCallTargets,
515 bool ShowMemOPSizes, bool ShowDetailedSummary,
516516 std::vector DetailedSummaryCutoffs,
517517 bool ShowAllFunctions,
518518 const std::string &ShowFunction, bool TextFormat,
531531 size_t ShownFunctions = 0;
532532 int NumVPKind = IPVK_Last - IPVK_First + 1;
533533 std::vector VPStats(NumVPKind);
534
535 auto MinCmp = [](const std::pair &v1,
536 const std::pair &v2) {
537 return v1.second > v2.second;
538 };
539
540 std::priority_queue,
541 std::vector>,
542 decltype(MinCmp)>
543 HottestFuncs(MinCmp);
544
534545 for (const auto &Func : *Reader) {
535546 bool Show =
536547 ShowAllFunctions || (!ShowFunction.empty() &&
547558
548559 assert(Func.Counts.size() > 0 && "function missing entry counter");
549560 Builder.addRecord(Func);
561
562 if (TopN) {
563 uint64_t FuncMax = 0;
564 for (size_t I = 0, E = Func.Counts.size(); I < E; ++I)
565 FuncMax = std::max(FuncMax, Func.Counts[I]);
566
567 if (HottestFuncs.size() == TopN) {
568 if (HottestFuncs.top().second < FuncMax) {
569 HottestFuncs.pop();
570 HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax));
571 }
572 } else
573 HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax));
574 }
550575
551576 if (Show) {
552577
604629 OS << "Total functions: " << PS->getNumFunctions() << "\n";
605630 OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
606631 OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
632
633 if (TopN) {
634 std::vector> SortedHottestFuncs;
635 while (!HottestFuncs.empty()) {
636 SortedHottestFuncs.emplace_back(HottestFuncs.top());
637 HottestFuncs.pop();
638 }
639 OS << "Top " << TopN
640 << " functions with the largest internal block counts: \n";
641 for (auto &hotfunc : llvm::reverse(SortedHottestFuncs))
642 OS << " " << hotfunc.first << ", max count = " << hotfunc.second << "\n";
643 }
607644
608645 if (ShownFunctions && ShowIndirectCallTargets) {
609646 OS << "Statistics for indirect call sites profile:\n";
688725 cl::desc("Profile kind:"), cl::init(instr),
689726 cl::values(clEnumVal(instr, "Instrumentation profile (default)"),
690727 clEnumVal(sample, "Sample profile")));
728 cl::opt TopNFunctions(
729 "topn", cl::init(0),
730 cl::desc("Show the list of functions with the largest internal counts"));
691731
692732 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n");
693733
705745 std::vector Cutoffs(DetailedSummaryCutoffs.begin(),
706746 DetailedSummaryCutoffs.end());
707747 if (ProfileKind == instr)
708 return showInstrProfile(Filename, ShowCounts, ShowIndirectCallTargets,
709 ShowMemOPSizes, ShowDetailedSummary,
710 DetailedSummaryCutoffs, ShowAllFunctions,
711 ShowFunction, TextFormat, OS);
748 return showInstrProfile(Filename, ShowCounts, TopNFunctions,
749 ShowIndirectCallTargets, ShowMemOPSizes,
750 ShowDetailedSummary, DetailedSummaryCutoffs,
751 ShowAllFunctions, ShowFunction, TextFormat, OS);
712752 else
713753 return showSampleProfile(Filename, ShowCounts, ShowAllFunctions,
714754 ShowFunction, OS);