[BOLT] Fix merge-fdata for memory events (#128108)
Don't attempt to parse mispredictions for memory entries in LBR profile. Test Plan: added merge-fdata-mem-prof.test
This commit is contained in:
parent
f07988ff3e
commit
b01c3d6682
@ -8,13 +8,13 @@
|
||||
|
||||
# CHECK: boltedcollection
|
||||
# CHECK: no_lbr
|
||||
# CHECK: main 2
|
||||
# CHECK: 1 main 2
|
||||
|
||||
#--- a.fdata
|
||||
boltedcollection
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
#--- b.fdata
|
||||
boltedcollection
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
|
||||
17
bolt/test/merge-fdata-mem-prof.test
Normal file
17
bolt/test/merge-fdata-mem-prof.test
Normal file
@ -0,0 +1,17 @@
|
||||
## Check that merge-fdata tool correctly handles memory profile, emitting it
|
||||
## after branch profile.
|
||||
|
||||
# REQUIRES: system-linux
|
||||
|
||||
# RUN: split-file %s %t
|
||||
# RUN: merge-fdata %t/a.fdata %t/b.fdata -o %t/merged.fdata
|
||||
# RUN: FileCheck %s --input-file %t/merged.fdata
|
||||
|
||||
# CHECK: 1 main 5 1 main 10 0 1
|
||||
# CHECK-NEXT: 4 Curl_cf_def_query c 4 Curl_cft_h1_proxy 68 3
|
||||
|
||||
#--- a.fdata
|
||||
4 Curl_cf_def_query c 4 Curl_cft_h1_proxy 68 1
|
||||
4 Curl_cf_def_query c 4 Curl_cft_h1_proxy 68 2
|
||||
#--- b.fdata
|
||||
1 main 5 1 main 10 0 1
|
||||
@ -10,7 +10,7 @@
|
||||
#--- a.fdata
|
||||
boltedcollection
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
#--- b.fdata
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
|
||||
@ -10,6 +10,6 @@
|
||||
|
||||
#--- a.fdata
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
#--- b.fdata
|
||||
main 1
|
||||
1 main 1
|
||||
|
||||
@ -8,11 +8,11 @@
|
||||
# RUN: FileCheck %s --input-file %t/merged.fdata
|
||||
|
||||
# CHECK: no_lbr
|
||||
# CHECK: main 2
|
||||
# CHECK: 1 main 2
|
||||
|
||||
#--- a.fdata
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
#--- b.fdata
|
||||
no_lbr
|
||||
main 1
|
||||
1 main 1
|
||||
|
||||
@ -278,7 +278,10 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
|
||||
}
|
||||
CounterTy operator+(const CounterTy &O) { return *this += O; }
|
||||
};
|
||||
typedef StringMap<CounterTy> ProfileTy;
|
||||
struct ProfileTy {
|
||||
StringMap<CounterTy> Branch;
|
||||
StringMap<CounterTy> Memory;
|
||||
};
|
||||
|
||||
auto ParseProfile = [&](const std::string &Filename, auto &Profiles) {
|
||||
const llvm::thread::id tid = llvm::this_thread::get_id();
|
||||
@ -316,19 +319,23 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
|
||||
do {
|
||||
StringRef Line(FdataLine);
|
||||
CounterTy Count;
|
||||
unsigned Type = 0;
|
||||
if (Line.split(' ').first.getAsInteger(10, Type))
|
||||
report_error(Filename, "Malformed / corrupted entry type");
|
||||
bool IsBranchEntry = Type < 3;
|
||||
auto [Signature, ExecCount] = Line.rsplit(' ');
|
||||
if (ExecCount.getAsInteger(10, Count.Exec))
|
||||
report_error(Filename, "Malformed / corrupted execution count");
|
||||
// Only LBR profile has misprediction field
|
||||
if (!NoLBRCollection.value_or(false)) {
|
||||
if (!NoLBRCollection.value_or(false) && IsBranchEntry) {
|
||||
auto [SignatureLBR, MispredCount] = Signature.rsplit(' ');
|
||||
Signature = SignatureLBR;
|
||||
if (MispredCount.getAsInteger(10, Count.Mispred))
|
||||
report_error(Filename, "Malformed / corrupted misprediction count");
|
||||
}
|
||||
|
||||
Count += Profile->lookup(Signature);
|
||||
Profile->insert_or_assign(Signature, Count);
|
||||
auto &ProfileMap = IsBranchEntry ? Profile->Branch : Profile->Memory;
|
||||
ProfileMap[Signature] += Count;
|
||||
} while (std::getline(FdataFile, FdataLine));
|
||||
};
|
||||
|
||||
@ -344,22 +351,25 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
|
||||
Pool.wait();
|
||||
|
||||
ProfileTy MergedProfile;
|
||||
for (const auto &[Thread, Profile] : ParsedProfiles)
|
||||
for (const auto &[Key, Value] : Profile) {
|
||||
CounterTy Count = MergedProfile.lookup(Key) + Value;
|
||||
MergedProfile.insert_or_assign(Key, Count);
|
||||
}
|
||||
for (const auto &[Thread, Profile] : ParsedProfiles) {
|
||||
for (const auto &[Key, Value] : Profile.Branch)
|
||||
MergedProfile.Branch[Key] += Value;
|
||||
for (const auto &[Key, Value] : Profile.Memory)
|
||||
MergedProfile.Memory[Key] += Value;
|
||||
}
|
||||
|
||||
if (BoltedCollection.value_or(false))
|
||||
output() << "boltedcollection\n";
|
||||
if (NoLBRCollection.value_or(false))
|
||||
output() << "no_lbr\n";
|
||||
for (const auto &[Key, Value] : MergedProfile) {
|
||||
for (const auto &[Key, Value] : MergedProfile.Branch) {
|
||||
output() << Key << " ";
|
||||
if (!NoLBRCollection.value_or(false))
|
||||
output() << Value.Mispred << " ";
|
||||
output() << Value.Exec << "\n";
|
||||
}
|
||||
for (const auto &[Key, Value] : MergedProfile.Memory)
|
||||
output() << Key << ' ' << Value.Exec << '\n';
|
||||
|
||||
errs() << "Profile from " << Filenames.size() << " files merged.\n";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user