Skip to content

Commit 0489643

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 0489643

File tree

7 files changed

+47
-1
lines changed

7 files changed

+47
-1
lines changed

bolt/test/Inputs/lbr_profile.fdata

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 foo a 1
2+
1 bar b 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
no_lbr cycles:HG:
2+
1 foo c 2
3+
1 bar abc 20
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
no_lbr cycles:HG:
2+
1 bar abc 10
3+
1 foobar def 5

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/lbr_profile.fdata %S/Inputs/lbr_profile.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: 2>&1 | FileCheck %s
6+
7+
# CHECK: 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 bar abc 30

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)