@@ -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" ),
@@ -177,6 +183,10 @@ void DataAggregator::start() {
177183 " script -F pid,event,ip" ,
178184 /* Wait = */ false );
179185 } else if (!opts::ITraceAggregation.empty ()) {
186+ // Disable parsing memory profile from trace data, unless requested by user.
187+ if (!opts::ParseMemProfile.getNumOccurrences ())
188+ opts::ParseMemProfile = false ;
189+
180190 std::string ItracePerfScriptArgs = llvm::formatv (
181191 " script -F pid,brstack --itrace={0}" , opts::ITraceAggregation);
182192 launchPerfProcess (" branch events with itrace" , MainEventsPPI,
@@ -187,12 +197,9 @@ void DataAggregator::start() {
187197 /* Wait = */ false );
188198 }
189199
190- // Note: we launch script for mem events regardless of the option, as the
191- // command fails fairly fast if mem events were not collected.
192- launchPerfProcess (" mem events" ,
193- MemEventsPPI,
194- " script -F pid,event,addr,ip" ,
195- /* Wait = */ false );
200+ if (opts::ParseMemProfile)
201+ launchPerfProcess (" mem events" , MemEventsPPI, " script -F pid,event,addr,ip" ,
202+ /* Wait = */ false );
196203
197204 launchPerfProcess (" process events" , MMapEventsPPI,
198205 " script --show-mmap-events --no-itrace" ,
@@ -213,7 +220,8 @@ void DataAggregator::abort() {
213220 sys::Wait (TaskEventsPPI.PI , 1 , &Error);
214221 sys::Wait (MMapEventsPPI.PI , 1 , &Error);
215222 sys::Wait (MainEventsPPI.PI , 1 , &Error);
216- sys::Wait (MemEventsPPI.PI , 1 , &Error);
223+ if (opts::ParseMemProfile)
224+ sys::Wait (MemEventsPPI.PI , 1 , &Error);
217225
218226 deleteTempFiles ();
219227
@@ -464,13 +472,6 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
464472 exit (1 );
465473 };
466474
467- auto MemEventsErrorCallback = [&](int ReturnCode, StringRef ErrBuf) {
468- Regex NoData (" Samples for '.*' event do not have ADDR attribute set. "
469- " Cannot print 'addr' field." );
470- if (!NoData.match (ErrBuf))
471- ErrorCallback (ReturnCode, ErrBuf);
472- };
473-
474475 if (BC.IsLinuxKernel ) {
475476 // Current MMap parsing logic does not work with linux kernel.
476477 // MMap entries for linux kernel uses PERF_RECORD_MMAP
@@ -511,13 +512,21 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
511512 (opts::BasicAggregation && parseBasicEvents ()))
512513 errs () << " PERF2BOLT: failed to parse samples\n " ;
513514
514- // Special handling for memory events
515- if (prepareToParse (" mem events" , MemEventsPPI, MemEventsErrorCallback))
516- return Error::success ();
515+ if (opts::ParseMemProfile) {
516+ auto MemEventsErrorCallback = [&](int ReturnCode, StringRef ErrBuf) {
517+ Regex NoData (" Samples for '.*' event do not have ADDR attribute set. "
518+ " Cannot print 'addr' field." );
519+ if (!NoData.match (ErrBuf))
520+ ErrorCallback (ReturnCode, ErrBuf);
521+ };
517522
518- if (const std::error_code EC = parseMemEvents ())
519- errs () << " PERF2BOLT: failed to parse memory events: " << EC.message ()
520- << ' \n ' ;
523+ if (prepareToParse (" mem events" , MemEventsPPI, MemEventsErrorCallback))
524+ return Error::success ();
525+
526+ if (const std::error_code EC = parseMemEvents ())
527+ errs () << " PERF2BOLT: failed to parse memory events: " << EC.message ()
528+ << ' \n ' ;
529+ }
521530
522531 deleteTempFiles ();
523532
0 commit comments