diff --git a/llvm/test/tools/llvm-profgen/Inputs/recursion-compression-pseudoprobe-nommap.perfscript b/llvm/test/tools/llvm-profgen/Inputs/recursion-compression-pseudoprobe-nommap.perfscript new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-profgen/Inputs/recursion-compression-pseudoprobe-nommap.perfscript @@ -0,0 +1,21 @@ + 2017db + 2017ba + 2017e5 + 2017ba + 2017e5 + 2017d9 + 2017ba + 2017b0 + 2017b0 + 2017b0 + 2017b0 + 2017b0 + 2017b0 + 2017b0 + 2017b0 + 2017e5 + 2017d9 + 201847 + 7fcb072a67c3 + 5541f689495641d7 + 0x2017cd/0x2017db/P/-/-/0 0x2017b5/0x2017c0/P/-/-/0 0x2017a7/0x2017b2/P/-/-/0 0x2017e0/0x2017a0/P/-/-/0 0x2017cd/0x2017db/P/-/-/0 0x2017b5/0x2017c0/P/-/-/0 0x2017a7/0x2017b2/P/-/-/0 0x2017e0/0x2017a0/P/-/-/0 0x2017cd/0x2017db/P/-/-/0 0x2017d4/0x2017c0/P/-/-/0 0x2017b5/0x2017c0/P/-/-/0 0x2017a7/0x2017b2/P/-/-/0 0x2017ab/0x2017a0/P/-/-/0 0x2017ab/0x2017a0/P/-/-/0 0x2017ab/0x2017a0/P/-/-/0 0x2017ab/0x2017a0/P/-/-/0 diff --git a/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test b/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test --- a/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test +++ b/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test @@ -3,6 +3,9 @@ ; RUN: FileCheck %s --input-file %t -check-prefix=CHECK-UNCOMPRESS ; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/recursion-compression-pseudoprobe.perfscript --binary=%S/Inputs/recursion-compression-pseudoprobe.perfbin --output=%t --show-unwinder-output --profile-summary-cold-count=0 | FileCheck %s --check-prefix=CHECK-UNWINDER ; RUN: FileCheck %s --input-file %t +; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/recursion-compression-pseudoprobe-nommap.perfscript --binary=%S/Inputs/recursion-compression-pseudoprobe.perfbin --output=%t --show-unwinder-output --profile-summary-cold-count=0 | FileCheck %s --check-prefix=CHECK-UNWINDER +; RUN: FileCheck %s --input-file %t + ; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa]:4:1 ; CHECK-UNCOMPRESS: 1: 1 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 @@ -653,6 +653,10 @@ // Samples with the repeating time generated by the perf reader AggregatedCounter AggregatedSamples; PerfScriptType PerfType = PERF_UNKNOWN; + + // Use to check and warn whether we have met a mmap event before parsing a + // sample + bool EventSeen = false; }; /* 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 @@ -317,7 +317,13 @@ exitWithError(ErrorMsg); } - return Ret.first->second; + // Initialize the base address to preferred address. + ProfiledBinary &B = Ret.first->second; + uint64_t PreferredAddr = B.getPreferredBaseAddress(); + AddrToBinaryMap[PreferredAddr] = &B; + B.setBaseAddress(PreferredAddr); + + return B; } void PerfReaderBase::updateBinaryAddress(const MMapEvent &Event) { @@ -641,6 +647,13 @@ // Record samples by aggregation Sample->genHashCode(); AggregatedSamples[Hashable(Sample)]++; + if (!EventSeen) { + WithColor::warning() + << "No corresponding mmap event is matched, will use preferred " + "address as the base loading address!\n"; + // Avoid redundant warning, only warn at the first unmatched sample. + EventSeen = true; + } } } else { // LBR sample is encoded in single line after stack sample @@ -649,6 +662,7 @@ } void PerfReaderBase::parseMMap2Event(TraceStream &TraceIt) { + EventSeen = true; // Parse a line like: // PERF_RECORD_MMAP2 2113428/2113428: [0x7fd4efb57000(0x204000) @ 0 // 08:04 19532229 3585508847]: r-xp /usr/lib64/libdl-2.17.so @@ -727,8 +741,10 @@ void PerfReaderBase::parsePerfTraces( cl::list &PerfTraceFilenames) { // Parse perf traces and do aggregation. - for (auto Filename : PerfTraceFilenames) + for (auto Filename : PerfTraceFilenames) { + EventSeen = false; parseAndAggregateTrace(Filename); + } generateRawProfile(); }