; 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/cs-sample.proftext | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=CS
; CS:2 out of 8 functions with profile (25.00%) are considered hot functions (max sample >= 23324).
; CS-NEXT: Total sample (%) Max sample Entry sample Function name
; CS-NEXT: 1467299 (74.52%) 287884 11 main:3 @ _Z5funcAi:1 @ _Z8funcLeafi
; CS-NEXT: 500853 (25.44%) 74946 20 main:3.1 @ _Z5funcBi:1 @ _Z8funcLeafi
+
+
+; RUN: llvm-profdata show --sample --topn=2 %S/Inputs/sample-hot-func-list.proftext | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=TOPN
+
+; TOPN:8 out of 10 functions with profile (80.00%) are considered hot functions (max sample >= 470).
+; TOPN-NEXT:355251 out of 356026 profile counts (99.78%) are from hot functions.
+; TOPN-NEXT: Total sample (%) Max sample Entry sample Function name
+; TOPN-NEXT: 184019 (51.69%) 2300 534 main
+; TOPN-NEXT: 97401 (27.36%) 10640 3035 Func3
+
+; RUN: llvm-profdata show --sample --topn=1 %S/Inputs/cs-sample.proftext | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=CS-TOPN
+
+; CS-TOPN:2 out of 8 functions with profile (25.00%) are considered hot functions (max sample >= 23324).
+; CS-TOPN-NEXT:1968152 out of 1968919 profile counts (99.96%) are from hot functions.
+; CS-TOPN-NEXT: Total sample (%) Max sample Entry sample Function name
+; CS-TOPN-NEXT: 1467299 (74.52%) 287884 11 main:3 @ _Z5funcAi:1 @ _Z8funcLeafi
uint64_t HotFuncCount, uint64_t TotalFuncCount,
uint64_t HotProfCount, uint64_t TotalProfCount,
const std::string &HotFuncMetric,
- raw_fd_ostream &OS) {
+ uint32_t TopNFunctions, raw_fd_ostream &OS) {
assert(ColumnOffset.size() == ColumnTitle.size() &&
"ColumnOffset and ColumnTitle should have the same size");
assert(ColumnTitle.size() >= 4 &&
}
FOS << "\n";
- for (const HotFuncInfo &R : PrintValues) {
+ uint32_t Count = 0;
+ for (const auto &R : PrintValues) {
+ if (TopNFunctions && (Count++ == TopNFunctions))
+ break;
FOS.PadToColumn(ColumnOffset[0]);
FOS << R.TotalCount << " (" << format("%.2f%%", R.TotalCountPercent) << ")";
FOS.PadToColumn(ColumnOffset[1]);
}
static int showHotFunctionList(const sampleprof::SampleProfileMap &Profiles,
- ProfileSummary &PS, raw_fd_ostream &OS) {
+ ProfileSummary &PS, uint32_t TopN,
+ raw_fd_ostream &OS) {
using namespace sampleprof;
const uint32_t HotFuncCutoff = 990000;
}
dumpHotFunctionList(ColumnTitle, ColumnOffset, PrintValues, HotFuncCount,
Profiles.size(), HotFuncSample, ProfileTotalSample,
- Metric, OS);
+ Metric, TopN, OS);
return 0;
}
static int showSampleProfile(const std::string &Filename, bool ShowCounts,
- bool ShowAllFunctions, bool ShowDetailedSummary,
+ uint32_t TopN, bool ShowAllFunctions,
+ bool ShowDetailedSummary,
const std::string &ShowFunction,
bool ShowProfileSymbolList,
bool ShowSectionInfoOnly, bool ShowHotFuncList,
PS.printDetailedSummary(OS);
}
- if (ShowHotFuncList)
- showHotFunctionList(Reader->getProfiles(), Reader->getSummary(), OS);
+ if (ShowHotFuncList || TopN)
+ showHotFunctionList(Reader->getProfiles(), Reader->getSummary(), TopN, OS);
return 0;
}
ShowAllFunctions, ShowCS, ValueCutoff, OnlyListBelow, ShowFunction,
TextFormat, ShowBinaryIds, OS);
else
- return showSampleProfile(Filename, ShowCounts, ShowAllFunctions,
- ShowDetailedSummary, ShowFunction,
- ShowProfileSymbolList, ShowSectionInfoOnly,
- ShowHotFuncList, OS);
+ return showSampleProfile(Filename, ShowCounts, TopNFunctions,
+ ShowAllFunctions, ShowDetailedSummary,
+ ShowFunction, ShowProfileSymbolList,
+ ShowSectionInfoOnly, ShowHotFuncList, OS);
}
int main(int argc, const char *argv[]) {