@@ -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 }
@@ -1216,8 +1217,8 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12161217 ErrorOr<StringRef> TypeOrErr = parseString (FieldSeparator);
12171218 if (std::error_code EC = TypeOrErr.getError ())
12181219 return EC;
1219- enum TType { TRACE, BRANCH, FT, FT_EXTERNAL_ORIGIN, INVALID };
1220- auto Type = StringSwitch<TType >(TypeOrErr.get ())
1220+ enum AggregatedLBREntry { TRACE, BRANCH, FT, FT_EXTERNAL_ORIGIN, INVALID };
1221+ auto Type = StringSwitch<AggregatedLBREntry >(TypeOrErr.get ())
12211222 .Case (" T" , TRACE)
12221223 .Case (" B" , BRANCH)
12231224 .Case (" F" , FT)
@@ -1241,7 +1242,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12411242 return EC;
12421243
12431244 ErrorOr<Location> TraceFtEnd = std::error_code ();
1244- if (Type == TRACE) {
1245+ if (Type == AggregatedLBREntry:: TRACE) {
12451246 while (checkAndConsumeFS ()) {
12461247 }
12471248 TraceFtEnd = parseLocationOrOffset ();
@@ -1251,12 +1252,13 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
12511252
12521253 while (checkAndConsumeFS ()) {
12531254 }
1254- ErrorOr<int64_t > Frequency = parseNumberField (FieldSeparator, Type != BRANCH);
1255+ ErrorOr<int64_t > Frequency =
1256+ parseNumberField (FieldSeparator, Type != AggregatedLBREntry::BRANCH);
12551257 if (std::error_code EC = Frequency.getError ())
12561258 return EC;
12571259
12581260 uint64_t Mispreds = 0 ;
1259- if (Type == BRANCH) {
1261+ if (Type == AggregatedLBREntry:: BRANCH) {
12601262 while (checkAndConsumeFS ()) {
12611263 }
12621264 ErrorOr<int64_t > MispredsOrErr = parseNumberField (FieldSeparator, true );
@@ -1354,19 +1356,14 @@ std::error_code DataAggregator::printLBRHeatMap() {
13541356 exit (1 );
13551357 }
13561358
1357- if (opts::HeatmapStats) {
1358- HM.printSectionHotness (outs ());
1359- return std::error_code ();
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" );
13601366 }
1361- HM.print (opts::OutputFilename);
1362- if (opts::OutputFilename == " -" )
1363- HM.printCDF (opts::OutputFilename);
1364- else
1365- HM.printCDF (opts::OutputFilename + " .csv" );
1366- if (opts::OutputFilename == " -" )
1367- HM.printSectionHotness (opts::OutputFilename);
1368- else
1369- HM.printSectionHotness (opts::OutputFilename + " -section-hotness.csv" );
13701367
13711368 return std::error_code ();
13721369}
@@ -1393,7 +1390,7 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
13931390 const uint64_t TraceTo = NextLBR->From ;
13941391 const BinaryFunction *TraceBF =
13951392 getBinaryFunctionContainingAddress (TraceFrom);
1396- if (opts::HeatmapMode) {
1393+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive ) {
13971394 FTInfo &Info = FallthroughLBRs[Trace (TraceFrom, TraceTo)];
13981395 ++Info.InternCount ;
13991396 } else if (TraceBF && TraceBF->containsAddress (TraceTo)) {
@@ -1431,7 +1428,7 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14311428 NextLBR = &LBR;
14321429
14331430 // Record branches outside binary functions for heatmap.
1434- if (opts::HeatmapMode) {
1431+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive ) {
14351432 TakenBranchInfo &Info = BranchLBRs[Trace (LBR.From , LBR.To )];
14361433 ++Info.TakenCount ;
14371434 continue ;
@@ -1446,7 +1443,8 @@ void DataAggregator::parseLBRSample(const PerfBranchSample &Sample,
14461443 }
14471444 // Record LBR addresses not covered by fallthroughs (bottom-of-stack source
14481445 // and top-of-stack target) as basic samples for heatmap.
1449- if (opts::HeatmapMode && !Sample.LBR .empty ()) {
1446+ if (opts::HeatmapMode == opts::HeatmapModeKind::HM_Exclusive &&
1447+ !Sample.LBR .empty ()) {
14501448 ++BasicSamples[Sample.LBR .front ().To ];
14511449 ++BasicSamples[Sample.LBR .back ().From ];
14521450 }
@@ -2231,8 +2229,8 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
22312229 for (const StringMapEntry<std::nullopt_t > &EventEntry : EventNames)
22322230 EventNamesOS << LS << EventEntry.first ().str ();
22332231
2234- BP.Header .Flags =
2235- opts::BasicAggregation ? BinaryFunction::PF_IP : BinaryFunction::PF_LBR ;
2232+ BP.Header .Flags = opts::BasicAggregation ? BinaryFunction::PF_BASIC
2233+ : BinaryFunction::PF_BRANCH ;
22362234
22372235 // Add probe inline tree nodes.
22382236 YAMLProfileWriter::InlineTreeDesc InlineTree;
0 commit comments