[llvm-profdata] --hot-func-list: fix some style issues in D81800
authorFangrui Song <maskray@google.com>
Wed, 24 Jun 2020 22:17:03 +0000 (15:17 -0700)
committerFangrui Song <maskray@google.com>
Wed, 24 Jun 2020 22:17:03 +0000 (15:17 -0700)
Reviewed By: wenlei, hoyFB

Differential Revision: https://reviews.llvm.org/D82500

llvm/include/llvm/ProfileData/SampleProf.h
llvm/test/tools/llvm-profdata/sample-hot-func-list.test
llvm/tools/llvm-profdata/llvm-profdata.cpp

index 53087df..5624683 100644 (file)
@@ -502,14 +502,11 @@ public:
   /// inlined in it.
   uint64_t getMaxCountInside() const {
     uint64_t MaxCount = 0;
-    for (const auto &L : getBodySamples()) {
+    for (const auto &L : getBodySamples())
       MaxCount = std::max(MaxCount, L.second.getSamples());
-    }
-    for (const auto &C : getCallsiteSamples()) {
-      for (const auto &F : C.second) {
+    for (const auto &C : getCallsiteSamples())
+      for (const FunctionSamplesMap::value_type &F : C.second)
         MaxCount = std::max(MaxCount, F.second.getMaxCountInside());
-      }
-    }
     return MaxCount;
   }
 
index 352056c..2ea8136 100644 (file)
@@ -1,12 +1,13 @@
-; RUN: llvm-profdata show --sample --hot-func-list %S/Inputs/sample-hot-func-list.proftext | FileCheck %s
-; CHECK: 8 out of 10 functions with profile (80.00%) are considered hot functions (max sample >= 470).
-; CHECK-NEXT: 355251 out of 356026 profile counts (99.78%) are from hot functions.
-; CHECK-NEXT: Total sample (%)        Max sample        Entry sample    Function name
-; CHECK-NEXT: 184019 (51.69%)         2300              534             main
-; CHECK-NEXT: 97401 (27.36%)          10640             3035            Func3
-; CHECK-NEXT: 20305 (5.70%)           1000              1000            _Z3bazi
-; CHECK-NEXT: 20301 (5.70%)           1437              1437            _Z3bari
-; CHECK-NEXT: 17043 (4.79%)           3105              1594            Func2
-; CHECK-NEXT: 7711 (2.17%)            610               610             _Z3fooi
-; CHECK-NEXT: 6948 (1.95%)            3507              470             Func5
-; CHECK-NEXT: 1523 (0.43%)            563               169             Func1
+; RUN: llvm-profdata show --sample --hot-func-list %S/Inputs/sample-hot-func-list.proftext | FileCheck %s --match-full-lines --strict-whitespace
+
+;      CHECK:8 out of 10 functions with profile (80.00%) are considered hot functions (max sample >= 470).
+; CHECK-NEXT:355251 out of 356026 profile counts (99.78%) are from hot functions.
+; CHECK-NEXT: Total sample (%)       Max sample        Entry sample    Function name
+; CHECK-NEXT: 184019 (51.69%)        2300              534             main
+; CHECK-NEXT: 97401 (27.36%)         10640             3035            Func3
+; CHECK-NEXT: 20305 (5.70%)          1000              1000            _Z3bazi
+; CHECK-NEXT: 20301 (5.70%)          1437              1437            _Z3bari
+; CHECK-NEXT: 17043 (4.79%)          3105              1594            Func2
+; CHECK-NEXT: 7711 (2.17%)           610               610             _Z3fooi
+; CHECK-NEXT: 6948 (1.95%)           3507              470             Func5
+; CHECK-NEXT: 1523 (0.43%)           563               169             Func1
index 5fdb0ce..1eb4bc6 100644 (file)
@@ -1027,6 +1027,7 @@ static void showSectionInfo(sampleprof::SampleProfileReader *Reader,
   }
 }
 
+namespace {
 struct HotFuncInfo {
   StringRef FuncName;
   uint64_t TotalCount;
@@ -1042,6 +1043,7 @@ struct HotFuncInfo {
       : FuncName(FN), TotalCount(TS), TotalCountPercent(TSP), MaxCount(MS),
         EntryCount(ES) {}
 };
+} // namespace
 
 // Print out detailed information about hot functions in PrintValues vector.
 // Users specify titles and offset of every columns through ColumnTitle and
@@ -1079,7 +1081,7 @@ static void dumpHotFunctionList(const std::vector<std::string> &ColumnTitle,
   }
   FOS << "\n";
 
-  for (const auto &R : PrintValues) {
+  for (const HotFuncInfo &R : PrintValues) {
     FOS.PadToColumn(ColumnOffset[0]);
     FOS << R.TotalCount << " (" << format("%.2f%%", R.TotalCountPercent) << ")";
     FOS.PadToColumn(ColumnOffset[1]);
@@ -1100,7 +1102,7 @@ showHotFunctionList(const StringMap<sampleprof::FunctionSamples> &Profiles,
   const uint32_t HotFuncCutoff = 990000;
   auto &SummaryVector = PS.getDetailedSummary();
   uint64_t MinCountThreshold = 0;
-  for (const auto &SummaryEntry : SummaryVector) {
+  for (const ProfileSummaryEntry &SummaryEntry : SummaryVector) {
     if (SummaryEntry.Cutoff == HotFuncCutoff) {
       MinCountThreshold = SummaryEntry.MinCount;
       break;
@@ -1119,7 +1121,7 @@ showHotFunctionList(const StringMap<sampleprof::FunctionSamples> &Profiles,
   uint64_t HotFuncCount = 0;
   uint64_t MaxCount = 0;
   for (const auto &I : Profiles) {
-    const auto &FuncProf = I.second;
+    const FunctionSamples &FuncProf = I.second;
     ProfileTotalSample += FuncProf.getTotalSamples();
     MaxCount = FuncProf.getMaxCountInside();
 
@@ -1141,14 +1143,14 @@ showHotFunctionList(const StringMap<sampleprof::FunctionSamples> &Profiles,
       std::string("max sample >= ") + std::to_string(MinCountThreshold);
   std::vector<HotFuncInfo> PrintValues;
   for (const auto &FuncPair : HotFunc) {
-    const auto &FuncPtr = FuncPair.second.first;
+    const FunctionSamples &Func = *FuncPair.second.first;
     double TotalSamplePercent =
         (ProfileTotalSample > 0)
-            ? (FuncPtr->getTotalSamples() * 100.0) / ProfileTotalSample
+            ? (Func.getTotalSamples() * 100.0) / ProfileTotalSample
             : 0;
     PrintValues.emplace_back(HotFuncInfo(
-        FuncPtr->getFuncName(), FuncPtr->getTotalSamples(), TotalSamplePercent,
-        FuncPair.second.second, FuncPtr->getEntrySamples()));
+        Func.getFuncName(), Func.getTotalSamples(), TotalSamplePercent,
+        FuncPair.second.second, Func.getEntrySamples()));
   }
   dumpHotFunctionList(ColumnTitle, ColumnOffset, PrintValues, HotFuncCount,
                       Profiles.size(), HotFuncSample, ProfileTotalSample,