[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
Mingming Liu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 18 14:51:45 PDT 2025
================
@@ -370,6 +377,61 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput,
return PerfReader;
}
+void PerfReaderBase::parseDataAccessPerfTraces(
+ StringRef DataAccessPerfTraceFile, std::optional<int32_t> PIDFilter) {
+ std::regex logRegex(
+ R"(^.*?PERF_RECORD_SAMPLE\(.*?\):\s*(\d+)\/(\d+):\s*(0x[0-9a-fA-F]+)\s+period:\s*\d+\s+addr:\s*(0x[0-9a-fA-F]+)$)");
+
+ auto BufferOrErr = MemoryBuffer::getFile(DataAccessPerfTraceFile);
+ std::error_code EC = BufferOrErr.getError();
+ if (EC)
+ exitWithError("Failed to open perf trace file: " + DataAccessPerfTraceFile);
+
+ 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;
+ }
+
+ // Skip lines that do not contain "PERF_RECORD_SAMPLE".
+ if (!Line.contains("PERF_RECORD_SAMPLE")) {
+ continue;
+ }
+
+ std::smatch matches;
+ const std::string LineStr = Line.str();
+
+ if (std::regex_search(LineStr.begin(), LineStr.end(), matches, logRegex)) {
+ if (matches.size() != 5)
+ continue;
+
+ const int32_t PID = std::stoi(matches[1].str());
+ if (PIDFilter && *PIDFilter != PID) {
----------------
mingmingl-llvm wrote:
done.
https://github.com/llvm/llvm-project/pull/148013
More information about the llvm-branch-commits
mailing list