[llvm] [profdata] Use --hot-func-list to show all hot functions (PR #149428)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 18 13:01:35 PDT 2025
================
@@ -3034,16 +3019,26 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
<< "): " << PS->getNumFunctions() - BelowCutoffFunctions << "\n";
}
+ // Sort by MaxCount in decreasing order
+ llvm::stable_sort(NameRefAndMaxCount, [](const auto &L, const auto &R) {
+ return L.second > R.second;
+ });
if (TopNFunctions) {
- std::vector<std::pair<std::string, uint64_t>> SortedHottestFuncs;
- while (!HottestFuncs.empty()) {
- SortedHottestFuncs.emplace_back(HottestFuncs.top());
- HottestFuncs.pop();
- }
OS << "Top " << TopNFunctions
<< " functions with the largest internal block counts: \n";
- for (auto &hotfunc : llvm::reverse(SortedHottestFuncs))
- OS << " " << hotfunc.first << ", max count = " << hotfunc.second << "\n";
+ auto TopFuncs = ArrayRef(NameRefAndMaxCount).take_front(TopNFunctions);
+ for (auto [NameRef, MaxCount] : TopFuncs)
+ OS << " " << Reader->getSymtab().getFuncOrVarName(NameRef)
+ << ", max count = " << MaxCount << "\n";
+ }
+
+ if (ShowHotFuncList) {
+ auto HotCountThreshold =
+ ProfileSummaryBuilder::getHotCountThreshold(PS->getDetailedSummary());
+ OS << "# Hot count threshold: " << HotCountThreshold << "\n";
+ for (auto [NameRef, MaxCount] : NameRefAndMaxCount)
+ if (MaxCount >= HotCountThreshold)
+ OS << Reader->getSymtab().getFuncOrVarName(NameRef) << "\n";
----------------
mingmingl-llvm wrote:
nit: exit the loop after seeing the first counter that's smaller than `HotCountThreshold`, given NameRefAndMaxCount is sorted by count descendingly.
https://github.com/llvm/llvm-project/pull/149428
More information about the llvm-commits
mailing list