[llvm] 546be08 - [llvm-profdata] --hot-func-list: fix some style issues in D81800

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 15:18:19 PDT 2020


Author: Fangrui Song
Date: 2020-06-24T15:17:03-07:00
New Revision: 546be0883784838be5d07a82f39ec4390f49e19e

URL: https://github.com/llvm/llvm-project/commit/546be0883784838be5d07a82f39ec4390f49e19e
DIFF: https://github.com/llvm/llvm-project/commit/546be0883784838be5d07a82f39ec4390f49e19e.diff

LOG: [llvm-profdata] --hot-func-list: fix some style issues in D81800

Reviewed By: wenlei, hoyFB

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 53087df9fa15..562468333ef4 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -502,14 +502,11 @@ class FunctionSamples {
   /// 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;
   }
 

diff  --git a/llvm/test/tools/llvm-profdata/sample-hot-func-list.test b/llvm/test/tools/llvm-profdata/sample-hot-func-list.test
index 352056c6694f..2ea81363d49c 100644
--- a/llvm/test/tools/llvm-profdata/sample-hot-func-list.test
+++ b/llvm/test/tools/llvm-profdata/sample-hot-func-list.test
@@ -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

diff  --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 5fdb0ce8cc8d..1eb4bc66d60c 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -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,


        


More information about the llvm-commits mailing list