Skip to content

Commit 7a42b2f

Browse files
kongytstellar
authored andcommitted
[BOLT] Compact legacy profiles
Merging multiple legacy profiles (produced by instrumentation BOLT) can easily reach GiBs. Let merge-fdata compact the profiles during merge to significantly reduce space usage. Differential Revision: https://reviews.llvm.org/D123513 (cherry picked from commit 7d7771f)
1 parent d631924 commit 7a42b2f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
239239
errs() << "Using legacy profile format.\n";
240240
bool BoltedCollection = false;
241241
bool First = true;
242+
StringMap<uint64_t> Entries;
242243
for (const std::string &Filename : Filenames) {
243244
if (isYAML(Filename))
244245
report_error(Filename, "cannot mix YAML and legacy formats");
@@ -265,9 +266,25 @@ void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
265266
"cannot mix profile collected in BOLT and non-BOLT deployments");
266267
}
267268

268-
outs() << Buf;
269+
SmallVector<StringRef, 10> Lines;
270+
SplitString(Buf, Lines, "\n");
271+
for (StringRef Line : Lines) {
272+
size_t Pos = Line.rfind(" ");
273+
if (Pos == StringRef::npos)
274+
report_error(Filename, "Malformed / corrupted profile");
275+
StringRef Signature = Line.substr(0, Pos);
276+
uint64_t Count;
277+
if (Line.substr(Pos + 1, Line.size() - Pos).getAsInteger(10, Count))
278+
report_error(Filename, "Malformed / corrupted profile counter");
279+
Count += Entries.lookup(Signature);
280+
Entries.insert_or_assign(Signature, Count);
281+
}
269282
First = false;
270283
}
284+
285+
for (const auto &Entry : Entries)
286+
outs() << Entry.getKey() << " " << Entry.getValue() << "\n";
287+
271288
errs() << "Profile from " << Filenames.size() << " files merged.\n";
272289
}
273290

0 commit comments

Comments
 (0)