llvm.org GIT mirror llvm / bf02309
[PGO] Use SourceFileName rather module name in PGOFuncName In LTO or Thin-lto mode (though linker plugin), the module names are of temp file names which are different for different compilations. Using SourceFileName avoids the issue. This should not change any functionality for current PGO as all the current callers of getPGOFuncName() is before LTO. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350579 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 8 months ago
5 changed file(s) with 111 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
202202 annotations.
203203
204204 .. option:: -topn=n
205
205
206206 Instruct the profile dumper to show the top ``n`` functions with the
207207 hottest basic blocks in the summary section. By default, the topn functions
208208 are not dumped.
215215
216216 Show the profiled sizes of the memory intrinsic calls for shown functions.
217217
218 .. option:: -value-cutoff=n
219
220 Show only those functions whose max count values are greater or equal to ``n``.
221 By default, the value-cutoff is set to 0.
222
223 .. option:: -list-below-cutoff
224
225 Only output names of functions whose max count value are below the cutoff
226 value.
227
218228 EXIT STATUS
219229 -----------
220230
0 # IR level Instrumentation Flag
1 :ir
2 bar
3 10
4 2
5 0
6 0
7
8 main
9 16650
10 4
11 1
12 1000
13 1000000
14 499500
15
16 foo
17 10
18 2
19 999
20 1
0 Basic tests for cutoff options in show command.
1
2 RUN: llvm-profdata show -value-cutoff=1 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1 -check-prefix=CHECK
3 RUN: llvm-profdata show -value-cutoff=1000 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1000 -check-prefix=CHECK
4 RUN: llvm-profdata show -all-functions -value-cutoff=1 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1FUNC -check-prefix=CUTOFF1 -check-prefix=CHECK
5 RUN: llvm-profdata show -all-functions -value-cutoff=1000 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1000FUNC -check-prefix=CUTOFF1000 -check-prefix=CHECK
6 RUN: llvm-profdata show -value-cutoff=1 -list-below-cutoff %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=BELOW1 -check-prefix=CUTOFF1 -check-prefix=CHECK
7 RUN: llvm-profdata show -value-cutoff=1000 -list-below-cutoff %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=BELOW1000 -check-prefix=CUTOFF1000 -check-prefix=CHECK
8 CUTOFF1FUNC-NOT: bar
9 CUTOFF1FUNC: Functions shown: 2
10 CUTOFF1000FUNC-NOT: bar
11 CUTOFF1000FUNC-NOT: foo
12 CUTOFF1000FUNC: Functions shown: 1
13 BELOW1: The list of functions with the maximum counter less than 1:
14 BELOW1: bar: (Max = 0 Sum = 0)
15 BELOW1000:The list of functions with the maximum counter less than 1000:
16 BELOW1000: bar: (Max = 0 Sum = 0)
17 BELOW1000: foo: (Max = 999 Sum = 1000)
18 CHECK: Total functions: 3
19 CUTOFF1: Number of functions with maximum count (< 1): 1
20 CUTOFF1: Number of functions with maximum count (>= 1): 2
21 CUTOFF1000: Number of functions with maximum count (< 1000): 2
22 CUTOFF1000: Number of functions with maximum count (>= 1000): 1
4646
4747 #ICTXT: Indirect Call Site Count: 3
4848 #ICTXT-NEXT: Indirect Target Results:
49 #ICTXT-NEXT: [ 1, foo, 100 ]
50 #ICTXT-NEXT: [ 1, foo2, 1000 ]
51 #ICTXT-NEXT: [ 2, foo2, 20000 ]
49 #ICTXT-NEXT: [ 1, foo, 100 ] (9.09%)
50 #ICTXT-NEXT: [ 1, foo2, 1000 ] (90.91%)
51 #ICTXT-NEXT: [ 2, foo2, 20000 ] (100.00%)
5252
5353 #IC: Indirect Call Site Count: 3
5454 #IC-NEXT: Indirect Target Results:
632632 Stats.ValueSitesHistogram.resize(NV, 0);
633633 Stats.ValueSitesHistogram[NV - 1]++;
634634 }
635
636 uint64_t SiteSum = 0;
637 for (uint32_t V = 0; V < NV; V++)
638 SiteSum += VD[V].Count;
639 if (SiteSum == 0)
640 SiteSum = 1;
641
635642 for (uint32_t V = 0; V < NV; V++) {
636 OS << "\t[ " << I << ", ";
643 OS << "\t[ " << format("%2u", I) << ", ";
637644 if (Symtab == nullptr)
638 OS << VD[V].Value;
645 OS << format("%4u", VD[V].Value);
639646 else
640647 OS << Symtab->getFuncName(VD[V].Value);
641 OS << ", " << VD[V].Count << " ]\n";
648 OS << ", " << format("%10" PRId64, VD[V].Count) << " ] ("
649 << format("%.2f%%", (VD[V].Count * 100.0 / SiteSum)) << ")\n";
642650 }
643651 }
644652 }
661669 uint32_t TopN, bool ShowIndirectCallTargets,
662670 bool ShowMemOPSizes, bool ShowDetailedSummary,
663671 std::vector DetailedSummaryCutoffs,
664 bool ShowAllFunctions,
665 const std::string &ShowFunction, bool TextFormat,
666 raw_fd_ostream &OS) {
672 bool ShowAllFunctions, uint64_t ValueCutoff,
673 bool OnlyListBelow, const std::string &ShowFunction,
674 bool TextFormat, raw_fd_ostream &OS) {
667675 auto ReaderOrErr = InstrProfReader::create(Filename);
668676 std::vector Cutoffs = std::move(DetailedSummaryCutoffs);
669677 if (ShowDetailedSummary && Cutoffs.empty()) {
676684 auto Reader = std::move(ReaderOrErr.get());
677685 bool IsIRInstr = Reader->isIRLevelProfile();
678686 size_t ShownFunctions = 0;
687 size_t BelowCutoffFunctions = 0;
679688 int NumVPKind = IPVK_Last - IPVK_First + 1;
680689 std::vector VPStats(NumVPKind);
681690
688697 std::vector>,
689698 decltype(MinCmp)>
690699 HottestFuncs(MinCmp);
700
701 if (!TextFormat && OnlyListBelow) {
702 OS << "The list of functions with the maximum counter less than "
703 << ValueCutoff << ":\n";
704 }
691705
692706 // Add marker so that IR-level instrumentation round-trips properly.
693707 if (TextFormat && IsIRInstr)
710724 assert(Func.Counts.size() > 0 && "function missing entry counter");
711725 Builder.addRecord(Func);
712726
727 uint64_t FuncMax = 0;
728 uint64_t FuncSum = 0;
729 for (size_t I = 0, E = Func.Counts.size(); I < E; ++I) {
730 FuncMax = std::max(FuncMax, Func.Counts[I]);
731 FuncSum += Func.Counts[I];
732 }
733
734 if (FuncMax < ValueCutoff) {
735 ++BelowCutoffFunctions;
736 if (OnlyListBelow) {
737 OS << " " << Func.Name << ": (Max = " << FuncMax
738 << " Sum = " << FuncSum << ")\n";
739 }
740 continue;
741 } else if (OnlyListBelow)
742 continue;
743
713744 if (TopN) {
714 uint64_t FuncMax = 0;
715 for (size_t I = 0, E = Func.Counts.size(); I < E; ++I)
716 FuncMax = std::max(FuncMax, Func.Counts[I]);
717
718745 if (HottestFuncs.size() == TopN) {
719746 if (HottestFuncs.top().second < FuncMax) {
720747 HottestFuncs.pop();
725752 }
726753
727754 if (Show) {
728
729755 if (!ShownFunctions)
730756 OS << "Counters:\n";
731757
780806 if (ShowAllFunctions || !ShowFunction.empty())
781807 OS << "Functions shown: " << ShownFunctions << "\n";
782808 OS << "Total functions: " << PS->getNumFunctions() << "\n";
809 if (ValueCutoff > 0) {
810 OS << "Number of functions with maximum count (< " << ValueCutoff
811 << "): " << BelowCutoffFunctions << "\n";
812 OS << "Number of functions with maximum count (>= " << ValueCutoff
813 << "): " << PS->getNumFunctions() - BelowCutoffFunctions << "\n";
814 }
783815 OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
784816 OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
785817
881913 cl::opt TopNFunctions(
882914 "topn", cl::init(0),
883915 cl::desc("Show the list of functions with the largest internal counts"));
884
916 cl::opt ValueCutoff(
917 "value-cutoff", cl::init(0),
918 cl::desc("Set the count value cutoff. Functions with the maximum count "
919 "less than this value will not be printed out. (Default is 0)"));
920 cl::opt OnlyListBelow(
921 "list-below-cutoff", cl::init(false),
922 cl::desc("Only output names of functions whose max count values are "
923 "below the cutoff value"));
885924 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n");
886925
887926 if (OutputFilename.empty())
901940 return showInstrProfile(Filename, ShowCounts, TopNFunctions,
902941 ShowIndirectCallTargets, ShowMemOPSizes,
903942 ShowDetailedSummary, DetailedSummaryCutoffs,
904 ShowAllFunctions, ShowFunction, TextFormat, OS);
943 ShowAllFunctions, ValueCutoff, OnlyListBelow,
944 ShowFunction, TextFormat, OS);
905945 else
906946 return showSampleProfile(Filename, ShowCounts, ShowAllFunctions,
907947 ShowFunction, OS);