diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -502,14 +502,11 @@ /// 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 --- 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 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -1027,6 +1027,7 @@ } } +namespace { struct HotFuncInfo { StringRef FuncName; uint64_t TotalCount; @@ -1042,6 +1043,7 @@ : 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 @@ } 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 @@ 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 @@ 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 @@ std::string("max sample >= ") + std::to_string(MinCountThreshold); std::vector 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,