diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-01-27 22:06:42 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-01-27 22:06:42 +0000 |
| commit | 6f8fc217eaa12bf657be1c6468ed9938d10168b3 (patch) | |
| tree | a1fd89b864d9b93e2ad68fe1dcf7afee2e3c8d76 /llvm/tools/llvm-profdata/llvm-profdata.cpp | |
| parent | 77fc4c146f0870ffb09c1afb823ccbe742c5e6ff (diff) | |
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
| -rw-r--r-- | llvm/tools/llvm-profdata/llvm-profdata.cpp | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 285b41f57147..5e58c1365d80 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -204,8 +204,8 @@ struct WriterContext { WriterContext(bool IsSparse, std::mutex &ErrLock, SmallSet<instrprof_error, 4> &WriterErrorCodes) - : Lock(), Writer(IsSparse), Errors(), ErrLock(ErrLock), - WriterErrorCodes(WriterErrorCodes) {} + : Writer(IsSparse), ErrLock(ErrLock), WriterErrorCodes(WriterErrorCodes) { + } }; /// Computer the overlap b/w profile BaseFilename and TestFileName, @@ -661,8 +661,8 @@ static void populateProfileSymbolList(MemoryBuffer *Buffer, StringRef Data = Buffer->getBuffer(); Data.split(SymbolVec, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false); - for (StringRef symbol : SymbolVec) - PSL.add(symbol); + for (StringRef SymbolStr : SymbolVec) + PSL.add(SymbolStr.trim()); } static void handleExtBinaryWriter(sampleprof::SampleProfileWriter &Writer, @@ -968,7 +968,7 @@ static int merge_main(int argc, const char *argv[]) { "gen-cs-nested-profile", cl::Hidden, cl::init(false), cl::desc("Generate nested function profiles for CSSPGO")); cl::opt<std::string> DebugInfoFilename( - "debug-info", cl::init(""), cl::Hidden, + "debug-info", cl::init(""), cl::desc("Use the provided debug info to correlate the raw profile.")); cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n"); @@ -2303,8 +2303,7 @@ struct HotFuncInfo { uint64_t EntryCount; HotFuncInfo() - : FuncName(), TotalCount(0), TotalCountPercent(0.0f), MaxCount(0), - EntryCount(0) {} + : TotalCount(0), TotalCountPercent(0.0f), MaxCount(0), EntryCount(0) {} HotFuncInfo(StringRef FN, uint64_t TS, double TSP, uint64_t MS, uint64_t ES) : FuncName(FN.begin(), FN.end()), TotalCount(TS), TotalCountPercent(TSP), @@ -2487,9 +2486,35 @@ static int showMemProfProfile(const std::string &Filename, raw_fd_ostream &OS) { return 0; } +static int showDebugInfoCorrelation(const std::string &Filename, + bool ShowDetailedSummary, + bool ShowProfileSymbolList, + raw_fd_ostream &OS) { + std::unique_ptr<InstrProfCorrelator> Correlator; + if (auto Err = InstrProfCorrelator::get(Filename).moveInto(Correlator)) + exitWithError(std::move(Err), Filename); + if (auto Err = Correlator->correlateProfileData()) + exitWithError(std::move(Err), Filename); + + InstrProfSymtab Symtab; + if (auto Err = Symtab.create( + StringRef(Correlator->getNamesPointer(), Correlator->getNamesSize()))) + exitWithError(std::move(Err), Filename); + + if (ShowProfileSymbolList) + Symtab.dumpNames(OS); + // TODO: Read "Profile Data Type" from debug info to compute and show how many + // counters the section holds. + if (ShowDetailedSummary) + OS << "Counters section size: 0x" + << Twine::utohexstr(Correlator->getCountersSectionSize()) << " bytes\n"; + OS << "Found " << Correlator->getDataSize() << " functions\n"; + + return 0; +} + static int show_main(int argc, const char *argv[]) { - cl::opt<std::string> Filename(cl::Positional, cl::Required, - cl::desc("<profdata-file>")); + cl::opt<std::string> Filename(cl::Positional, cl::desc("<profdata-file>")); cl::opt<bool> ShowCounts("counts", cl::init(false), cl::desc("Show counter values for shown functions")); @@ -2550,9 +2575,18 @@ static int show_main(int argc, const char *argv[]) { "extbinary format")); cl::opt<bool> ShowBinaryIds("binary-ids", cl::init(false), cl::desc("Show binary ids in the profile. ")); + cl::opt<std::string> DebugInfoFilename( + "debug-info", cl::init(""), + cl::desc("Read and extract profile metadata from debug info and show " + "the functions it found.")); cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n"); + if (Filename.empty() && DebugInfoFilename.empty()) + exitWithError( + "the positional argument '<profdata-file>' is required unless '--" + + DebugInfoFilename.ArgStr + "' is provided"); + if (Filename == OutputFilename) { errs() << sys::path::filename(argv[0]) << ": Input file name cannot be the same as the output file name!\n"; @@ -2567,6 +2601,10 @@ static int show_main(int argc, const char *argv[]) { if (ShowAllFunctions && !ShowFunction.empty()) WithColor::warning() << "-function argument ignored: showing all functions\n"; + if (!DebugInfoFilename.empty()) + return showDebugInfoCorrelation(DebugInfoFilename, ShowDetailedSummary, + ShowProfileSymbolList, OS); + if (ProfileKind == instr) return showInstrProfile( Filename, ShowCounts, TopNFunctions, ShowIndirectCallTargets, |
