Skip to content

Commit 5225f1b

Browse files
authored
[BOLT][merge-fdata] Fix basic sample profile aggregation without LBR info (#118481)
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 331f3cc commit 5225f1b

File tree

6 files changed

+103
-1
lines changed

6 files changed

+103
-1
lines changed

bolt/test/merge-fdata-bat-no-lbr.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Check that merge-fdata correctly handles merging two fdata files with both boltedcollection and no_lbr tags.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: split-file %s %t
6+
# RUN: merge-fdata %t/a.fdata %t/b.fdata -o %t/merged.fdata
7+
# RUN: FileCheck %s --input-file %t/merged.fdata
8+
9+
# CHECK: boltedcollection
10+
# CHECK: no_lbr
11+
# CHECK: main 2
12+
13+
#--- a.fdata
14+
boltedcollection
15+
no_lbr
16+
main 1
17+
#--- b.fdata
18+
boltedcollection
19+
no_lbr
20+
main 1

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Check that merge-fdata tool doesn't falsely print no_lbr when not in no-lbr mode
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: split-file %s %t
6+
# RUN: merge-fdata %t/a.fdata %t/b.fdata -o %t/merged.fdata
7+
# RUN: FileCheck %s --input-file %t/merged.fdata
8+
9+
# CHECK-NOT: no_lbr
10+
# CHECK: main 2
11+
12+
#--- a.fdata
13+
main 1
14+
#--- b.fdata
15+
main 1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Check that merge-fdata doesn't incorrectly merge two fdata files with boltedcollection and no_lbr tags.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: split-file %s %t
6+
# RUN: not merge-fdata %t/a.fdata %t/b.fdata 2>&1 | FileCheck %s
7+
8+
# CHECK: cannot mix profile collected in BOLT and non-BOLT deployments
9+
10+
#--- a.fdata
11+
boltedcollection
12+
no_lbr
13+
main 1
14+
#--- b.fdata
15+
no_lbr
16+
main 1

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Check that merge-fdata tool correctly reports error message
2+
## when trying to merge 'no-lbr' and 'lbr' profiles
3+
4+
# REQUIRES: system-linux
5+
6+
# RUN: split-file %s %t
7+
# RUN: not merge-fdata %t/a.fdata %t/b.fdata 2>&1 | FileCheck %s
8+
9+
# CHECK: cannot mix 'no_lbr' and 'lbr' profiles.
10+
11+
#--- a.fdata
12+
no_lbr
13+
main 1
14+
#--- b.fdata
15+
main 1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Check that merge-fdata tool correctly processes fdata files with header
2+
## string produced by no-lbr mode (no_lbr)
3+
4+
# REQUIRES: system-linux
5+
6+
# RUN: split-file %s %t
7+
# RUN: merge-fdata %t/a.fdata %t/b.fdata -o %t/merged.fdata
8+
# RUN: FileCheck %s --input-file %t/merged.fdata
9+
10+
# CHECK: no_lbr
11+
# CHECK: main 2
12+
13+
#--- a.fdata
14+
no_lbr
15+
main 1
16+
#--- b.fdata
17+
no_lbr
18+
main 1

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

Lines changed: 19 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,22 @@ 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+
// (or second line if BoltedCollection is true)
303+
size_t CheckNoLBRPos = Buf.find('\n');
304+
if (CheckNoLBRPos != StringRef::npos) {
305+
StringRef FirstLine = Buf.substr(0, CheckNoLBRPos);
306+
if (FirstLine.contains("no_lbr")) {
307+
if (!NoLBRCollection.value_or(true))
308+
report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
309+
NoLBRCollection = true;
310+
Buf = Buf.drop_front(CheckNoLBRPos + 1);
311+
} else {
312+
if (NoLBRCollection.value_or(false))
313+
report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
314+
NoLBRCollection = false;
315+
}
316+
}
301317
Profile = &Profiles[tid];
302318
}
303319

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

337353
if (BoltedCollection.value_or(false))
338354
output() << "boltedcollection\n";
355+
if (NoLBRCollection.value_or(false))
356+
output() << "no_lbr\n";
339357
for (const auto &[Key, Value] : MergedProfile)
340358
output() << Key << " " << Value << "\n";
341359

0 commit comments

Comments
 (0)