@@ -2846,9 +2846,9 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
28462846 auto FS = vfs::getRealFileSystem ();
28472847 auto ReaderOrErr = InstrProfReader::create (Filename, *FS);
28482848 std::vector<uint32_t > Cutoffs = std::move (DetailedSummaryCutoffs);
2849- if (ShowDetailedSummary && Cutoffs.empty ()) {
2850- Cutoffs = ProfileSummaryBuilder::DefaultCutoffs;
2851- }
2849+ if (Cutoffs.empty ())
2850+ if (ShowDetailedSummary || ShowHotFuncList)
2851+ Cutoffs = ProfileSummaryBuilder::DefaultCutoffs;
28522852 InstrProfSummaryBuilder Builder (std::move (Cutoffs));
28532853 if (Error E = ReaderOrErr.takeError ())
28542854 exitWithError (std::move (E), Filename);
@@ -2860,15 +2860,7 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
28602860 int NumVPKind = IPVK_Last - IPVK_First + 1 ;
28612861 std::vector<ValueSitesStats> VPStats (NumVPKind);
28622862
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);
2863+ std::vector<std::pair<uint64_t , uint64_t >> NameRefAndMaxCount;
28722864
28732865 if (!TextFormat && OnlyListBelow) {
28742866 OS << " The list of functions with the maximum counter less than "
@@ -2942,15 +2934,9 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
29422934 if (OnlyListBelow)
29432935 continue ;
29442936
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- }
2937+ if (TopNFunctions || ShowHotFuncList)
2938+ NameRefAndMaxCount.emplace_back (IndexedInstrProf::ComputeHash (Func.Name ),
2939+ FuncMax);
29542940
29552941 if (Show) {
29562942 if (!ShownFunctions)
@@ -3029,16 +3015,26 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
30293015 << " ): " << PS->getNumFunctions () - BelowCutoffFunctions << " \n " ;
30303016 }
30313017
3018+ // Sort by MaxCount in decreasing order
3019+ llvm::stable_sort (NameRefAndMaxCount, [](const auto &L, const auto &R) {
3020+ return L.second > R.second ;
3021+ });
30323022 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- }
30383023 OS << " Top " << TopNFunctions
30393024 << " functions with the largest internal block counts: \n " ;
3040- for (auto &hotfunc : llvm::reverse (SortedHottestFuncs))
3041- OS << " " << hotfunc.first << " , max count = " << hotfunc.second << " \n " ;
3025+ auto TopFuncs = ArrayRef (NameRefAndMaxCount).take_front (TopNFunctions);
3026+ for (auto [NameRef, MaxCount] : TopFuncs)
3027+ OS << " " << Reader->getSymtab ().getFuncOrVarName (NameRef)
3028+ << " , max count = " << MaxCount << " \n " ;
3029+ }
3030+
3031+ if (ShowHotFuncList) {
3032+ auto HotCountThreshold =
3033+ ProfileSummaryBuilder::getHotCountThreshold (PS->getDetailedSummary ());
3034+ OS << " # Hot count threshold: " << HotCountThreshold << " \n " ;
3035+ for (auto [NameRef, MaxCount] : NameRefAndMaxCount)
3036+ if (MaxCount >= HotCountThreshold)
3037+ OS << Reader->getSymtab ().getFuncOrVarName (NameRef) << " \n " ;
30423038 }
30433039
30443040 if (ShownFunctions && ShowIndirectCallTargets) {
0 commit comments