[llvm] [BOLT] Make memory profile parsing optional (PR #129585)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 14:13:33 PDT 2025
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/129585
>From 868e791ff4c45cc3d3270a4778d5b76c61c8c28b Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 3 Mar 2025 12:20:29 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
bolt/lib/Profile/DataAggregator.cpp | 49 +++++++++++++++++------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index d20626bd5062f..909ec32477468 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -61,6 +61,12 @@ FilterMemProfile("filter-mem-profile",
cl::init(true),
cl::cat(AggregatorCategory));
+static cl::opt<bool> ParseMemProfile(
+ "parse-mem-profile",
+ cl::desc("enable memory profile parsing if it's present in the input data, "
+ "on by default unless `--itrace` is set."),
+ cl::init(true), cl::cat(AggregatorCategory));
+
static cl::opt<unsigned long long>
FilterPID("pid",
cl::desc("only use samples from process with specified PID"),
@@ -177,6 +183,10 @@ void DataAggregator::start() {
"script -F pid,event,ip",
/*Wait = */false);
} else if (!opts::ITraceAggregation.empty()) {
+ // Disable parsing memory profile from trace data, unless requested by user.
+ if (!opts::ParseMemProfile.getNumOccurrences())
+ opts::ParseMemProfile = false;
+
std::string ItracePerfScriptArgs = llvm::formatv(
"script -F pid,brstack --itrace={0}", opts::ITraceAggregation);
launchPerfProcess("branch events with itrace", MainEventsPPI,
@@ -187,12 +197,9 @@ void DataAggregator::start() {
/*Wait = */ false);
}
- // Note: we launch script for mem events regardless of the option, as the
- // command fails fairly fast if mem events were not collected.
- launchPerfProcess("mem events",
- MemEventsPPI,
- "script -F pid,event,addr,ip",
- /*Wait = */false);
+ if (opts::ParseMemProfile)
+ launchPerfProcess("mem events", MemEventsPPI, "script -F pid,event,addr,ip",
+ /*Wait = */ false);
launchPerfProcess("process events", MMapEventsPPI,
"script --show-mmap-events --no-itrace",
@@ -213,7 +220,8 @@ void DataAggregator::abort() {
sys::Wait(TaskEventsPPI.PI, 1, &Error);
sys::Wait(MMapEventsPPI.PI, 1, &Error);
sys::Wait(MainEventsPPI.PI, 1, &Error);
- sys::Wait(MemEventsPPI.PI, 1, &Error);
+ if (opts::ParseMemProfile)
+ sys::Wait(MemEventsPPI.PI, 1, &Error);
deleteTempFiles();
@@ -464,13 +472,6 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
exit(1);
};
- auto MemEventsErrorCallback = [&](int ReturnCode, StringRef ErrBuf) {
- Regex NoData("Samples for '.*' event do not have ADDR attribute set. "
- "Cannot print 'addr' field.");
- if (!NoData.match(ErrBuf))
- ErrorCallback(ReturnCode, ErrBuf);
- };
-
if (BC.IsLinuxKernel) {
// Current MMap parsing logic does not work with linux kernel.
// MMap entries for linux kernel uses PERF_RECORD_MMAP
@@ -511,13 +512,21 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
(opts::BasicAggregation && parseBasicEvents()))
errs() << "PERF2BOLT: failed to parse samples\n";
- // Special handling for memory events
- if (prepareToParse("mem events", MemEventsPPI, MemEventsErrorCallback))
- return Error::success();
+ if (opts::ParseMemProfile) {
+ auto MemEventsErrorCallback = [&](int ReturnCode, StringRef ErrBuf) {
+ Regex NoData("Samples for '.*' event do not have ADDR attribute set. "
+ "Cannot print 'addr' field.");
+ if (!NoData.match(ErrBuf))
+ ErrorCallback(ReturnCode, ErrBuf);
+ };
- if (const std::error_code EC = parseMemEvents())
- errs() << "PERF2BOLT: failed to parse memory events: " << EC.message()
- << '\n';
+ if (prepareToParse("mem events", MemEventsPPI, MemEventsErrorCallback))
+ return Error::success();
+
+ if (const std::error_code EC = parseMemEvents())
+ errs() << "PERF2BOLT: failed to parse memory events: " << EC.message()
+ << '\n';
+ }
deleteTempFiles();
More information about the llvm-commits
mailing list