Unverified Commit 45b11953 authored by Amir Ayupov's avatar Amir Ayupov Committed by GitHub
Browse files

[llvm-profgen][NFC] Reuse isLBRSample (#191595)

Replace `StringRef::starts_with(" 0x")` calls with explicit
`isLBRSample` checks.
This is needed to support buildid-prefixed addresses in a follow-up
#190863.
parent f089c0fe
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -745,7 +745,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
  // It's in bottom-up order with each frame in one line.

  // Extract stack frames from sample
  while (!TraceIt.isAtEoF() && !TraceIt.getCurrentLine().starts_with(" 0x")) {
  while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
    StringRef FrameStr = TraceIt.getCurrentLine().ltrim();
    uint64_t FrameAddr = 0;
    if (parseAddress(FrameStr, FrameAddr, false)) {
@@ -793,7 +793,7 @@ bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
  // Skip other unrelated line, find the next valid LBR line
  // Note that even for empty call stack, we should skip the address at the
  // bottom, otherwise the following pass may generate a truncated callstack
  while (!TraceIt.isAtEoF() && !TraceIt.getCurrentLine().starts_with(" 0x")) {
  while (!TraceIt.isAtEoF() && !isLBRSample(TraceIt.getCurrentLine(), true)) {
    TraceIt.advance();
  }
  // Filter out broken stack sample. We may not have complete frame info
@@ -838,14 +838,14 @@ void HybridPerfReader::parseSample(TraceStream &TraceIt, uint64_t Count) {
  // Parsing call stack and populate into PerfSample.CallStack
  if (!extractCallstack(TraceIt, Sample->CallStack)) {
    // Skip the next LBR line matched current call stack
    if (!TraceIt.isAtEoF() && TraceIt.getCurrentLine().starts_with(" 0x"))
    if (!TraceIt.isAtEoF() && isLBRSample(TraceIt.getCurrentLine(), true))
      TraceIt.advance();
    return;
  }

  warnIfMissingMMap();

  if (!TraceIt.isAtEoF() && TraceIt.getCurrentLine().starts_with(" 0x")) {
  if (!TraceIt.isAtEoF() && isLBRSample(TraceIt.getCurrentLine(), true)) {
    // Parsing LBR stack and populate into PerfSample.LBRStack
    if (extractLBRStack(TraceIt, Sample->LBRStack)) {
      if (IgnoreStackSamples) {
@@ -1172,10 +1172,12 @@ void PerfScriptReader::parseAndAggregateTrace() {
// 40062f 0x5c6313f/0x5c63170/P/-/-/0  0x5c630e7/0x5c63130/P/-/-/0 ...
// A heuristic for fast detection by checking whether a
// leading "  0x" and the '/' exist.
bool PerfScriptReader::isLBRSample(StringRef Line) {
bool PerfScriptReader::isLBRSample(StringRef Line, bool CheckLineStart) {
  // Skip the leading instruction pointer
  SmallVector<StringRef, 32> Records;
  Line.trim().split(Records, " ", 2, false);
  if (!CheckLineStart)
    Line = Line.trim();
  Line.split(Records, " ", 2, CheckLineStart);
  if (Records.size() < 2)
    return false;
  if (Records[1].starts_with("0x") && Records[1].contains('/'))
@@ -1222,7 +1224,7 @@ PerfContent PerfScriptReader::checkPerfScriptType(StringRef FileName) {
      TraceIt.advance();
    }
    if (!TraceIt.isAtEoF()) {
      if (isLBRSample(TraceIt.getCurrentLine())) {
      if (isLBRSample(TraceIt.getCurrentLine(), false)) {
        if (Count > 0)
          return PerfContent::LBRStack;
        else
+1 −1
Original line number Diff line number Diff line
@@ -633,7 +633,7 @@ public:

protected:
  // Check whether a given line is LBR sample
  static bool isLBRSample(StringRef Line);
  static bool isLBRSample(StringRef Line, bool CheckLineStart);
  // Check whether a given line is MMAP event
  static bool isMMapEvent(StringRef Line);
  // Update base address based on mmap events