Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

57 changes: 0 additions & 57 deletions llvm/test/tools/llvm-profgen/filter-build-id.test

This file was deleted.

71 changes: 13 additions & 58 deletions llvm/tools/llvm-profgen/PerfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ cl::opt<bool> TimeProfGen("time-profgen", cl::desc("Time llvm-profgen phases"),
static const char *TimerGroupName = "profgen";
static const char *TimerGroupDesc = "llvm-profgen";

static cl::opt<std::string> FilterBuildID(
"filter-build-id",
cl::desc("Override auto-detected build ID for filtering perfscript "
"addresses in [buildid:]addr format. When set, only addresses "
"with a matching build ID prefix are kept."),
cl::cat(ProfGenCategory));

namespace sampleprof {

void VirtualUnwinder::unwindCall(UnwindState &State) {
Expand Down Expand Up @@ -672,37 +665,12 @@ void HybridPerfReader::unwindSamples() {
}

/// Parse a hex address from \p Str.
/// Parse an optional [buildid:] prefix into \p BuildID.
static bool parseAddress(StringRef Str, uint64_t &Addr, bool HasPrefix,
StringRef &BuildID) {
size_t ColonPos = Str.find(':');
if (ColonPos != StringRef::npos) {
BuildID = Str.substr(0, ColonPos);
Str = Str.substr(ColonPos + 1);
}
static bool parseAddress(StringRef Str, uint64_t &Addr, bool HasPrefix) {
if (Str.consume_front("0x") != HasPrefix)
return true;
return Str.getAsInteger(16, Addr);
}

/// Return the build ID to use for filtering perfscript addresses.
/// If --filter-build-id is specified, use it as an override (with a warning
/// if it doesn't match the binary's auto-detected build ID).
/// Otherwise, use the auto-detected value from the binary.
static StringRef getFilterBuildID(const ProfiledBinary *Binary) {
StringRef BinaryBuildID = Binary->getFilterBuildID();
if (FilterBuildID.getNumOccurrences() == 0)
return BinaryBuildID;
static bool Warned = false;
if (!Warned && !BinaryBuildID.empty() && FilterBuildID != BinaryBuildID) {
WithColor::warning() << "--filter-build-id=" << FilterBuildID
<< " does not match binary build ID " << BinaryBuildID
<< "\n";
Warned = true;
}
return FilterBuildID;
}

bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
SmallVectorImpl<LBREntry> &LBRStack) {
// The raw format of LBR stack is like:
Expand All @@ -720,9 +688,8 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
// Skip the leading instruction pointer.
size_t Index = 0;
uint64_t LeadingAddr;
StringRef LeadingBuildID;
if (!Records.empty() && !Records[0].contains('/')) {
if (parseAddress(Records[0], LeadingAddr, false, LeadingBuildID)) {
if (parseAddress(Records[0], LeadingAddr, false)) {
WarnInvalidLBR(TraceIt);
TraceIt.advance();
return false;
Expand All @@ -742,25 +709,19 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
Token.split(Addresses, "/");
uint64_t Src;
uint64_t Dst;
StringRef SrcBuildID, DstBuildID;

// Stop at broken LBR records.
if (Addresses.size() < 2 ||
parseAddress(Addresses[0], Src, true, SrcBuildID) ||
parseAddress(Addresses[1], Dst, true, DstBuildID)) {
if (Addresses.size() < 2 || parseAddress(Addresses[0], Src, true) ||
parseAddress(Addresses[1], Dst, true)) {
WarnInvalidLBR(TraceIt);
break;
}

// Canonicalize to use preferred load address as base address.
Src = Binary->canonicalizeVirtualAddress(Src);
Dst = Binary->canonicalizeVirtualAddress(Dst);
// Filter by build ID.
StringRef BinaryBuildID = getFilterBuildID(Binary);
bool SrcIsInternal =
SrcBuildID == BinaryBuildID && Binary->addressIsCode(Src);
bool DstIsInternal =
DstBuildID == BinaryBuildID && Binary->addressIsCode(Dst);
bool SrcIsInternal = Binary->addressIsCode(Src);
bool DstIsInternal = Binary->addressIsCode(Dst);
if (!SrcIsInternal)
Src = ExternalAddr;
if (!DstIsInternal)
Expand All @@ -778,17 +739,16 @@ bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
SmallVectorImpl<uint64_t> &CallStack) {
// The raw format of call stack is like:
// 4005dc # leaf frame (no buildid)
// 4005dc # leaf frame
// 400634
// deadbeef:400684 # root frame (with buildid prefix)
// 400684 # root frame
// It's in bottom-up order with each frame in one line.

// Extract stack frames from sample
while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
uint64_t FrameAddr = 0;
StringRef FrameBuildID;
if (parseAddress(FrameStr, FrameAddr, false, FrameBuildID)) {
if (parseAddress(FrameStr, FrameAddr, false)) {
// We might parse a non-perf sample line like empty line and comments,
// skip it
TraceIt.advance();
Expand All @@ -798,9 +758,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,

FrameAddr = Binary->canonicalizeVirtualAddress(FrameAddr);
// Currently intermixed frame from different binaries is not supported.
bool IsExternal = FrameBuildID != getFilterBuildID(Binary) ||
!Binary->addressIsCode(FrameAddr);
if (IsExternal) {
if (!Binary->addressIsCode(FrameAddr)) {
if (CallStack.empty())
NumLeafExternalFrame++;
// Push a special value(ExternalAddr) for the external frames so that
Expand Down Expand Up @@ -1213,7 +1171,7 @@ void PerfScriptReader::parseAndAggregateTrace() {
// A LBR sample is like:
// 40062f 0x5c6313f/0x5c63170/P/-/-/0 0x5c630e7/0x5c63130/P/-/-/0 ...
// A heuristic for fast detection by checking whether a
// leading " 0x" or " buildid:0x" and the '/' exist.
// leading " 0x" and the '/' exist.
bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
// Skip the leading instruction pointer
SmallVector<StringRef, 32> Records;
Expand All @@ -1222,8 +1180,7 @@ bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
Line.split(Records, " ", 2, CheckLineStart);
if (Records.size() < 2)
return false;
if ((Records[1].starts_with("0x") || Records[1].contains(":0x")) &&
Records[1].contains('/'))
if (Records[1].starts_with("0x") && Records[1].contains('/'))
return true;
return false;
}
Expand Down Expand Up @@ -1261,10 +1218,8 @@ PerfContent PerfScriptReader::checkPerfScriptType(StringRef FileName) {

// Detect sample with call stack
int32_t Count = 0;
StringRef FrameBuildId;
while (!TraceIt.isAtEoF() &&
!parseAddress(TraceIt.getCurrentLine().ltrim(), FrameAddr, false,
FrameBuildId)) {
!parseAddress(TraceIt.getCurrentLine().ltrim(), FrameAddr, false)) {
Count++;
TraceIt.advance();
}
Expand Down