[llvm] [Bolt] Add a new hidden option to perf2bolt for testing purpose (PR #163785)
Ádám Kallai via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 7 03:02:16 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 = "";
----------------
kaadam wrote:
Thanks for your feedback.
Yes, that was my first idea. However using the following `perf script --show-mmap-events -F pid,brstack ...` command by default to extract 'mmap' and 'brstack' events for `brstack` aggregation, I found sometimes the output is not exactly an ordered list. I mean an `mmap` event might appear among the branch events. That's why I moved to create a pre-selection logic before we call the proper functions. I agree it is costly.
All in all if we can guarantee the strict order of the entries (as a prerequisites), that case we can call `parseMMapEvents` first, and when the first parse error occurs we can invoke `parseBranchEvents` on the Buffer as you suggested.
Side note: Using `parseMMapEvents` directly on the parsing buffer works correctly, the mmap function is able to handle other events like `brstack`. However if `parseBranchEvents` finds an mmap event, it will report an error.
Currently I focused on branch event aggregation only, but I agree I need to cover other events and aggregation types.
https://github.com/llvm/llvm-project/pull/163785
More information about the llvm-commits
mailing list