Skip to content

Commit b8ebec1

Browse files
committed
[BOLT][merge-fdata] Fix basic sample profile aggregation without LBR info
When a basic sample profile is gathered without LBR info, the generated profile contains a "no-lbr" tag in the first line of the fdata file. This PR fixes merge-fdata to recognize and save this tag to the output file.
1 parent 3a01b46 commit b8ebec1

File tree

7 files changed

+99
-1
lines changed

7 files changed

+99
-1
lines changed

bolt/test/Inputs/lbr_profile.fdata

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
1 __aarch64_cas4_acq/1 c 2
2+
1 __aarch64_cas4_acq/1 0 20
3+
1 __aarch64_cas4_acq/1 14 954
4+
1 __aarch64_swp4_rel/1 14 657
5+
1 __ieee754_fmod 54 1
6+
1 __ieee754_fmod 14 1
7+
1 __ieee754_fmod c8 59
8+
1 __ieee754_fmod 74 2
9+
1 __ieee754_fmod 8c 119
10+
1 __ieee754_fmod b4 55
11+
1 __ieee754_fmod 78 95
12+
1 __ieee754_fmod a0 93
13+
1 __ieee754_fmod 94 33
14+
1 __ieee754_fmod c4 96
15+
1 __ieee754_fmod 84 31
16+
1 __ieee754_fmod 80 9
17+
1 __ieee754_fmod c0 38
18+
1 __ieee754_fmod 1c 12
19+
1 __ieee754_fmod 88 111
20+
1 __ieee754_fmod 18 14
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
no_lbr cycles:HG:
2+
1 __aarch64_cas4_acq/1 c 2
3+
1 __aarch64_cas4_acq/1 0 20
4+
1 __aarch64_cas4_acq/1 14 954
5+
1 __aarch64_swp4_rel/1 14 657
6+
1 __ieee754_fmod 54 1
7+
1 __ieee754_fmod 14 1
8+
1 __ieee754_fmod c8 59
9+
1 __ieee754_fmod 74 2
10+
1 __ieee754_fmod 8c 119
11+
1 __ieee754_fmod b4 55
12+
1 __ieee754_fmod 78 95
13+
1 __ieee754_fmod a0 93
14+
1 __ieee754_fmod 94 33
15+
1 __ieee754_fmod c4 96
16+
1 __ieee754_fmod 84 31
17+
1 __ieee754_fmod 80 9
18+
1 __ieee754_fmod c0 38
19+
1 __ieee754_fmod 1c 12
20+
1 __ieee754_fmod 88 111
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
no_lbr cycles:HG:
2+
1 __aarch64_cas4_acq/1 14 981
3+
1 __aarch64_cas4_acq/1 0 23
4+
1 __aarch64_swp4_rel/1 c 2
5+
1 __aarch64_swp4_rel/1 14 663
6+
1 __ieee754_fmod 80 17
7+
1 __ieee754_fmod bc 4
8+
1 __ieee754_fmod b4 56
9+
1 __ieee754_fmod 58 12
10+
1 __ieee754_fmod b0 49
11+
1 __ieee754_fmod c0 44
12+
1 __ieee754_fmod 18 12
13+
1 __ieee754_fmod 88 98
14+
1 __ieee754_fmod 38 12
15+
1 __ieee754_fmod c4 73
16+
1 __ieee754_fmod 1c 11
17+
1 __ieee754_fmod 98 85
18+
1 __ieee754_fmod a0 85
19+
1 __ieee754_fmod c8 65
20+
1 __ieee754_fmod ac 15

bolt/test/merge-fdata-lbr-mode.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Check that merge-fdata tool doesn't falsely print no_lbr when not in no-lbr mode
2+
3+
RUN: merge-fdata %S/Inputs/blarge.fdata %S/Inputs/blarge.fdata \
4+
RUN: | FileCheck %s --check-prefix=CHECK-FDATA
5+
6+
CHECK-FDATA-NOT: no_lbr

bolt/test/merge-fdata-mixed-mode.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Check that merge-fdata tool correctly reports error message
2+
## when trying to merge 'no-lbr' and 'lbr' profiles
3+
# RUN: not merge-fdata %S/Inputs/no-lbr_profile_1.fdata \
4+
# RUN: %S/Inputs/lbr_profile.fdata \
5+
# RUN: | FileCheck %s
6+
7+
# CHECK: error: cannot mix 'no_lbr' and 'lbr' profiles
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Check that merge-fdata tool correctly processes fdata files with header
2+
## string produced by no-lbr mode (no_lbr)
3+
RUN: merge-fdata %S/Inputs/no-lbr_profile_1.fdata \
4+
RUN: %S/Inputs/no-lbr_profile_2.fdata \
5+
RUN: | FileCheck %s --check-prefix=CHECK-FDATA
6+
7+
CHECK-FDATA: no_lbr
8+
CHECK-FDATA: 1 tan 234 1

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ bool isYAML(const StringRef Filename) {
265265
void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
266266
errs() << "Using legacy profile format.\n";
267267
std::optional<bool> BoltedCollection;
268+
std::optional<bool> NoLBRCollection;
268269
std::mutex BoltedCollectionMutex;
269270
typedef StringMap<uint64_t> ProfileTy;
270271

@@ -297,7 +298,21 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
297298
"cannot mix profile collected in BOLT and non-BOLT deployments");
298299
BoltedCollection = false;
299300
}
300-
301+
// Check if the string "no_lbr" is in the first line
302+
size_t FirstNewline = Buf.find('\n');
303+
if (FirstNewline != StringRef::npos) {
304+
StringRef FirstLine = Buf.substr(0, FirstNewline);
305+
if (FirstLine.contains("no_lbr")) {
306+
if (!NoLBRCollection.value_or(true))
307+
report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
308+
NoLBRCollection = true;
309+
Buf = Buf.drop_front(FirstNewline + 1);
310+
} else {
311+
if (NoLBRCollection.value_or(false))
312+
report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
313+
NoLBRCollection = false;
314+
}
315+
}
301316
Profile = &Profiles[tid];
302317
}
303318

@@ -336,6 +351,8 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
336351

337352
if (BoltedCollection.value_or(false))
338353
output() << "boltedcollection\n";
354+
if (NoLBRCollection.value_or(false))
355+
output() << "no_lbr\n";
339356
for (const auto &[Key, Value] : MergedProfile)
340357
output() << Key << " " << Value << "\n";
341358

0 commit comments

Comments
 (0)