@@ -164,9 +164,9 @@ 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 --print- heatmap-stats flag.
168- if (opts::HeatmapStats )
169- opts::HeatmapMode = true ;
167+ // Turn on heatmap building if requested by --heatmap flag.
168+ if (! opts::HeatmapMode && opts::HeatmapOutput. getNumOccurrences () )
169+ opts::HeatmapMode = opts::HeatmapModeKind::HM_Optional ;
170170
171171 // Don't launch perf for pre-aggregated files or when perf input is specified
172172 // by the user.
@@ -520,9 +520,10 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
520520 if (std::error_code EC = printLBRHeatMap ())
521521 return errorCodeToError (EC);
522522
523- if (opts::HeatmapStats )
523+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Optional )
524524 return Error::success ();
525525
526+ assert (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive);
526527 exit (0 );
527528}
528529
@@ -570,11 +571,11 @@ void DataAggregator::processProfile(BinaryContext &BC) {
570571 for (auto &BFI : BC.getBinaryFunctions ()) {
571572 BinaryFunction &BF = BFI.second ;
572573 if (FuncBranchData *FBD = getBranchData (BF)) {
573- BF.markProfiled (BinaryFunction::PF_LBR );
574+ BF.markProfiled (BinaryFunction::PF_BRANCH );
574575 BF.RawSampleCount = FBD->getNumExecutedBranches ();
575576 } else if (FuncBasicSampleData *FSD =
576577 getFuncBasicSampleData (BF.getNames ())) {
577- BF.markProfiled (BinaryFunction::PF_IP );
578+ BF.markProfiled (BinaryFunction::PF_BASIC );
578579 BF.RawSampleCount = FSD->getSamples ();
579580 }
580581 }
@@ -1209,8 +1210,8 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12091210 ErrorOr<StringRef> TypeOrErr = parseString (FieldSeparator);
12101211 if (std::error_code EC = TypeOrErr.getError ())
12111212 return EC;
1212- enum TType { TRACE, BRANCH, FT, FT_EXTERNAL_ORIGIN, INVALID };
1213- auto Type = StringSwitch<TType >(TypeOrErr.get ())
1213+ enum AggregatedLBREntry { TRACE, BRANCH, FT, FT_EXTERNAL_ORIGIN, INVALID };
1214+ auto Type = StringSwitch<AggregatedLBREntry >(TypeOrErr.get ())
12141215 .Case (" T" , TRACE)
12151216 .Case (" B" , BRANCH)
12161217 .Case (" F" , FT)
@@ -1234,7 +1235,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12341235 return EC;
12351236
12361237 ErrorOr<Location> TraceFtEnd = std::error_code ();
1237- if (Type == TRACE) {
1238+ if (Type == AggregatedLBREntry:: TRACE) {
12381239 while (checkAndConsumeFS ()) {
12391240 }
12401241 TraceFtEnd = parseLocationOrOffset ();
@@ -1244,12 +1245,13 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12441245
12451246 while (checkAndConsumeFS ()) {
12461247 }
1247- ErrorOr<int64_t > Frequency = parseNumberField (FieldSeparator, Type != BRANCH);
1248+ ErrorOr<int64_t > Frequency =
1249+ parseNumberField (FieldSeparator, Type != AggregatedLBREntry::BRANCH);
12481250 if (std::error_code EC = Frequency.getError ())
12491251 return EC;
12501252
12511253 uint64_t Mispreds = 0 ;
1252- if (Type == BRANCH) {
1254+ if (Type == AggregatedLBREntry:: BRANCH) {
12531255 while (checkAndConsumeFS ()) {
12541256 }
12551257 ErrorOr<int64_t > MispredsOrErr = parseNumberField (FieldSeparator, true );
@@ -1347,19 +1349,14 @@ std::error_code DataAggregator::printLBRHeatMap() {
13471349 exit (1 );
13481350 }
13491351
1350- if (opts::HeatmapStats) {
1351- HM.printSectionHotness (outs ());
1352- return std::error_code ();
1352+ HM.print (opts::HeatmapOutput);
1353+ if (opts::HeatmapOutput == " -" ) {
1354+ HM.printCDF (opts::HeatmapOutput);
1355+ HM.printSectionHotness (opts::HeatmapOutput);
1356+ } else {
1357+ HM.printCDF (opts::HeatmapOutput + " .csv" );
1358+ HM.printSectionHotness (opts::HeatmapOutput + " -section-hotness.csv" );
13531359 }
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" );
13631360
13641361 return std::error_code ();
13651362}
@@ -1386,7 +1383,7 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
13861383 const uint64_t TraceTo = NextLBR->From ;
13871384 const BinaryFunction *TraceBF =
13881385 getBinaryFunctionContainingAddress (TraceFrom);
1389- if (opts::HeatmapMode) {
1386+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive ) {
13901387 FTInfo &Info = FallthroughLBRs[Trace (TraceFrom, TraceTo)];
13911388 ++Info.InternCount ;
13921389 } else if (TraceBF && TraceBF->containsAddress (TraceTo)) {
@@ -1424,7 +1421,7 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14241421 NextLBR = &LBR;
14251422
14261423 // Record branches outside binary functions for heatmap.
1427- if (opts::HeatmapMode) {
1424+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive ) {
14281425 TakenBranchInfo &Info = BranchLBRs[Trace (LBR.From , LBR.To )];
14291426 ++Info.TakenCount ;
14301427 continue ;
@@ -1439,7 +1436,8 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14391436 }
14401437 // Record LBR addresses not covered by fallthroughs (bottom-of-stack source
14411438 // and top-of-stack target) as basic samples for heatmap.
1442- if (opts::HeatmapMode && !Sample.LBR .empty ()) {
1439+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive &&
1440+ !Sample.LBR .empty ()) {
14431441 ++BasicSamples[Sample.LBR .front ().To ];
14441442 ++BasicSamples[Sample.LBR .back ().From ];
14451443 }
@@ -2208,8 +2206,8 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
22082206 for (const StringMapEntry<std::nullopt_t > &EventEntry : EventNames)
22092207 EventNamesOS << LS << EventEntry.first ().str ();
22102208
2211- BP.Header .Flags =
2212- opts::BasicAggregation ? BinaryFunction::PF_IP : BinaryFunction::PF_LBR ;
2209+ BP.Header .Flags = opts::BasicAggregation ? BinaryFunction::PF_BASIC
2210+ : BinaryFunction::PF_BRANCH ;
22132211
22142212 // Add probe inline tree nodes.
22152213 YAMLProfileWriter::InlineTreeDesc InlineTree;
0 commit comments