diff options
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r-- | llvm/tools/llvm-profdata/llvm-profdata.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 3af8f80..e392128 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -2488,7 +2488,7 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts, const std::string &ShowFunction, bool ShowProfileSymbolList, bool ShowSectionInfoOnly, bool ShowHotFuncList, - raw_fd_ostream &OS) { + bool JsonFormat, raw_fd_ostream &OS) { using namespace sampleprof; LLVMContext Context; auto ReaderOrErr = @@ -2505,11 +2505,20 @@ static int showSampleProfile(const std::string &Filename, bool ShowCounts, if (std::error_code EC = Reader->read()) exitWithErrorCode(EC, Filename); - if (ShowAllFunctions || ShowFunction.empty()) - Reader->dump(OS); - else + if (ShowAllFunctions || ShowFunction.empty()) { + if (JsonFormat) + Reader->dumpJson(OS); + else + Reader->dump(OS); + } else { + if (JsonFormat) + exitWithError( + "the JSON format is supported only when all functions are to " + "be printed"); + // TODO: parse context string to support filtering by contexts. Reader->dumpFunctionProfile(StringRef(ShowFunction), OS); + } if (ShowProfileSymbolList) { std::unique_ptr<sampleprof::ProfileSymbolList> ReaderList = @@ -2582,6 +2591,9 @@ static int show_main(int argc, const char *argv[]) { cl::opt<bool> TextFormat( "text", cl::init(false), cl::desc("Show instr profile data in text dump format")); + cl::opt<bool> JsonFormat( + "json", cl::init(false), + cl::desc("Show sample profile data in the JSON format")); cl::opt<bool> ShowIndirectCallTargets( "ic-targets", cl::init(false), cl::desc("Show indirect call site target values for shown functions")); @@ -2679,10 +2691,10 @@ static int show_main(int argc, const char *argv[]) { ShowAllFunctions, ShowCS, ValueCutoff, OnlyListBelow, ShowFunction, TextFormat, ShowBinaryIds, ShowCovered, OS); if (ProfileKind == sample) - return showSampleProfile(Filename, ShowCounts, TopNFunctions, - ShowAllFunctions, ShowDetailedSummary, - ShowFunction, ShowProfileSymbolList, - ShowSectionInfoOnly, ShowHotFuncList, OS); + return showSampleProfile( + Filename, ShowCounts, TopNFunctions, ShowAllFunctions, + ShowDetailedSummary, ShowFunction, ShowProfileSymbolList, + ShowSectionInfoOnly, ShowHotFuncList, JsonFormat, OS); return showMemProfProfile(Filename, ProfiledBinary, OS); } |