diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h --- a/llvm/tools/llvm-profgen/PerfReader.h +++ b/llvm/tools/llvm-profgen/PerfReader.h @@ -13,6 +13,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Regex.h" +#include #include #include #include @@ -411,13 +412,8 @@ // Callsite merging may cause the loss of original probe IDs. // Cutting off the context from here since the inliner will // not know how to consume a context with unknown callsites. - if (!CallProbe) { - if (!Cur->isLeafFrame()) - WithColor::warning() - << "Untracked frame at " << format("%" PRIx64, Cur->Address) - << " due to missing call probe\n"; + if (!CallProbe) return false; - } Stack.push_back(CallProbe); return true; } @@ -464,6 +460,7 @@ VirtualUnwinder(ContextSampleCounterMap *Counter, const ProfiledBinary *B) : CtxCounterMap(Counter), Binary(B) {} bool unwind(const PerfSample *Sample, uint64_t Repeat); + std::set &getUntrackedCallsites() { return UntrackedCallsites; } private: bool isCallState(UnwindState &State) const { @@ -498,6 +495,8 @@ ContextSampleCounterMap *CtxCounterMap; // Profiled binary that current frame address belongs to const ProfiledBinary *Binary; + // Keep track of all untracked callsites + std::set UntrackedCallsites; }; // Read perf trace to parse the events and samples. diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -153,6 +153,12 @@ for (const auto &Item : Cur->Children) { collectSamplesFromFrameTrie(Item.second.get(), EmptyStack); } + + // Keep note of untracked call site and deduplicate them + // for warning later. + if (!Cur->isLeafFrame()) + UntrackedCallsites.insert(Cur->Address); + return; } } @@ -368,12 +374,22 @@ } void HybridPerfReader::unwindSamples() { + std::set AllUntrackedCallsites; for (const auto &Item : AggregatedSamples) { const PerfSample *Sample = Item.first.getPtr(); VirtualUnwinder Unwinder(&SampleCounters, Binary); Unwinder.unwind(Sample, Item.second); + auto &CurrUntrackedCallsites = Unwinder.getUntrackedCallsites(); + AllUntrackedCallsites.insert(CurrUntrackedCallsites.begin(), + CurrUntrackedCallsites.end()); } + // Warn about untracked frames due to missing probes. + for (auto Address : AllUntrackedCallsites) + WithColor::warning() << "Profile context truncated due to missing probe " + << "for call instructions at " + << format("%" PRIx64, Address) << "\n"; + if (SkipSymbolization) PerfReaderBase::writeRawProfile(OutputFilename); }