Skip to content

Commit 606a715

Browse files
WenleiHememfrob
authored andcommitted
[llvm-profgen] Deduplicate and improve warning for truncated context
This change improves the warning for truncated context by: 1) deduplicate them as one call without probe can appear in many different context leading to duplicated warnings , 2) rephrase the message to make it easier to understand. The term "untracked frame" can be confusing. Differential Revision: https://reviews.llvm.org/D109115
1 parent 7ed7853 commit 606a715

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

llvm/tools/llvm-profgen/PerfReader.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ void VirtualUnwinder::collectSamplesFromFrameTrie(
153153
for (const auto &Item : Cur->Children) {
154154
collectSamplesFromFrameTrie(Item.second.get(), EmptyStack);
155155
}
156+
157+
// Keep note of untracked call site and deduplicate them
158+
// for warning later.
159+
if (!Cur->isLeafFrame())
160+
UntrackedCallsites.insert(Cur->Address);
161+
156162
return;
157163
}
158164
}
@@ -368,12 +374,22 @@ void HybridPerfReader::writeRawProfile(raw_fd_ostream &OS) {
368374
}
369375

370376
void HybridPerfReader::unwindSamples() {
377+
std::set<uint64_t> AllUntrackedCallsites;
371378
for (const auto &Item : AggregatedSamples) {
372379
const PerfSample *Sample = Item.first.getPtr();
373380
VirtualUnwinder Unwinder(&SampleCounters, Binary);
374381
Unwinder.unwind(Sample, Item.second);
382+
auto &CurrUntrackedCallsites = Unwinder.getUntrackedCallsites();
383+
AllUntrackedCallsites.insert(CurrUntrackedCallsites.begin(),
384+
CurrUntrackedCallsites.end());
375385
}
376386

387+
// Warn about untracked frames due to missing probes.
388+
for (auto Address : AllUntrackedCallsites)
389+
WithColor::warning() << "Profile context truncated due to missing probe "
390+
<< "for call instruction at "
391+
<< format("%" PRIx64, Address) << "\n";
392+
377393
if (SkipSymbolization)
378394
PerfReaderBase::writeRawProfile(OutputFilename);
379395
}

llvm/tools/llvm-profgen/PerfReader.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/Support/Casting.h"
1414
#include "llvm/Support/CommandLine.h"
1515
#include "llvm/Support/Regex.h"
16+
#include <cstdint>
1617
#include <fstream>
1718
#include <list>
1819
#include <map>
@@ -411,13 +412,8 @@ struct ProbeStack {
411412
// Callsite merging may cause the loss of original probe IDs.
412413
// Cutting off the context from here since the inliner will
413414
// not know how to consume a context with unknown callsites.
414-
if (!CallProbe) {
415-
if (!Cur->isLeafFrame())
416-
WithColor::warning()
417-
<< "Untracked frame at " << format("%" PRIx64, Cur->Address)
418-
<< " due to missing call probe\n";
415+
if (!CallProbe)
419416
return false;
420-
}
421417
Stack.push_back(CallProbe);
422418
return true;
423419
}
@@ -464,6 +460,7 @@ class VirtualUnwinder {
464460
VirtualUnwinder(ContextSampleCounterMap *Counter, const ProfiledBinary *B)
465461
: CtxCounterMap(Counter), Binary(B) {}
466462
bool unwind(const PerfSample *Sample, uint64_t Repeat);
463+
std::set<uint64_t> &getUntrackedCallsites() { return UntrackedCallsites; }
467464

468465
private:
469466
bool isCallState(UnwindState &State) const {
@@ -498,6 +495,8 @@ class VirtualUnwinder {
498495
ContextSampleCounterMap *CtxCounterMap;
499496
// Profiled binary that current frame address belongs to
500497
const ProfiledBinary *Binary;
498+
// Keep track of all untracked callsites
499+
std::set<uint64_t> UntrackedCallsites;
501500
};
502501

503502
// Read perf trace to parse the events and samples.

0 commit comments

Comments
 (0)