[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
Paschalis Mpeis via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 25 04:54:07 PDT 2025
================
@@ -370,6 +375,65 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput,
return PerfReader;
}
+Error PerfReaderBase::parseDataAccessPerfTraces(
+ StringRef DataAccessPerfTraceFile, std::optional<int32_t> PIDFilter) {
+ // A perf_record_sample line is like
+ // . 1282514022939813 0x87b0 [0x60]: PERF_RECORD_SAMPLE(IP, 0x4002):
+ // 3446532/3446532: 0x2608a2 period: 233 addr: 0x3b3fb0
+ constexpr static const char *const DataAccessSamplePattern =
+ "PERF_RECORD_SAMPLE\\([A-Za-z]+, 0x[0-9a-fA-F]+\\): "
+ "([0-9]+)\\/[0-9]+: (0x[0-9a-fA-F]+) period: [0-9]+ addr: "
+ "(0x[0-9a-fA-F]+)";
+
+ llvm::Regex logRegex(DataAccessSamplePattern);
+
+ auto BufferOrErr = MemoryBuffer::getFile(DataAccessPerfTraceFile);
+ std::error_code EC = BufferOrErr.getError();
+ if (EC)
+ return make_error<StringError>("Failed to open perf trace file: " +
+ DataAccessPerfTraceFile,
+ inconvertibleErrorCode());
+
+ assert(!SampleCounters.empty() && "Sample counters should not be empty!");
+ SampleCounter &Counter = SampleCounters.begin()->second;
+ line_iterator LineIt(*BufferOrErr.get(), true);
+ for (; !LineIt.is_at_eof(); ++LineIt) {
+ StringRef Line = *LineIt;
+
+ MMapEvent MMap;
+ if (Line.contains("PERF_RECORD_MMAP2")) {
+ if (PerfScriptReader::extractMMapEventForBinary(Binary, Line, MMap)) {
+ if (!MMap.MemProtectionFlag.contains("x")) {
+ Binary->addMMapNonTextEvent(MMap);
+ }
+ }
+ continue;
+ }
+
+ SmallVector<StringRef> Fields;
+ if (logRegex.match(Line, &Fields)) {
+ int32_t PID = 0;
+ Fields[1].getAsInteger(0, PID);
+ if (PIDFilter.has_value() && *PIDFilter != PID) {
+ continue;
+ }
+
+ uint64_t DataAddress = 0;
+ Fields[3].getAsInteger(0, DataAddress);
+
+ StringRef DataSymbol = Binary->symbolizeDataAddress(
----------------
paschalis-mpeis wrote:
Maybe it's worth adding a comment that the memory accesses pointing to the vtables (based on the ABI convention) are recorded?
https://github.com/llvm/llvm-project/pull/148013
More information about the llvm-branch-commits
mailing list