Skip to content

Commit 5a55e2a

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 5a55e2a

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-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
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
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: 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)