@@ -565,15 +565,14 @@ void DataAggregator::processProfile(BinaryContext &BC) {
565565 processMemEvents ();
566566
567567 // Mark all functions with registered events as having a valid profile.
568- const auto Flags = opts::BasicAggregation ? BinaryFunction::PF_SAMPLE
569- : BinaryFunction::PF_LBR;
570568 for (auto &BFI : BC.getBinaryFunctions ()) {
571569 BinaryFunction &BF = BFI.second ;
572- FuncBranchData *FBD = getBranchData (BF);
573- if (FBD || getFuncSampleData (BF.getNames ())) {
574- BF.markProfiled (Flags);
575- if (FBD)
576- BF.RawBranchCount = FBD->getNumExecutedBranches ();
570+ if (FuncBranchData *FBD = getBranchData (BF)) {
571+ BF.markProfiled (BinaryFunction::PF_LBR);
572+ BF.RawBranchCount = FBD->getNumExecutedBranches ();
573+ } else if (FuncSampleData *FSD = getFuncSampleData (BF.getNames ())) {
574+ BF.markProfiled (BinaryFunction::PF_SAMPLE);
575+ BF.RawBranchCount = FSD->getSamples ();
577576 }
578577 }
579578
@@ -630,10 +629,18 @@ StringRef DataAggregator::getLocationName(const BinaryFunction &Func,
630629
631630bool DataAggregator::doSample (BinaryFunction &OrigFunc, uint64_t Address,
632631 uint64_t Count) {
632+ // To record executed bytes, use basic block size as is regardless of BAT.
633+ uint64_t BlockSize = 0 ;
634+ if (BinaryBasicBlock *BB = OrigFunc.getBasicBlockContainingOffset (
635+ Address - OrigFunc.getAddress ()))
636+ BlockSize = BB->getOriginalSize ();
637+
633638 BinaryFunction *ParentFunc = getBATParentFunction (OrigFunc);
634639 BinaryFunction &Func = ParentFunc ? *ParentFunc : OrigFunc;
635- if (ParentFunc || (BAT && !BAT->isBATFunction (OrigFunc .getAddress ())))
640+ if (ParentFunc || (BAT && !BAT->isBATFunction (Func .getAddress ())))
636641 NumColdSamples += Count;
642+ // Attach executed bytes to parent function in case of cold fragment.
643+ Func.SampleCountInBytes += Count * BlockSize;
637644
638645 auto I = NamesToSamples.find (Func.getOneName ());
639646 if (I == NamesToSamples.end ()) {
0 commit comments