Skip to content

Commit e9b590a

Browse files
[nfc][llvm-profdata] Move show options to its namespace
1 parent 6a451ea commit e9b590a

File tree

1 file changed

+115
-137
lines changed

1 file changed

+115
-137
lines changed

llvm/tools/llvm-profdata/llvm-profdata.cpp

+115-137
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,7 @@ static int overlap_main(int argc, const char *argv[]) {
23872387
return 0;
23882388
}
23892389

2390+
namespace show_llvmprofdata {
23902391
namespace {
23912392
struct ValueSitesStats {
23922393
ValueSitesStats()
@@ -2447,14 +2448,101 @@ static void showValueSitesStats(raw_fd_ostream &OS, uint32_t VK,
24472448
}
24482449
}
24492450

2450-
static int showInstrProfile(
2451-
const std::string &Filename, bool ShowCounts, uint32_t TopN,
2452-
bool ShowIndirectCallTargets, bool ShowMemOPSizes, bool ShowDetailedSummary,
2453-
std::vector<uint32_t> DetailedSummaryCutoffs, bool ShowAllFunctions,
2454-
bool ShowCS, uint64_t ValueCutoff, bool OnlyListBelow,
2455-
const std::string &ShowFunction, bool TextFormat, bool ShowBinaryIds,
2456-
bool ShowCovered, bool ShowProfileVersion, bool ShowTemporalProfTraces,
2457-
ShowFormat SFormat, raw_fd_ostream &OS) {
2451+
cl::opt<std::string> Filename(cl::Positional, cl::desc("<profdata-file>"));
2452+
2453+
cl::opt<bool> ShowCounts("counts", cl::init(false),
2454+
cl::desc("Show counter values for shown functions"));
2455+
cl::opt<ShowFormat>
2456+
SFormat("show-format", cl::init(ShowFormat::Text),
2457+
cl::desc("Emit output in the selected format if supported"),
2458+
cl::values(clEnumValN(ShowFormat::Text, "text",
2459+
"emit normal text output (default)"),
2460+
clEnumValN(ShowFormat::Json, "json", "emit JSON"),
2461+
clEnumValN(ShowFormat::Yaml, "yaml", "emit YAML")));
2462+
// TODO: Consider replacing this with `--show-format=text-encoding`.
2463+
cl::opt<bool>
2464+
TextFormat("text", cl::init(false),
2465+
cl::desc("Show instr profile data in text dump format"));
2466+
cl::opt<bool>
2467+
JsonFormat("json", cl::desc("Show sample profile data in the JSON format "
2468+
"(deprecated, please use --show-format=json)"));
2469+
cl::opt<bool> ShowIndirectCallTargets(
2470+
"ic-targets", cl::init(false),
2471+
cl::desc("Show indirect call site target values for shown functions"));
2472+
cl::opt<bool> ShowMemOPSizes(
2473+
"memop-sizes", cl::init(false),
2474+
cl::desc("Show the profiled sizes of the memory intrinsic calls "
2475+
"for shown functions"));
2476+
cl::opt<bool> ShowDetailedSummary("detailed-summary", cl::init(false),
2477+
cl::desc("Show detailed profile summary"));
2478+
cl::list<uint32_t> DetailedSummaryCutoffs(
2479+
cl::CommaSeparated, "detailed-summary-cutoffs",
2480+
cl::desc(
2481+
"Cutoff percentages (times 10000) for generating detailed summary"),
2482+
cl::value_desc("800000,901000,999999"));
2483+
cl::opt<bool> ShowHotFuncList(
2484+
"hot-func-list", cl::init(false),
2485+
cl::desc("Show profile summary of a list of hot functions"));
2486+
cl::opt<bool> ShowAllFunctions("all-functions", cl::init(false),
2487+
cl::desc("Details for every function"));
2488+
cl::opt<bool> ShowCS("showcs", cl::init(false),
2489+
cl::desc("Show context sensitive counts"));
2490+
cl::opt<std::string> ShowFunction("function",
2491+
cl::desc("Details for matching functions"));
2492+
2493+
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
2494+
cl::init("-"), cl::desc("Output file"));
2495+
cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
2496+
cl::aliasopt(OutputFilename));
2497+
cl::opt<ProfileKinds> ProfileKind(
2498+
cl::desc("Profile kind:"), cl::init(instr),
2499+
cl::values(clEnumVal(instr, "Instrumentation profile (default)"),
2500+
clEnumVal(sample, "Sample profile"),
2501+
clEnumVal(memory, "MemProf memory access profile")));
2502+
cl::opt<uint32_t> TopNFunctions(
2503+
"topn", cl::init(0),
2504+
cl::desc("Show the list of functions with the largest internal counts"));
2505+
cl::opt<uint32_t> ValueCutoff(
2506+
"value-cutoff", cl::init(0),
2507+
cl::desc("Set the count value cutoff. Functions with the maximum count "
2508+
"less than this value will not be printed out. (Default is 0)"));
2509+
cl::opt<bool> OnlyListBelow(
2510+
"list-below-cutoff", cl::init(false),
2511+
cl::desc("Only output names of functions whose max count values are "
2512+
"below the cutoff value"));
2513+
cl::opt<bool> ShowProfileSymbolList(
2514+
"show-prof-sym-list", cl::init(false),
2515+
cl::desc("Show profile symbol list if it exists in the profile. "));
2516+
cl::opt<bool> ShowSectionInfoOnly(
2517+
"show-sec-info-only", cl::init(false),
2518+
cl::desc("Show the information of each section in the sample profile. "
2519+
"The flag is only usable when the sample profile is in "
2520+
"extbinary format"));
2521+
cl::opt<bool> ShowBinaryIds("binary-ids", cl::init(false),
2522+
cl::desc("Show binary ids in the profile. "));
2523+
cl::opt<bool> ShowTemporalProfTraces(
2524+
"temporal-profile-traces",
2525+
cl::desc("Show temporal profile traces in the profile."));
2526+
cl::opt<std::string> DebugInfoFilename(
2527+
"debug-info", cl::init(""),
2528+
cl::desc("Read and extract profile metadata from debug info and show "
2529+
"the functions it found."));
2530+
cl::opt<unsigned> MaxDbgCorrelationWarnings(
2531+
"max-debug-info-correlation-warnings",
2532+
cl::desc("The maximum number of warnings to emit when correlating "
2533+
"profile from debug info (0 = no limit)"),
2534+
cl::init(5));
2535+
cl::opt<bool>
2536+
ShowCovered("covered", cl::init(false),
2537+
cl::desc("Show only the functions that have been executed."));
2538+
cl::opt<std::string> ProfiledBinary(
2539+
"profiled-binary", cl::init(""),
2540+
cl::desc("Path to binary from which the profile was collected."));
2541+
cl::opt<bool> ShowProfileVersion("profile-version", cl::init(false),
2542+
cl::desc("Show profile version. "));
2543+
2544+
static int showInstrProfile(const std::string &Filename, ShowFormat SFormat,
2545+
raw_fd_ostream &OS) {
24582546
if (SFormat == ShowFormat::Json)
24592547
exitWithError("JSON output is not supported for instr profiles");
24602548
if (SFormat == ShowFormat::Yaml)
@@ -2559,8 +2647,8 @@ static int showInstrProfile(
25592647
} else if (OnlyListBelow)
25602648
continue;
25612649

2562-
if (TopN) {
2563-
if (HottestFuncs.size() == TopN) {
2650+
if (TopNFunctions) {
2651+
if (HottestFuncs.size() == TopNFunctions) {
25642652
if (HottestFuncs.top().second < FuncMax) {
25652653
HottestFuncs.pop();
25662654
HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax));
@@ -2636,13 +2724,13 @@ static int showInstrProfile(
26362724
OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
26372725
OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
26382726

2639-
if (TopN) {
2727+
if (TopNFunctions) {
26402728
std::vector<std::pair<std::string, uint64_t>> SortedHottestFuncs;
26412729
while (!HottestFuncs.empty()) {
26422730
SortedHottestFuncs.emplace_back(HottestFuncs.top());
26432731
HottestFuncs.pop();
26442732
}
2645-
OS << "Top " << TopN
2733+
OS << "Top " << TopNFunctions
26462734
<< " functions with the largest internal block counts: \n";
26472735
for (auto &hotfunc : llvm::reverse(SortedHottestFuncs))
26482736
OS << " " << hotfunc.first << ", max count = " << hotfunc.second << "\n";
@@ -2832,13 +2920,8 @@ static int showHotFunctionList(const sampleprof::SampleProfileMap &Profiles,
28322920
return 0;
28332921
}
28342922

2835-
static int showSampleProfile(const std::string &Filename, bool ShowCounts,
2836-
uint32_t TopN, bool ShowAllFunctions,
2837-
bool ShowDetailedSummary,
2838-
const std::string &ShowFunction,
2839-
bool ShowProfileSymbolList,
2840-
bool ShowSectionInfoOnly, bool ShowHotFuncList,
2841-
ShowFormat SFormat, raw_fd_ostream &OS) {
2923+
static int showSampleProfile(const std::string &Filename, ShowFormat SFormat,
2924+
raw_fd_ostream &OS) {
28422925
if (SFormat == ShowFormat::Yaml)
28432926
exitWithError("YAML output is not supported for sample profiles");
28442927
using namespace sampleprof;
@@ -2886,15 +2969,14 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts,
28862969
PS.printDetailedSummary(OS);
28872970
}
28882971

2889-
if (ShowHotFuncList || TopN)
2890-
showHotFunctionList(Reader->getProfiles(), Reader->getSummary(), TopN, OS);
2972+
if (ShowHotFuncList || TopNFunctions)
2973+
showHotFunctionList(Reader->getProfiles(), Reader->getSummary(),
2974+
TopNFunctions, OS);
28912975

28922976
return 0;
28932977
}
28942978

2895-
static int showMemProfProfile(const std::string &Filename,
2896-
const std::string &ProfiledBinary,
2897-
ShowFormat SFormat, raw_fd_ostream &OS) {
2979+
static int showMemProfProfile(const std::string &Filename, raw_fd_ostream &OS) {
28982980
if (SFormat == ShowFormat::Json)
28992981
exitWithError("JSON output is not supported for MemProf");
29002982
auto ReaderOr = llvm::memprof::RawMemProfReader::create(
@@ -2913,10 +2995,7 @@ static int showMemProfProfile(const std::string &Filename,
29132995
}
29142996

29152997
static int showDebugInfoCorrelation(const std::string &Filename,
2916-
bool ShowDetailedSummary,
2917-
bool ShowProfileSymbolList,
2918-
int MaxDbgCorrelationWarnings,
2919-
ShowFormat SFormat, raw_fd_ostream &OS) {
2998+
raw_fd_ostream &OS) {
29202999
if (SFormat == ShowFormat::Json)
29213000
exitWithError("JSON output is not supported for debug info correlation");
29223001
std::unique_ptr<InstrProfCorrelator> Correlator;
@@ -2950,101 +3029,8 @@ static int showDebugInfoCorrelation(const std::string &Filename,
29503029
return 0;
29513030
}
29523031

2953-
static int show_main(int argc, const char *argv[]) {
2954-
cl::opt<std::string> Filename(cl::Positional, cl::desc("<profdata-file>"));
2955-
2956-
cl::opt<bool> ShowCounts("counts", cl::init(false),
2957-
cl::desc("Show counter values for shown functions"));
2958-
cl::opt<ShowFormat> SFormat(
2959-
"show-format", cl::init(ShowFormat::Text),
2960-
cl::desc("Emit output in the selected format if supported"),
2961-
cl::values(clEnumValN(ShowFormat::Text, "text",
2962-
"emit normal text output (default)"),
2963-
clEnumValN(ShowFormat::Json, "json", "emit JSON"),
2964-
clEnumValN(ShowFormat::Yaml, "yaml", "emit YAML")));
2965-
// TODO: Consider replacing this with `--show-format=text-encoding`.
2966-
cl::opt<bool> TextFormat(
2967-
"text", cl::init(false),
2968-
cl::desc("Show instr profile data in text dump format"));
2969-
cl::opt<bool> JsonFormat(
2970-
"json", cl::desc("Show sample profile data in the JSON format "
2971-
"(deprecated, please use --show-format=json)"));
2972-
cl::opt<bool> ShowIndirectCallTargets(
2973-
"ic-targets", cl::init(false),
2974-
cl::desc("Show indirect call site target values for shown functions"));
2975-
cl::opt<bool> ShowMemOPSizes(
2976-
"memop-sizes", cl::init(false),
2977-
cl::desc("Show the profiled sizes of the memory intrinsic calls "
2978-
"for shown functions"));
2979-
cl::opt<bool> ShowDetailedSummary("detailed-summary", cl::init(false),
2980-
cl::desc("Show detailed profile summary"));
2981-
cl::list<uint32_t> DetailedSummaryCutoffs(
2982-
cl::CommaSeparated, "detailed-summary-cutoffs",
2983-
cl::desc(
2984-
"Cutoff percentages (times 10000) for generating detailed summary"),
2985-
cl::value_desc("800000,901000,999999"));
2986-
cl::opt<bool> ShowHotFuncList(
2987-
"hot-func-list", cl::init(false),
2988-
cl::desc("Show profile summary of a list of hot functions"));
2989-
cl::opt<bool> ShowAllFunctions("all-functions", cl::init(false),
2990-
cl::desc("Details for every function"));
2991-
cl::opt<bool> ShowCS("showcs", cl::init(false),
2992-
cl::desc("Show context sensitive counts"));
2993-
cl::opt<std::string> ShowFunction("function",
2994-
cl::desc("Details for matching functions"));
2995-
2996-
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
2997-
cl::init("-"), cl::desc("Output file"));
2998-
cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
2999-
cl::aliasopt(OutputFilename));
3000-
cl::opt<ProfileKinds> ProfileKind(
3001-
cl::desc("Profile kind:"), cl::init(instr),
3002-
cl::values(clEnumVal(instr, "Instrumentation profile (default)"),
3003-
clEnumVal(sample, "Sample profile"),
3004-
clEnumVal(memory, "MemProf memory access profile")));
3005-
cl::opt<uint32_t> TopNFunctions(
3006-
"topn", cl::init(0),
3007-
cl::desc("Show the list of functions with the largest internal counts"));
3008-
cl::opt<uint32_t> ValueCutoff(
3009-
"value-cutoff", cl::init(0),
3010-
cl::desc("Set the count value cutoff. Functions with the maximum count "
3011-
"less than this value will not be printed out. (Default is 0)"));
3012-
cl::opt<bool> OnlyListBelow(
3013-
"list-below-cutoff", cl::init(false),
3014-
cl::desc("Only output names of functions whose max count values are "
3015-
"below the cutoff value"));
3016-
cl::opt<bool> ShowProfileSymbolList(
3017-
"show-prof-sym-list", cl::init(false),
3018-
cl::desc("Show profile symbol list if it exists in the profile. "));
3019-
cl::opt<bool> ShowSectionInfoOnly(
3020-
"show-sec-info-only", cl::init(false),
3021-
cl::desc("Show the information of each section in the sample profile. "
3022-
"The flag is only usable when the sample profile is in "
3023-
"extbinary format"));
3024-
cl::opt<bool> ShowBinaryIds("binary-ids", cl::init(false),
3025-
cl::desc("Show binary ids in the profile. "));
3026-
cl::opt<bool> ShowTemporalProfTraces(
3027-
"temporal-profile-traces",
3028-
cl::desc("Show temporal profile traces in the profile."));
3029-
cl::opt<std::string> DebugInfoFilename(
3030-
"debug-info", cl::init(""),
3031-
cl::desc("Read and extract profile metadata from debug info and show "
3032-
"the functions it found."));
3033-
cl::opt<unsigned> MaxDbgCorrelationWarnings(
3034-
"max-debug-info-correlation-warnings",
3035-
cl::desc("The maximum number of warnings to emit when correlating "
3036-
"profile from debug info (0 = no limit)"),
3037-
cl::init(5));
3038-
cl::opt<bool> ShowCovered(
3039-
"covered", cl::init(false),
3040-
cl::desc("Show only the functions that have been executed."));
3041-
cl::opt<std::string> ProfiledBinary(
3042-
"profiled-binary", cl::init(""),
3043-
cl::desc("Path to binary from which the profile was collected."));
3044-
cl::opt<bool> ShowProfileVersion("profile-version", cl::init(false),
3045-
cl::desc("Show profile version. "));
3032+
static int main(int argc, const char *argv[]) {
30463033
cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n");
3047-
30483034
if (Filename.empty() && DebugInfoFilename.empty())
30493035
exitWithError(
30503036
"the positional argument '<profdata-file>' is required unless '--" +
@@ -3067,25 +3053,17 @@ static int show_main(int argc, const char *argv[]) {
30673053
WithColor::warning() << "-function argument ignored: showing all functions\n";
30683054

30693055
if (!DebugInfoFilename.empty())
3070-
return showDebugInfoCorrelation(DebugInfoFilename, ShowDetailedSummary,
3071-
ShowProfileSymbolList,
3072-
MaxDbgCorrelationWarnings, SFormat, OS);
3056+
return showDebugInfoCorrelation(DebugInfoFilename, OS);
30733057

30743058
if (ProfileKind == instr)
3075-
return showInstrProfile(
3076-
Filename, ShowCounts, TopNFunctions, ShowIndirectCallTargets,
3077-
ShowMemOPSizes, ShowDetailedSummary, DetailedSummaryCutoffs,
3078-
ShowAllFunctions, ShowCS, ValueCutoff, OnlyListBelow, ShowFunction,
3079-
TextFormat, ShowBinaryIds, ShowCovered, ShowProfileVersion,
3080-
ShowTemporalProfTraces, SFormat, OS);
3059+
return showInstrProfile(Filename, SFormat, OS);
30813060
if (ProfileKind == sample)
3082-
return showSampleProfile(Filename, ShowCounts, TopNFunctions,
3083-
ShowAllFunctions, ShowDetailedSummary,
3084-
ShowFunction, ShowProfileSymbolList,
3085-
ShowSectionInfoOnly, ShowHotFuncList, SFormat, OS);
3086-
return showMemProfProfile(Filename, ProfiledBinary, SFormat, OS);
3061+
return showSampleProfile(Filename, SFormat, OS);
3062+
return showMemProfProfile(Filename, SFormat, OS);
30873063
}
30883064

3065+
} // namespace show_llvmprofdata
3066+
30893067
static int order_main(int argc, const char *argv[]) {
30903068
cl::opt<std::string> Filename(cl::Positional, cl::desc("<profdata-file>"));
30913069
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
@@ -3130,7 +3108,7 @@ typedef int (*llvm_profdata_subcommand)(int, const char *[]);
31303108
static std::tuple<StringRef, llvm_profdata_subcommand>
31313109
llvm_profdata_subcommands[] = {
31323110
{"merge", merge_main},
3133-
{"show", show_main},
3111+
{"show", show_llvmprofdata::main},
31343112
{"order", order_main},
31353113
{"overlap", overlap_main},
31363114
};

0 commit comments

Comments
 (0)