@@ -164,6 +164,10 @@ void DataAggregator::findPerfExecutable() {
164164void DataAggregator::start () {
165165 outs () << " PERF2BOLT: Starting data aggregation job for " << Filename << " \n " ;
166166
167+ // Turn on heatmap building if requested by --heatmap flag.
168+ if (!opts::HeatmapMode && opts::HeatmapOutput.getNumOccurrences ())
169+ opts::HeatmapMode = opts::HeatmapModeKind::HM_Optional;
170+
167171 // Don't launch perf for pre-aggregated files or when perf input is specified
168172 // by the user.
169173 if (opts::ReadPreAggregated || !opts::ReadPerfEvents.empty ())
@@ -502,24 +506,25 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
502506 errs () << " PERF2BOLT: failed to parse samples\n " ;
503507
504508 // Special handling for memory events
505- if (prepareToParse (" mem events" , MemEventsPPI, MemEventsErrorCallback))
506- return Error::success ();
507-
508- if (const std::error_code EC = parseMemEvents ())
509- errs () << " PERF2BOLT: failed to parse memory events: " << EC.message ()
510- << ' \n ' ;
509+ if (!prepareToParse (" mem events" , MemEventsPPI, MemEventsErrorCallback))
510+ if (const std::error_code EC = parseMemEvents ())
511+ errs () << " PERF2BOLT: failed to parse memory events: " << EC.message ()
512+ << ' \n ' ;
511513
512514 deleteTempFiles ();
513515
514516heatmap:
515- if (opts::HeatmapMode) {
516- if (std::error_code EC = printLBRHeatMap ()) {
517- errs () << " ERROR: failed to print heat map: " << EC.message () << ' \n ' ;
518- exit (1 );
519- }
520- exit (0 );
521- }
522- return Error::success ();
517+ if (!opts::HeatmapMode)
518+ return Error::success ();
519+
520+ if (std::error_code EC = printLBRHeatMap ())
521+ return errorCodeToError (EC);
522+
523+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Optional)
524+ return Error::success ();
525+
526+ assert (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive);
527+ exit (0 );
523528}
524529
525530Error DataAggregator::readProfile (BinaryContext &BC) {
@@ -1351,15 +1356,14 @@ std::error_code DataAggregator::printLBRHeatMap() {
13511356 exit (1 );
13521357 }
13531358
1354- HM.print (opts::OutputFilename);
1355- if (opts::OutputFilename == " -" )
1356- HM.printCDF (opts::OutputFilename);
1357- else
1358- HM.printCDF (opts::OutputFilename + " .csv" );
1359- if (opts::OutputFilename == " -" )
1360- HM.printSectionHotness (opts::OutputFilename);
1361- else
1362- HM.printSectionHotness (opts::OutputFilename + " -section-hotness.csv" );
1359+ HM.print (opts::HeatmapOutput);
1360+ if (opts::HeatmapOutput == " -" ) {
1361+ HM.printCDF (opts::HeatmapOutput);
1362+ HM.printSectionHotness (opts::HeatmapOutput);
1363+ } else {
1364+ HM.printCDF (opts::HeatmapOutput + " .csv" );
1365+ HM.printSectionHotness (opts::HeatmapOutput + " -section-hotness.csv" );
1366+ }
13631367
13641368 return std::error_code ();
13651369}
@@ -1386,7 +1390,7 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
13861390 const uint64_t TraceTo = NextLBR->From ;
13871391 const BinaryFunction *TraceBF =
13881392 getBinaryFunctionContainingAddress (TraceFrom);
1389- if (opts::HeatmapMode) {
1393+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive ) {
13901394 FTInfo &Info = FallthroughLBRs[Trace (TraceFrom, TraceTo)];
13911395 ++Info.InternCount ;
13921396 } else if (TraceBF && TraceBF->containsAddress (TraceTo)) {
@@ -1424,7 +1428,7 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14241428 NextLBR = &LBR;
14251429
14261430 // Record branches outside binary functions for heatmap.
1427- if (opts::HeatmapMode) {
1431+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive ) {
14281432 TakenBranchInfo &Info = BranchLBRs[Trace (LBR.From , LBR.To )];
14291433 ++Info.TakenCount ;
14301434 continue ;
@@ -1439,7 +1443,8 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14391443 }
14401444 // Record LBR addresses not covered by fallthroughs (bottom-of-stack source
14411445 // and top-of-stack target) as basic samples for heatmap.
1442- if (opts::HeatmapMode && !Sample.LBR .empty ()) {
1446+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive &&
1447+ !Sample.LBR .empty ()) {
14431448 ++BasicSamples[Sample.LBR .front ().To ];
14441449 ++BasicSamples[Sample.LBR .back ().From ];
14451450 }
0 commit comments