Lines Matching +full:build +full:- +full:metrics +full:- +full:container

1 //===- llvm-profdata.cpp - LLVM profile data tool -------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // llvm-profdata merges .profdata files.
11 //===----------------------------------------------------------------------===//
53 // https://llvm.org/docs/CommandGuide/llvm-profdata.html has documentations
59 "https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-show");
65 "https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-order");
70 "https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-overlap");
75 "https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-merge");
95 cl::init("-"), cl::desc("Output file"),
102 cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
111 cl::opt<std::string> Filename(cl::Positional, cl::desc("<profdata-file>"),
115 "max-debug-info-correlation-warnings",
120 "profiled-binary", cl::init(""),
124 "debug-info", cl::init(""),
131 BinaryFilename("binary-file", cl::init(""),
136 "debug-file-directory",
137 cl::desc("Directories to search for object files by build ID"));
143 cl::desc("Use debug-info or binary correlation to correlate profiles with "
144 "build id fetcher"),
148 clEnumValN(InstrProfCorrelator::DEBUG_INFO, "debug-info",
161 // factor out the common cl::sub in cl::opt constructor for subcommand-specific
167 cl::list<std::string> WeightedInputFilenames("weighted-input",
179 "GCC encoding (only meaningful for -sample)")));
181 InputFilenamesFile("input-files", cl::init(""), cl::sub(MergeSubcommand),
182 cl::desc("Path to file containing newline-separated "
184 cl::alias InputFilenamesFileA("f", cl::desc("Alias for --input-files"),
187 "dump-input-file-list", cl::init(false), cl::Hidden,
190 cl::opt<std::string> RemappingFile("remapping-file", cl::value_desc("file"),
193 cl::alias RemappingFileA("r", cl::desc("Alias for --remapping-file"),
196 UseMD5("use-md5", cl::init(false), cl::Hidden,
198 "meaningful for -extbinary)"),
201 "compress-all-sections", cl::init(false), cl::Hidden,
204 "meaningful for -extbinary)"));
206 "sample-merge-cold-context", cl::init(false), cl::Hidden,
211 "sample-trim-cold-context", cl::init(false), cl::Hidden,
216 "sample-frame-depth-for-cold-context", cl::init(1),
219 "context-less base profile"));
221 "output-size-limit", cl::init(0), cl::Hidden, cl::sub(MergeSubcommand),
226 "gen-partial-profile", cl::init(false), cl::Hidden,
228 cl::desc("Generate a partial profile (only meaningful for -extbinary)"));
230 "split-layout", cl::init(false), cl::Hidden,
234 "meaningful for -extbinary)"));
236 "supplement-instr-with-sample", cl::init(""), cl::Hidden,
241 "format (The flag only works with -instr)"));
243 "zero-counter-threshold", cl::init(0.7), cl::Hidden,
251 "suppl-min-size-threshold", cl::init(10), cl::Hidden,
257 "instr-prof-cold-threshold", cl::init(0), cl::Hidden,
265 "temporal-profile-trace-reservoir-size", cl::init(100),
270 "temporal-profile-max-trace-length", cl::init(10000),
275 "no-function", cl::init(""),
280 FailMode("failure-mode", cl::init(failIfAnyAreInvalid),
291 cl::desc("Generate a sparse profile (only meaningful for -instr)"));
293 "num-threads", cl::init(0), cl::sub(MergeSubcommand),
295 cl::alias NumThreadsA("j", cl::desc("Alias for --num-threads"),
299 "prof-sym-list", cl::init(""), cl::sub(MergeSubcommand),
304 "convert-sample-profile-layout",
314 "drop-profile-symbol-list", cl::init(false), cl::Hidden,
317 "(only meaningful for -sample)"));
320 "keep-vtable-symbols", cl::init(false), cl::Hidden,
327 // deployment of newer versions of llvm-profdata.
329 "write-prev-version", cl::init(false), cl::Hidden,
334 "memprof-version", cl::Hidden, cl::sub(MergeSubcommand),
341 "memprof-full-schema", cl::Hidden, cl::sub(MergeSubcommand),
345 MemprofGenerateRandomHotness("memprof-random-hotness", cl::init(false),
349 "memprof-random-hotness-seed", cl::init(0), cl::Hidden,
362 "similarity-cutoff", cl::init(0),
374 "value-cutoff", cl::init(-1),
386 SFormat("show-format", cl::init(ShowFormat::Text),
393 // TODO: Consider replacing this with `--show-format=text-encoding`.
401 "(deprecated, please use --show-format=json)"),
404 "ic-targets", cl::init(false),
407 cl::opt<bool> ShowVTables("show-vtables", cl::init(false),
411 "memop-sizes", cl::init(false),
415 cl::opt<bool> ShowDetailedSummary("detailed-summary", cl::init(false),
419 cl::CommaSeparated, "detailed-summary-cutoffs",
424 ShowHotFuncList("hot-func-list", cl::init(false),
427 cl::opt<bool> ShowAllFunctions("all-functions", cl::init(false),
444 "value-cutoff", cl::init(0),
449 "list-below-cutoff", cl::init(false),
454 "show-prof-sym-list", cl::init(false),
458 "show-sec-info-only", cl::init(false),
463 cl::opt<bool> ShowBinaryIds("binary-ids", cl::init(false),
467 "temporal-profile-traces",
476 cl::opt<bool> ShowProfileVersion("profile-version", cl::init(false),
482 NumTestTraces("num-test-traces", cl::init(0),
483 cl::desc("Keep aside the last <num-test-traces> traces in "
490 const std::string DuplicateNameStr = "----";
527 Hint = "Perhaps you forgot to use the --sample or --memory option?";
559 [&IPE](std::unique_ptr<InstrProfError> E) -> Error {
560 IPE = E->get();
593 /// Build a SymbolRemapper from a file containing a list of old/new symbols.
600 Remapper->File = std::move(BufOrError.get());
602 for (line_iterator LineIt(*Remapper->File, /*SkipBlanks=*/true, '#');
604 std::pair<StringRef, StringRef> Parts = LineIt->split(' ');
611 Remapper->RemappingTable.insert(Parts);
670 WC->Errors.emplace_back(make_error<InstrProfError>(ErrorCode, Msg),
680 WC->Writer.overlapRecord(std::move(I), Overlap, FuncOverlap, FuncFilter);
691 std::unique_lock<std::mutex> CtxGuard{WC->Lock};
707 if (Error E = WC->Writer.mergeProfileKind(Reader->getProfileKind())) {
709 WC->Errors.emplace_back(
719 WC->Errors.emplace_back(make_error<InstrProfError>(ErrorCode, Msg),
723 WC->Writer.addMemProfData(Reader->takeMemProfData(), MemProfError);
735 if (Error E = WC->Writer.mergeProfileKind(Reader->getProfileKind())) {
737 WC->Errors.emplace_back(
747 WC->Errors.emplace_back(make_error<InstrProfError>(ErrorCode, Msg),
751 auto MemProfData = Reader->takeMemProfData();
755 WC->Errors.emplace_back(
760 WC->Writer.addMemProfData(std::move(MemProfData), MemProfError);
765 // TODO: This only saves the first non-fatal error from InstrProfReader, and
767 // we have more non-fatal errors from InstrProfReader in the future. How
768 // should this interact with different -failure-mode?
789 WC->Errors.emplace_back(make_error<InstrProfError>(ErrCode, Msg),
795 if (Error E = WC->Writer.mergeProfileKind(Reader->getProfileKind())) {
797 WC->Errors.emplace_back(
810 WC->Writer.addRecord(std::move(I), Input.Weight, [&](Error E) {
818 std::unique_lock<std::mutex> ErrGuard{WC->ErrLock};
819 bool firstTime = WC->WriterErrorCodes.insert(ErrCode).second;
826 const InstrProfSymtab &symtab = Reader->getSymtab();
830 WC->Writer.addVTableName(kv.getKey());
833 if (Reader->hasTemporalProfile()) {
834 auto &Traces = Reader->getTemporalProfTraces(Input.Weight);
836 WC->Writer.addTemporalProfileTraces(
837 Traces, Reader->getTemporalProfTraceStreamSize());
839 if (Reader->hasError()) {
840 if (Error E = Reader->getError()) {
841 WC->Errors.emplace_back(std::move(E), Filename);
847 if (Error E = Reader->readBinaryIds(BinaryIds)) {
848 WC->Errors.emplace_back(std::move(E), Filename);
851 WC->Writer.addBinaryIds(BinaryIds);
854 WC->Errors.emplace_back(std::move(ReaderWarning->first),
855 ReaderWarning->second);
861 for (auto &ErrorPair : Src->Errors)
862 Dst->Errors.push_back(std::move(ErrorPair));
863 Src->Errors.clear();
865 if (Error E = Dst->Writer.mergeProfileKind(Src->Writer.getProfileKind()))
868 Dst->Writer.mergeRecordsFromWriter(std::move(Src->Writer), [&](Error E) {
870 std::unique_lock<std::mutex> ErrGuard{Dst->ErrLock};
871 bool firstTime = Dst->WriterErrorCodes.insert(ErrorCode).second;
895 llvm::Regex ProbablyMSVCMangledName("[?@$_0-9A-Za-z]+");
929 llvm::dbgs() << Count - ProfileMap.size() << " of " << Count << " functions "
948 exitWithError("cannot write a non-text format profile to the terminal");
967 // correlation modes(w/wo debug-info/object correlation).
970 exitWithError("Expected only one of -binary-file, -debuginfod or "
971 "-debug-file-directory");
974 exitWithError("Expected only one of -debug-info, -binary-file, -debuginfod "
975 "or -debug-file-directory");
992 if (auto Err = Correlator->correlateProfileData(MaxDbgCorrelationWarnings))
1002 exitWithError("Expected --correlate when --debuginfod is provided");
1007 exitWithError("Expected --correlate when --debug-file-directory "
1011 exitWithError("Expected --debuginfod or --debug-file-directory when "
1012 "--correlate is provided");
1018 // If NumThreads is not specified, auto-detect a good default.
1058 Contexts[End - 1].get());
1070 for (auto &ErrorPair : WC->Errors) {
1079 filterFunctions(Contexts[0]->Writer.getProfileData());
1081 writeInstrProfile(OutputFilename, OutputFormat, Contexts[0]->Writer);
1096 uint64_t CntNum = Record->Counts.size();
1099 MaxCount = std::max(MaxCount, Record->Counts[I]);
1100 ZeroCntNum += !Record->Counts[I];
1107 /// -1 / -2 /in order to drop the profile or scale up the
1120 // counters to be -1 / -2 and PGO profile-use will drop the profile.
1121 // All counters being -1 also implies that the function is hot so
1122 // PGO profile-use will also set the entry count metadata to be
1124 // All counters being -2 implies that the function is warm so
1125 // PGO profile-use will also set the entry count metadata to be
1129 ProfRecord->setPseudoCount(Kind);
1146 ProfRecord->scale(Numerator, Denominator, [&](instrprof_error E) {
1159 "fs-discriminator-pass", cl::init(PassLast), cl::Hidden,
1165 clEnumVal(Pass2, "Use base and pass 1-2 discriminators"),
1166 clEnumVal(Pass3, "Use base and pass 1-3 discriminators"),
1186 for (const auto &PD : Reader->getProfiles()) {
1216 StringRef FName = Name.substr(0, PrefixPos - 1);
1228 // If instrumented profile uses -funique-internal-linkage-symbols,
1233 // If sample profile uses -funique-internal-linkage-symbols,
1234 // we build the map.
1245 It->second = DuplicateNameStr;
1250 // One caveat is the pre-inlined function -- their samples
1256 // name = FS->getName();
1307 auto &BuildImpl) -> void {
1320 It = InstrProfileMap.find(NewName->second);
1321 if (NewName->second != DuplicateNameStr) {
1322 NewRootName = &NewName->second;
1343 for (auto &PD : WC->Writer.getProfileData()) {
1355 InstrProfRecord *R = &PD.getValue().begin()->second;
1361 for (auto &PD : Reader->getProfiles()) {
1368 ProfileSummary SamplePS = Reader->getSummary();
1405 It = InstrProfileMap.find(NewName->second);
1406 if (NewName->second == DuplicateNameStr) {
1414 It->second.MaxCount > ColdInstrThreshold ||
1415 It->second.NumEdgeCounters < SupplMinSizeThreshold)
1418 updateInstrProfileEntry(It->second, SetToHot, HotInstrThreshold,
1439 if (OutputFilename == "-")
1456 if (std::error_code EC = Reader->read())
1465 if (WC->Errors.size() > 0)
1466 exitWithError(std::move(WC->Errors[0].first), InstrFilename);
1470 writeInstrProfile(OutputFilename, OutputFormat, WC->Writer);
1532 StringRef Data = Buffer->getBuffer();
1533 Data.split(SymbolVec, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
1547 warn("-split-layout is ignored. Specify -extbinary to enable it");
1561 warn("-compress-all-section is ignored. Specify -extbinary to enable it");
1567 warn("-use-md5 is ignored. Specify -extbinary to enable it");
1573 warn("-gen-partial-profile is ignored. Specify -extbinary to enable it");
1605 if (std::error_code EC = Reader->read()) {
1611 SampleProfileMap &Profiles = Reader->getProfiles();
1615 "cannot merge probe-based profile with non-probe-based profile");
1618 exitWithError("cannot merge CS profile with non-CS profile");
1624 Remapper ? remapSamples(I->second, *Remapper, Result)
1626 FunctionSamples &Samples = Remapper ? Remapped : I->second;
1639 Reader->getProfileSymbolList();
1651 (Summary->getDetailedSummary()));
1685 Writer->writeWithSizeLimit(ProfileMap, OutputSizeLimit))
1705 if (Filename == "-") {
1725 if (llvm::sys::fs::is_regular_file(F->path())) {
1726 addWeightedInput(WNI, {F->path(), Weight});
1740 StringRef Data = Buffer->getBuffer();
1741 Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
1768 exitWithError("no input files specified. See " + ProgName + " merge -help");
1783 "-supplement-instr-with-sample can only work with -instr. ");
1896 /// container iterators at the current step. If the previous status is
1908 // Current iterator and end iterator of the first container.
1911 // Current iterator and end iterator of the second container.
1939 (SecondIter == SecondEnd || FirstIter->first < SecondIter->first))
1942 (FirstIter == FirstEnd || SecondIter->first < FirstIter->first))
1988 /// Detect 0-sample input profile and report to output stream. This interface
1992 /// Write out function-level similarity statistics for functions specified by
1993 /// options --function, --value-cutoff, and --similarity-cutoff.
1996 /// Write out program-level similarity and overlap statistics.
1999 /// Write out hot-function and hot-block statistics for base_profile,
2008 /// pair of matched functions, it aggregates the function-level
2009 /// similarity into a profile-level similarity. It also dump function-level
2010 /// similarity information of functions specified by --function,
2011 /// --value-cutoff, and --similarity-cutoff options. The program-level
2013 /// Given function-level similarity FS(A) for all function A, the
2017 /// meaning no-overlap.
2023 /// use to avoid re-computations.
2055 // FuncFilter carries specifications in options --value-cutoff and
2056 // --function.
2058 // Column offsets for printing the function-level details table.
2069 /// function in base and test profiles. The line/block-similarity BS(i) is
2074 /// this function in test profile ST, compute BS(i) = 1.0 - fabs(BB(i)/SB -
2075 /// BT(i)/ST), ranging in [0.0f to 1.0f] with 0.0 meaning no-overlap.
2104 /// base and test profile. It also calculates a function-internal similarity
2108 /// FIS(A) = (2.0 - sum_i(1.0 - BS(i))) / 2, ranging in [0.0f to 1.0f] with
2115 /// Function-level similarity (FS) is a weighted value over function internal
2121 /// The function-level similarity FS(A) for a function A is computed as
2123 /// Compute a function-internal similarity FIS(A) by
2126 /// profile WT(A), compute FS(A) = FIS(A) * (1.0 - fabs(WB(A) - WT(A)))
2135 /// Profile-level similarity (PS) is a weighted aggregate over function-level
2166 return 1.0 - std::fabs(BaseFrac - TestFrac);
2231 1.0 - computeBlockSimilarity(BaseSample, TestSample, FuncOverlap);
2264 // We match them through sort-merge join algorithm because
2275 : BlockIterStep.getFirstIter()->second.getSamples();
2279 : BlockIterStep.getSecondIter()->second.getSamples();
2287 // them through sort-merge algorithm because
2305 for (const auto &F : Callsite->second)
2310 // matching all of them. This match is implemented through sort-merge
2314 CallsiteIterStep.getFirstIter()->second.cbegin(),
2315 CallsiteIterStep.getFirstIter()->second.cend(),
2316 CallsiteIterStep.getSecondIter()->second.cbegin(),
2317 CallsiteIterStep.getSecondIter()->second.cend());
2325 updateForUnmatchedCallee(Callee->second, FuncOverlap, Difference,
2330 Difference += 2.0 - 2 * computeSampleFunctionInternalOverlap(
2331 CalleeIterStep.getFirstIter()->second,
2332 CalleeIterStep.getSecondIter()->second,
2342 // function and ranges in [0.0f to 2.0f]. Take (2.0 - Difference) / 2 to
2344 return (2.0 - Difference) / 2;
2360 double WeightDistance = std::fabs(BaseFrac - TestFrac);
2363 return FuncInternalSimilarity * (1 - WeightDistance);
2406 FuncInternalSimilarity = (std::fabs(FuncInternalSimilarity - 0) < Epsilon)
2421 const auto &BaseProfiles = BaseReader->getProfiles();
2427 const auto &TestProfiles = TestReader->getProfiles();
2456 // Two functions match with each other. Compute function-level overlap and
2457 // aggregate them into profile-level overlap.
2458 FuncOverlap.BaseName = Match->second->getContext();
2465 Match->second, &TestFunc.second, &FuncOverlap, FuncOverlap.BaseSample,
2484 // Print function-level similarity information if specified by options.
2507 assert(BaseStats.count(F.second->getContext()) &&
2510 const FuncSampleStats &FuncStats = BaseStats[F.second->getContext()];
2527 ProfOverlap.Similarity = (std::fabs(ProfOverlap.Similarity - 1) < Epsilon)
2535 const auto &BaseProf = BaseReader->getProfiles();
2544 const auto &TestProf = TestReader->getProfiles();
2564 FOS << "Function-level details:\n";
2666 OS << " Hot-function overlap: "
2672 << HotFuncOverlap.BaseCount - HotFuncOverlap.OverlapCount << "\n";
2674 << HotFuncOverlap.TestCount - HotFuncOverlap.OverlapCount << "\n";
2678 OS << " Hot-block overlap: "
2684 << HotBlockOverlap.BaseCount - HotBlockOverlap.OverlapCount << "\n";
2686 << HotBlockOverlap.TestCount - HotBlockOverlap.OverlapCount << "\n";
2707 if (std::error_code EC = BaseReader->read())
2709 if (std::error_code EC = TestReader->read())
2711 if (BaseReader->profileIsProbeBased() != TestReader->profileIsProbeBased())
2713 "cannot compare probe-based profile with non-probe-based profile");
2714 if (BaseReader->profileIsCS() != TestReader->profileIsCS())
2715 exitWithError("cannot compare CS profile with non-CS profile");
2717 // Load BaseHotThreshold and TestHotThreshold as 99-percentile threshold in
2719 ProfileSummary &BasePS = BaseReader->getSummary();
2720 ProfileSummary &TestPS = TestReader->getSummary();
2735 // We use 0.000005 to initialize OverlapAggr.Epsilon because the final metrics
2736 // report 2--3 places after decimal point in percentage numbers.
2796 Stats.ValueSitesHistogram[NV - 1]++;
2809 OS << Symtab->getFuncOrVarName(V.Value);
2846 bool IsIRInstr = Reader->isIRLevelProfile();
2849 int NumVPKind = IPVK_Last - IPVK_First + 1;
2867 // Add marker so that IR-level instrumentation round-trips properly.
2872 if (Reader->isIRLevelProfile()) {
2883 InstrProfSymtab &Symtab = Reader->getSymtab();
2983 &(Reader->getSymtab()));
2990 &(Reader->getSymtab()));
3000 if (Reader->hasError())
3001 exitWithError(Reader->getError(), Filename);
3006 bool IsIR = Reader->isIRLevelProfile();
3007 OS << "Instrumentation level: " << (IsIR ? "IR" : "Front-end");
3009 OS << " entry_first = " << Reader->instrEntryBBEnabled();
3010 OS << " instrument_loop_entries = " << Reader->instrLoopEntriesEnabled();
3015 PS->printSummary(OS);
3020 << "): " << PS->getNumFunctions() - BelowCutoffFunctions << "\n";
3052 PS->printDetailedSummary(OS);
3055 if (Error E = Reader->printBinaryIds(OS))
3059 OS << "Profile version: " << Reader->getVersion() << "\n";
3062 auto &Traces = Reader->getTemporalProfTraces();
3064 << " seen=" << Reader->getTemporalProfTraceStreamSize() << "):\n";
3069 OS << " " << Reader->getSymtab().getFuncOrVarName(NameRef) << "\n";
3078 if (!Reader->dumpSectionInfo(OS)) {
3079 WithColor::warning() << "-show-sec-info-only is only supported for "
3237 if (std::error_code EC = Reader->read())
3242 Reader->dumpJson(OS);
3244 Reader->dump(OS);
3252 FunctionSamples *FS = Reader->getSamplesFor(StringRef(FuncNameFilter));
3253 Reader->dumpFunctionProfile(FS ? *FS : FunctionSamples(), OS);
3258 Reader->getProfileSymbolList();
3259 ReaderList->dump(OS);
3263 auto &PS = Reader->getSummary();
3269 showHotFunctionList(Reader->getProfiles(), Reader->getSummary(),
3293 Reader->printYAML(OS);
3304 memprof::AllMemProfData Data = Reader->getAllMemProfData();
3323 if (auto Err = Correlator->dumpYaml(MaxDbgCorrelationWarnings, OS))
3328 if (auto Err = Correlator->correlateProfileData(MaxDbgCorrelationWarnings))
3333 StringRef(Correlator->getNamesPointer(), Correlator->getNamesSize())))
3342 << Twine::utohexstr(Correlator->getCountersSectionSize()) << " bytes\n";
3343 OS << "Found " << Correlator->getDataSize() << " functions\n";
3351 "the positional argument '<profdata-file>' is required unless '--" +
3369 WithColor::warning() << "-function argument ignored: showing all functions\n";
3396 ArrayRef Traces = Reader->getTemporalProfTraces();
3399 "--" + NumTestTraces.ArgStr +
3425 TouchedPages.insert(It->getSecond());
3432 OS << "# Warning: Mach-O may prefix symbols with \"_\" depending on the "
3434 "post-processing may be required before passing to the linker via "
3435 "-order_file.\n";
3438 getParsedIRPGOName(Reader->getSymtab().getFuncOrVarName(N.Id));
3455 << ": No subcommand specified! Run llvm-profdata --help for usage.\n";
3474 << ": Unknown command. Run llvm-profdata --help for usage.\n";