From ea607d033aff54b8be0fcc6d4931b0bfc5ebb252 Mon Sep 17 00:00:00 2001 From: Ellis Hoag Date: Fri, 7 Oct 2022 10:29:59 -0700 Subject: [PATCH] [llvm-profdata] Rename show flag to --show-format In https://reviews.llvm.org/D135127 we created the show flag `--output-format` which was confusing because it behaved differently than the same flag in the merge command. So, rename the flag to `--show-format`. This also allows us to add the `text` option to mean "normal text output" rather than "text-encoded profiles" like it does for the merge command. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D135467 --- .../Linux/instrprof-show-debug-info-correlation.c | 2 +- llvm/docs/CommandGuide/llvm-profdata.rst | 2 +- .../tools/llvm-profdata/sample-profile-json.test | 2 +- llvm/tools/llvm-profdata/llvm-profdata.cpp | 49 ++++++++++++---------- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c b/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c index a7ea54f..f143901 100644 --- a/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c +++ b/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c @@ -1,6 +1,6 @@ // RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s // RUN: llvm-profdata show --debug-info=%t --detailed-summary --show-prof-sym-list | FileCheck %s -// RUN: llvm-profdata show --debug-info=%t --output-format=yaml | FileCheck %s --match-full-lines --check-prefix YAML +// RUN: llvm-profdata show --debug-info=%t --show-format=yaml | FileCheck %s --match-full-lines --check-prefix YAML // RUN: %clang_pgogen -o %t.no.dbg -mllvm --debug-info-correlate -mllvm --disable-vp=true %s // RUN: not llvm-profdata show --debug-info=%t.no.dbg 2>&1 | FileCheck %s --check-prefix NO-DBG diff --git a/llvm/docs/CommandGuide/llvm-profdata.rst b/llvm/docs/CommandGuide/llvm-profdata.rst index 12feed5..89a6245 100644 --- a/llvm/docs/CommandGuide/llvm-profdata.rst +++ b/llvm/docs/CommandGuide/llvm-profdata.rst @@ -253,7 +253,7 @@ OPTIONS Print the counter values for the displayed functions. -.. option:: --output-format= +.. option:: --show-format= Emit output in the selected format if supported by the provided profile type. diff --git a/llvm/test/tools/llvm-profdata/sample-profile-json.test b/llvm/test/tools/llvm-profdata/sample-profile-json.test index 9a19ab0..9e96693 100644 --- a/llvm/test/tools/llvm-profdata/sample-profile-json.test +++ b/llvm/test/tools/llvm-profdata/sample-profile-json.test @@ -1,5 +1,5 @@ RUN: llvm-profdata show --sample --json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON -RUN: llvm-profdata show --sample --output-format=json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON +RUN: llvm-profdata show --sample --show-format=json %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=JSON JSON: [ JSON-NEXT: { JSON-NEXT: "name": "main", diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 95019c9..5e2067e 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -57,7 +57,7 @@ enum ProfileFormat { PF_Binary }; -enum class OutputFormat { None, Json, Yaml }; +enum class ShowFormat { Text, Json, Yaml }; static void warn(Twine Message, std::string Whence = "", std::string Hint = "") { @@ -2254,11 +2254,11 @@ static int showInstrProfile(const std::string &Filename, bool ShowCounts, uint64_t ValueCutoff, bool OnlyListBelow, const std::string &ShowFunction, bool TextFormat, bool ShowBinaryIds, bool ShowCovered, - bool ShowProfileVersion, OutputFormat OFormat, + bool ShowProfileVersion, ShowFormat SFormat, raw_fd_ostream &OS) { - if (OFormat == OutputFormat::Json) + if (SFormat == ShowFormat::Json) exitWithError("JSON output is not supported for instr profiles"); - if (OFormat == OutputFormat::Yaml) + if (SFormat == ShowFormat::Yaml) exitWithError("YAML output is not supported for instr profiles"); auto ReaderOrErr = InstrProfReader::create(Filename); std::vector Cutoffs = std::move(DetailedSummaryCutoffs); @@ -2625,8 +2625,8 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts, const std::string &ShowFunction, bool ShowProfileSymbolList, bool ShowSectionInfoOnly, bool ShowHotFuncList, - OutputFormat OFormat, raw_fd_ostream &OS) { - if (OFormat == OutputFormat::Yaml) + ShowFormat SFormat, raw_fd_ostream &OS) { + if (SFormat == ShowFormat::Yaml) exitWithError("YAML output is not supported for sample profiles"); using namespace sampleprof; LLVMContext Context; @@ -2645,12 +2645,12 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts, exitWithErrorCode(EC, Filename); if (ShowAllFunctions || ShowFunction.empty()) { - if (OFormat == OutputFormat::Json) + if (SFormat == ShowFormat::Json) Reader->dumpJson(OS); else Reader->dump(OS); } else { - if (OFormat == OutputFormat::Json) + if (SFormat == ShowFormat::Json) exitWithError( "the JSON format is supported only when all functions are to " "be printed"); @@ -2679,8 +2679,8 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts, static int showMemProfProfile(const std::string &Filename, const std::string &ProfiledBinary, - OutputFormat OFormat, raw_fd_ostream &OS) { - if (OFormat == OutputFormat::Json) + ShowFormat SFormat, raw_fd_ostream &OS) { + if (SFormat == ShowFormat::Json) exitWithError("JSON output is not supported for MemProf"); auto ReaderOr = llvm::memprof::RawMemProfReader::create( Filename, ProfiledBinary, /*KeepNames=*/true); @@ -2700,13 +2700,13 @@ static int showMemProfProfile(const std::string &Filename, static int showDebugInfoCorrelation(const std::string &Filename, bool ShowDetailedSummary, bool ShowProfileSymbolList, - OutputFormat OFormat, raw_fd_ostream &OS) { - if (OFormat == OutputFormat::Json) + ShowFormat SFormat, raw_fd_ostream &OS) { + if (SFormat == ShowFormat::Json) exitWithError("JSON output is not supported for debug info correlation"); std::unique_ptr Correlator; if (auto Err = InstrProfCorrelator::get(Filename).moveInto(Correlator)) exitWithError(std::move(Err), Filename); - if (OFormat == OutputFormat::Yaml) { + if (SFormat == ShowFormat::Yaml) { if (auto Err = Correlator->dumpYaml(OS)) exitWithError(std::move(Err), Filename); return 0; @@ -2737,17 +2737,20 @@ static int show_main(int argc, const char *argv[]) { cl::opt ShowCounts("counts", cl::init(false), cl::desc("Show counter values for shown functions")); - cl::opt OFormat( - "output-format", cl::init(OutputFormat::None), + cl::opt SFormat( + "show-format", cl::init(ShowFormat::Text), cl::desc("Emit output in the selected format if supported"), - cl::values(clEnumValN(OutputFormat::Json, "json", "emit JSON"), - clEnumValN(OutputFormat::Yaml, "yaml", "emit YAML"))); + cl::values(clEnumValN(ShowFormat::Text, "text", + "emit normal text output (default)"), + clEnumValN(ShowFormat::Json, "json", "emit JSON"), + clEnumValN(ShowFormat::Yaml, "yaml", "emit YAML"))); + // TODO: Consider replacing this with `--show-format=text-encoding`. cl::opt TextFormat( "text", cl::init(false), cl::desc("Show instr profile data in text dump format")); cl::opt JsonFormat( "json", cl::desc("Show sample profile data in the JSON format " - "(deprecated, please use --output-format=json)")); + "(deprecated, please use --show-format=json)")); cl::opt ShowIndirectCallTargets( "ic-targets", cl::init(false), cl::desc("Show indirect call site target values for shown functions")); @@ -2827,7 +2830,7 @@ static int show_main(int argc, const char *argv[]) { return 1; } if (JsonFormat) - OFormat = OutputFormat::Json; + SFormat = ShowFormat::Json; std::error_code EC; raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::OF_TextWithCRLF); @@ -2839,21 +2842,21 @@ static int show_main(int argc, const char *argv[]) { if (!DebugInfoFilename.empty()) return showDebugInfoCorrelation(DebugInfoFilename, ShowDetailedSummary, - ShowProfileSymbolList, OFormat, OS); + ShowProfileSymbolList, SFormat, OS); if (ProfileKind == instr) return showInstrProfile( Filename, ShowCounts, TopNFunctions, ShowIndirectCallTargets, ShowMemOPSizes, ShowDetailedSummary, DetailedSummaryCutoffs, ShowAllFunctions, ShowCS, ValueCutoff, OnlyListBelow, ShowFunction, - TextFormat, ShowBinaryIds, ShowCovered, ShowProfileVersion, OFormat, + TextFormat, ShowBinaryIds, ShowCovered, ShowProfileVersion, SFormat, OS); if (ProfileKind == sample) return showSampleProfile(Filename, ShowCounts, TopNFunctions, ShowAllFunctions, ShowDetailedSummary, ShowFunction, ShowProfileSymbolList, - ShowSectionInfoOnly, ShowHotFuncList, OFormat, OS); - return showMemProfProfile(Filename, ProfiledBinary, OFormat, OS); + ShowSectionInfoOnly, ShowHotFuncList, SFormat, OS); + return showMemProfProfile(Filename, ProfiledBinary, SFormat, OS); } int llvm_profdata_main(int argc, char **argvNonConst) { -- 2.7.4