46
46
#include < algorithm>
47
47
#include < cmath>
48
48
#include < optional>
49
- #include < queue>
50
49
51
50
using namespace llvm ;
52
51
using ProfCorrelatorKind = InstrProfCorrelator::ProfCorrelatorKind;
@@ -2846,9 +2845,8 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
2846
2845
auto FS = vfs::getRealFileSystem ();
2847
2846
auto ReaderOrErr = InstrProfReader::create (Filename, *FS);
2848
2847
std::vector<uint32_t > Cutoffs = std::move (DetailedSummaryCutoffs);
2849
- if (ShowDetailedSummary && Cutoffs. empty ()) {
2848
+ if (Cutoffs. empty () && (ShowDetailedSummary || ShowHotFuncList))
2850
2849
Cutoffs = ProfileSummaryBuilder::DefaultCutoffs;
2851
- }
2852
2850
InstrProfSummaryBuilder Builder (std::move (Cutoffs));
2853
2851
if (Error E = ReaderOrErr.takeError ())
2854
2852
exitWithError (std::move (E), Filename);
@@ -2860,15 +2858,7 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
2860
2858
int NumVPKind = IPVK_Last - IPVK_First + 1 ;
2861
2859
std::vector<ValueSitesStats> VPStats (NumVPKind);
2862
2860
2863
- auto MinCmp = [](const std::pair<std::string, uint64_t > &v1,
2864
- const std::pair<std::string, uint64_t > &v2) {
2865
- return v1.second > v2.second ;
2866
- };
2867
-
2868
- std::priority_queue<std::pair<std::string, uint64_t >,
2869
- std::vector<std::pair<std::string, uint64_t >>,
2870
- decltype (MinCmp)>
2871
- HottestFuncs (MinCmp);
2861
+ std::vector<std::pair<StringRef, uint64_t >> NameAndMaxCount;
2872
2862
2873
2863
if (!TextFormat && OnlyListBelow) {
2874
2864
OS << " The list of functions with the maximum counter less than "
@@ -2942,15 +2932,8 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
2942
2932
if (OnlyListBelow)
2943
2933
continue ;
2944
2934
2945
- if (TopNFunctions) {
2946
- if (HottestFuncs.size () == TopNFunctions) {
2947
- if (HottestFuncs.top ().second < FuncMax) {
2948
- HottestFuncs.pop ();
2949
- HottestFuncs.emplace (std::make_pair (std::string (Func.Name ), FuncMax));
2950
- }
2951
- } else
2952
- HottestFuncs.emplace (std::make_pair (std::string (Func.Name ), FuncMax));
2953
- }
2935
+ if (TopNFunctions || ShowHotFuncList)
2936
+ NameAndMaxCount.emplace_back (Func.Name , FuncMax);
2954
2937
2955
2938
if (Show) {
2956
2939
if (!ShownFunctions)
@@ -3029,16 +3012,27 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
3029
3012
<< " ): " << PS->getNumFunctions () - BelowCutoffFunctions << " \n " ;
3030
3013
}
3031
3014
3015
+ // Sort by MaxCount in decreasing order
3016
+ llvm::stable_sort (NameAndMaxCount, [](const auto &L, const auto &R) {
3017
+ return L.second > R.second ;
3018
+ });
3032
3019
if (TopNFunctions) {
3033
- std::vector<std::pair<std::string, uint64_t >> SortedHottestFuncs;
3034
- while (!HottestFuncs.empty ()) {
3035
- SortedHottestFuncs.emplace_back (HottestFuncs.top ());
3036
- HottestFuncs.pop ();
3037
- }
3038
3020
OS << " Top " << TopNFunctions
3039
3021
<< " functions with the largest internal block counts: \n " ;
3040
- for (auto &hotfunc : llvm::reverse (SortedHottestFuncs))
3041
- OS << " " << hotfunc.first << " , max count = " << hotfunc.second << " \n " ;
3022
+ auto TopFuncs = ArrayRef (NameAndMaxCount).take_front (TopNFunctions);
3023
+ for (auto [Name, MaxCount] : TopFuncs)
3024
+ OS << " " << Name << " , max count = " << MaxCount << " \n " ;
3025
+ }
3026
+
3027
+ if (ShowHotFuncList) {
3028
+ auto HotCountThreshold =
3029
+ ProfileSummaryBuilder::getHotCountThreshold (PS->getDetailedSummary ());
3030
+ OS << " # Hot count threshold: " << HotCountThreshold << " \n " ;
3031
+ for (auto [Name, MaxCount] : NameAndMaxCount) {
3032
+ if (MaxCount < HotCountThreshold)
3033
+ break ;
3034
+ OS << Name << " \n " ;
3035
+ }
3042
3036
}
3043
3037
3044
3038
if (ShownFunctions && ShowIndirectCallTargets) {
0 commit comments