@@ -61,6 +61,12 @@ FilterMemProfile("filter-mem-profile",
6161 cl::init(true ),
6262 cl::cat(AggregatorCategory));
6363
64+ static cl::opt<bool > ParseMemProfile (
65+ " parse-mem-profile" ,
66+ cl::desc (" enable memory profile parsing if it's present in the input data, "
67+ " on by default unless `--itrace` is set." ),
68+ cl::init(true ), cl::cat(AggregatorCategory));
69+
6470static cl::opt<unsigned long long >
6571FilterPID (" pid" ,
6672 cl::desc (" only use samples from process with specified PID" ),
@@ -181,6 +187,10 @@ void DataAggregator::start() {
181187 " script -F pid,event,ip" ,
182188 /* Wait = */ false );
183189 } else if (!opts::ITraceAggregation.empty ()) {
190+ // Disable parsing memory profile from trace data, unless requested by user.
191+ if (!opts::ParseMemProfile.getNumOccurrences ())
192+ opts::ParseMemProfile = false ;
193+
184194 std::string ItracePerfScriptArgs = llvm::formatv (
185195 " script -F pid,brstack --itrace={0}" , opts::ITraceAggregation);
186196 launchPerfProcess (" branch events with itrace" , MainEventsPPI,
@@ -191,12 +201,9 @@ void DataAggregator::start() {
191201 /* Wait = */ false );
192202 }
193203
194- // Note: we launch script for mem events regardless of the option, as the
195- // command fails fairly fast if mem events were not collected.
196- launchPerfProcess (" mem events" ,
197- MemEventsPPI,
198- " script -F pid,event,addr,ip" ,
199- /* Wait = */ false );
204+ if (opts::ParseMemProfile)
205+ launchPerfProcess (" mem events" , MemEventsPPI, " script -F pid,event,addr,ip" ,
206+ /* Wait = */ false );
200207
201208 launchPerfProcess (" process events" , MMapEventsPPI,
202209 " script --show-mmap-events --no-itrace" ,
@@ -217,7 +224,8 @@ void DataAggregator::abort() {
217224 sys::Wait (TaskEventsPPI.PI , 1 , &Error);
218225 sys::Wait (MMapEventsPPI.PI , 1 , &Error);
219226 sys::Wait (MainEventsPPI.PI , 1 , &Error);
220- sys::Wait (MemEventsPPI.PI , 1 , &Error);
227+ if (opts::ParseMemProfile)
228+ sys::Wait (MemEventsPPI.PI , 1 , &Error);
221229
222230 deleteTempFiles ();
223231
@@ -506,7 +514,8 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
506514 errs () << " PERF2BOLT: failed to parse samples\n " ;
507515
508516 // Special handling for memory events
509- if (!prepareToParse (" mem events" , MemEventsPPI, MemEventsErrorCallback))
517+ if (opts::ParseMemProfile &&
518+ !prepareToParse (" mem events" , MemEventsPPI, MemEventsErrorCallback))
510519 if (const std::error_code EC = parseMemEvents ())
511520 errs () << " PERF2BOLT: failed to parse memory events: " << EC.message ()
512521 << ' \n ' ;
0 commit comments