[llvm] [Bolt] Add a new hidden option to perf2bolt for testing purpose (PR #163785)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 5 13:25:53 PST 2025
================
@@ -372,6 +379,80 @@ void DataAggregator::parsePreAggregated() {
}
}
+bool DataAggregator::isMMapEvent(StringRef Line) {
+ // Short cut to avoid string find is possible.
+ if (Line.empty() || Line.size() < 50)
+ return false;
+
+ // Check that PERF_RECORD_MMAP2 or PERF_RECORD_MMAP appear in the line.
+ return Line.contains("PERF_RECORD_MMAP");
+}
+
+void DataAggregator::parsePerfScriptEvents() {
+ outs() << "PERF2BOLT: parsing a hybrid perf-script events...\n";
+ NamedRegionTimer T("parsePerfScriptEvents", "Parsing perf-script events",
+ TimerGroupName, TimerGroupDesc, opts::TimeAggregator);
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
+ MemoryBuffer::getFileOrSTDIN(Filename);
+ if (std::error_code EC = MB.getError()) {
+ errs() << "PERF2BOLT-ERROR: cannot open " << Filename << ": "
+ << EC.message() << "\n";
+ exit(1);
+ }
+
+ FileBuf = std::move(*MB);
+ ParsingBuf = FileBuf->getBuffer();
+ Col = 0;
+ Line = 1;
+ std::string MMapEvents = "";
+ std::string BranchEvents = "";
----------------
aaupov wrote:
Constructing these strings might be really expensive for large perf script inputs. Did you check if running `parseMMapEvents` and `parseBranchEvents` directly on the parsing buffer works? `parseMMapEvents` is supposed to parse as much lines as it (advancing Line/Col), returning with an error code when parsing error occurs. We can consume the error and invoke parseBranchEvents on the buffer.
https://github.com/llvm/llvm-project/pull/163785
More information about the llvm-commits
mailing list