<div dir="ltr">Hey Rong, Teresa,<br><br>This seems like it might be problematic to me - Couldn't multiple modules have the same source file name (built with different preprocessor defines, etc) - at least I think that's the case for some projects at Google.<br><br>Does this identifier need to be unique? What are the ramifications if multiple modules had the same source file name & this situation?<br><br>- Dave<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 7, 2019 at 3:29 PM Rong Xu via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: xur<br>
Date: Mon Jan  7 15:25:56 2019<br>
New Revision: 350579<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=350579&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=350579&view=rev</a><br>
Log:<br>
[PGO] Use SourceFileName rather module name in PGOFuncName<br>
<br>
In LTO or Thin-lto mode (though linker plugin), the module<br>
names are of temp file names which are different for<br>
different compilations. Using SourceFileName avoids the issue.<br>
This should not change any functionality for current PGO as<br>
all the current callers of getPGOFuncName() is before LTO.<br>
<br>
Added:<br>
    llvm/trunk/test/tools/llvm-profdata/Inputs/cutoff.proftext<br>
    llvm/trunk/test/tools/llvm-profdata/cutoff.test<br>
Modified:<br>
    llvm/trunk/docs/CommandGuide/llvm-profdata.rst<br>
    llvm/trunk/test/tools/llvm-profdata/value-prof.proftext<br>
    llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp<br>
<br>
Modified: llvm/trunk/docs/CommandGuide/llvm-profdata.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-profdata.rst?rev=350579&r1=350578&r2=350579&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-profdata.rst?rev=350579&r1=350578&r2=350579&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/docs/CommandGuide/llvm-profdata.rst (original)<br>
+++ llvm/trunk/docs/CommandGuide/llvm-profdata.rst Mon Jan  7 15:25:56 2019<br>
@@ -203,7 +203,7 @@ OPTIONS<br>
  annotations.<br>
<br>
 .. option:: -topn=n<br>
-            <br>
+<br>
  Instruct the profile dumper to show the top ``n`` functions with the<br>
  hottest basic blocks in the summary section. By default, the topn functions<br>
  are not dumped.<br>
@@ -216,6 +216,16 @@ OPTIONS<br>
<br>
  Show the profiled sizes of the memory intrinsic calls for shown functions.<br>
<br>
+.. option:: -value-cutoff=n<br>
+<br>
+ Show only those functions whose max count values are greater or equal to ``n``.<br>
+ By default, the value-cutoff is set to 0.<br>
+<br>
+.. option:: -list-below-cutoff<br>
+<br>
+ Only output names of functions whose max count value are below the cutoff<br>
+ value.<br>
+<br>
 EXIT STATUS<br>
 -----------<br>
<br>
<br>
Added: llvm/trunk/test/tools/llvm-profdata/Inputs/cutoff.proftext<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/cutoff.proftext?rev=350579&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/cutoff.proftext?rev=350579&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-profdata/Inputs/cutoff.proftext (added)<br>
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/cutoff.proftext Mon Jan  7 15:25:56 2019<br>
@@ -0,0 +1,21 @@<br>
+# IR level Instrumentation Flag<br>
+:ir<br>
+bar<br>
+10<br>
+2<br>
+0<br>
+0<br>
+<br>
+main<br>
+16650<br>
+4<br>
+1<br>
+1000<br>
+1000000<br>
+499500<br>
+<br>
+foo<br>
+10<br>
+2<br>
+999<br>
+1<br>
<br>
Added: llvm/trunk/test/tools/llvm-profdata/cutoff.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/cutoff.test?rev=350579&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/cutoff.test?rev=350579&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-profdata/cutoff.test (added)<br>
+++ llvm/trunk/test/tools/llvm-profdata/cutoff.test Mon Jan  7 15:25:56 2019<br>
@@ -0,0 +1,23 @@<br>
+Basic tests for cutoff options in show command.<br>
+<br>
+RUN: llvm-profdata show -value-cutoff=1 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1 -check-prefix=CHECK<br>
+RUN: llvm-profdata show -value-cutoff=1000 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1000 -check-prefix=CHECK<br>
+RUN: llvm-profdata show -all-functions -value-cutoff=1 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1FUNC -check-prefix=CUTOFF1 -check-prefix=CHECK<br>
+RUN: llvm-profdata show -all-functions -value-cutoff=1000 %p/Inputs/cutoff.proftext | FileCheck %s -check-prefix=CUTOFF1000FUNC -check-prefix=CUTOFF1000 -check-prefix=CHECK<br>
+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<br>
+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<br>
+CUTOFF1FUNC-NOT: bar<br>
+CUTOFF1FUNC: Functions shown: 2<br>
+CUTOFF1000FUNC-NOT: bar<br>
+CUTOFF1000FUNC-NOT: foo<br>
+CUTOFF1000FUNC: Functions shown: 1<br>
+BELOW1: The list of functions with the maximum counter less than 1:<br>
+BELOW1:  bar: (Max = 0 Sum = 0)<br>
+BELOW1000:The list of functions with the maximum counter less than 1000:<br>
+BELOW1000:  bar: (Max = 0 Sum = 0)<br>
+BELOW1000:  foo: (Max = 999 Sum = 1000)<br>
+CHECK: Total functions: 3<br>
+CUTOFF1: Number of functions with maximum count (< 1): 1<br>
+CUTOFF1: Number of functions with maximum count (>= 1): 2<br>
+CUTOFF1000: Number of functions with maximum count (< 1000): 2<br>
+CUTOFF1000: Number of functions with maximum count (>= 1000): 1<br>
<br>
Modified: llvm/trunk/test/tools/llvm-profdata/value-prof.proftext<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/value-prof.proftext?rev=350579&r1=350578&r2=350579&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/value-prof.proftext?rev=350579&r1=350578&r2=350579&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-profdata/value-prof.proftext (original)<br>
+++ llvm/trunk/test/tools/llvm-profdata/value-prof.proftext Mon Jan  7 15:25:56 2019<br>
@@ -47,9 +47,9 @@ foo2:20000<br>
<br>
 #ICTXT: Indirect Call Site Count: 3<br>
 #ICTXT-NEXT:    Indirect Target Results:<br>
-#ICTXT-NEXT:   [ 1, foo, 100 ]<br>
-#ICTXT-NEXT:   [ 1, foo2, 1000 ]<br>
-#ICTXT-NEXT:   [ 2, foo2, 20000 ]<br>
+#ICTXT-NEXT:   [ 1, foo, 100 ] (9.09%)<br>
+#ICTXT-NEXT:   [ 1, foo2, 1000 ] (90.91%)<br>
+#ICTXT-NEXT:   [ 2, foo2, 20000 ] (100.00%)<br>
<br>
 #IC: Indirect Call Site Count: 3<br>
 #IC-NEXT:    Indirect Target Results:<br>
<br>
Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=350579&r1=350578&r2=350579&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=350579&r1=350578&r2=350579&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)<br>
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Mon Jan  7 15:25:56 2019<br>
@@ -633,13 +633,21 @@ static void traverseAllValueSites(const<br>
         Stats.ValueSitesHistogram.resize(NV, 0);<br>
       Stats.ValueSitesHistogram[NV - 1]++;<br>
     }<br>
+<br>
+    uint64_t SiteSum = 0;<br>
+    for (uint32_t V = 0; V < NV; V++)<br>
+      SiteSum += VD[V].Count;<br>
+    if (SiteSum == 0)<br>
+      SiteSum = 1;<br>
+<br>
     for (uint32_t V = 0; V < NV; V++) {<br>
-      OS << "\t[ " << I << ", ";<br>
+      OS << "\t[ " << format("%2u", I) << ", ";<br>
       if (Symtab == nullptr)<br>
-        OS << VD[V].Value;<br>
+        OS << format("%4u", VD[V].Value);<br>
       else<br>
         OS << Symtab->getFuncName(VD[V].Value);<br>
-      OS << ", " << VD[V].Count << " ]\n";<br>
+      OS << ", " << format("%10" PRId64, VD[V].Count) << " ] ("<br>
+         << format("%.2f%%", (VD[V].Count * 100.0 / SiteSum)) << ")\n";<br>
     }<br>
   }<br>
 }<br>
@@ -662,9 +670,9 @@ static int showInstrProfile(const std::s<br>
                             uint32_t TopN, bool ShowIndirectCallTargets,<br>
                             bool ShowMemOPSizes, bool ShowDetailedSummary,<br>
                             std::vector<uint32_t> DetailedSummaryCutoffs,<br>
-                            bool ShowAllFunctions,<br>
-                            const std::string &ShowFunction, bool TextFormat,<br>
-                            raw_fd_ostream &OS) {<br>
+                            bool ShowAllFunctions, uint64_t ValueCutoff,<br>
+                            bool OnlyListBelow, const std::string &ShowFunction,<br>
+                            bool TextFormat, raw_fd_ostream &OS) {<br>
   auto ReaderOrErr = InstrProfReader::create(Filename);<br>
   std::vector<uint32_t> Cutoffs = std::move(DetailedSummaryCutoffs);<br>
   if (ShowDetailedSummary && Cutoffs.empty()) {<br>
@@ -677,6 +685,7 @@ static int showInstrProfile(const std::s<br>
   auto Reader = std::move(ReaderOrErr.get());<br>
   bool IsIRInstr = Reader->isIRLevelProfile();<br>
   size_t ShownFunctions = 0;<br>
+  size_t BelowCutoffFunctions = 0;<br>
   int NumVPKind = IPVK_Last - IPVK_First + 1;<br>
   std::vector<ValueSitesStats> VPStats(NumVPKind);<br>
<br>
@@ -690,6 +699,11 @@ static int showInstrProfile(const std::s<br>
                       decltype(MinCmp)><br>
       HottestFuncs(MinCmp);<br>
<br>
+  if (!TextFormat && OnlyListBelow) {<br>
+    OS << "The list of functions with the maximum counter less than "<br>
+       << ValueCutoff << ":\n";<br>
+  }<br>
+<br>
   // Add marker so that IR-level instrumentation round-trips properly.<br>
   if (TextFormat && IsIRInstr)<br>
     OS << ":ir\n";<br>
@@ -711,11 +725,24 @@ static int showInstrProfile(const std::s<br>
     assert(Func.Counts.size() > 0 && "function missing entry counter");<br>
     Builder.addRecord(Func);<br>
<br>
-    if (TopN) {<br>
-      uint64_t FuncMax = 0;<br>
-      for (size_t I = 0, E = Func.Counts.size(); I < E; ++I)<br>
-        FuncMax = std::max(FuncMax, Func.Counts[I]);<br>
+    uint64_t FuncMax = 0;<br>
+    uint64_t FuncSum = 0;<br>
+    for (size_t I = 0, E = Func.Counts.size(); I < E; ++I) {<br>
+      FuncMax = std::max(FuncMax, Func.Counts[I]);<br>
+      FuncSum += Func.Counts[I];<br>
+    }<br>
+<br>
+    if (FuncMax < ValueCutoff) {<br>
+      ++BelowCutoffFunctions;<br>
+      if (OnlyListBelow) {<br>
+        OS << "  " << Func.Name << ": (Max = " << FuncMax<br>
+           << " Sum = " << FuncSum << ")\n";<br>
+      }<br>
+      continue;<br>
+    } else if (OnlyListBelow)<br>
+      continue;<br>
<br>
+    if (TopN) {<br>
       if (HottestFuncs.size() == TopN) {<br>
         if (HottestFuncs.top().second < FuncMax) {<br>
           HottestFuncs.pop();<br>
@@ -726,7 +753,6 @@ static int showInstrProfile(const std::s<br>
     }<br>
<br>
     if (Show) {<br>
-<br>
       if (!ShownFunctions)<br>
         OS << "Counters:\n";<br>
<br>
@@ -781,6 +807,12 @@ static int showInstrProfile(const std::s<br>
   if (ShowAllFunctions || !ShowFunction.empty())<br>
     OS << "Functions shown: " << ShownFunctions << "\n";<br>
   OS << "Total functions: " << PS->getNumFunctions() << "\n";<br>
+  if (ValueCutoff > 0) {<br>
+    OS << "Number of functions with maximum count (< " << ValueCutoff<br>
+       << "): " << BelowCutoffFunctions << "\n";<br>
+    OS << "Number of functions with maximum count (>= " << ValueCutoff<br>
+       << "): " << PS->getNumFunctions() - BelowCutoffFunctions << "\n";<br>
+  }<br>
   OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";<br>
   OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";<br>
<br>
@@ -882,7 +914,14 @@ static int show_main(int argc, const cha<br>
   cl::opt<uint32_t> TopNFunctions(<br>
       "topn", cl::init(0),<br>
       cl::desc("Show the list of functions with the largest internal counts"));<br>
-<br>
+  cl::opt<uint32_t> ValueCutoff(<br>
+      "value-cutoff", cl::init(0),<br>
+      cl::desc("Set the count value cutoff. Functions with the maximum count "<br>
+               "less than this value will not be printed out. (Default is 0)"));<br>
+  cl::opt<bool> OnlyListBelow(<br>
+      "list-below-cutoff", cl::init(false),<br>
+      cl::desc("Only output names of functions whose max count values are "<br>
+               "below the cutoff value"));<br>
   cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n");<br>
<br>
   if (OutputFilename.empty())<br>
@@ -902,7 +941,8 @@ static int show_main(int argc, const cha<br>
     return showInstrProfile(Filename, ShowCounts, TopNFunctions,<br>
                             ShowIndirectCallTargets, ShowMemOPSizes,<br>
                             ShowDetailedSummary, DetailedSummaryCutoffs,<br>
-                            ShowAllFunctions, ShowFunction, TextFormat, OS);<br>
+                            ShowAllFunctions, ValueCutoff, OnlyListBelow,<br>
+                            ShowFunction, TextFormat, OS);<br>
   else<br>
     return showSampleProfile(Filename, ShowCounts, ShowAllFunctions,<br>
                              ShowFunction, OS);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>