summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2022-04-11 21:56:12 +0800
committerTom Stellard <tstellar@redhat.com>2022-05-18 20:10:32 -0700
commit7a42b2fd5be3f4141bd0db3c5efa2ebb74ef658d (patch)
treee0b59c783bcefb56b43f98dc07d4849c299a7386
parentd6319246f89b2f47c9176e23be3fbe23c7c7d2c4 (diff)
downloadllvm-7a42b2fd5be3f4141bd0db3c5efa2ebb74ef658d.tar.gz
[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 7d7771f34d14e0108adf02a6fd0b33943afae3da)
-rw-r--r--bolt/tools/merge-fdata/merge-fdata.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/bolt/tools/merge-fdata/merge-fdata.cpp b/bolt/tools/merge-fdata/merge-fdata.cpp
index cd8f343ac08c..5738219247ba 100644
--- a/bolt/tools/merge-fdata/merge-fdata.cpp
+++ b/bolt/tools/merge-fdata/merge-fdata.cpp
@@ -239,6 +239,7 @@ void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
errs() << "Using legacy profile format.\n";
bool BoltedCollection = false;
bool First = true;
+ StringMap<uint64_t> Entries;
for (const std::string &Filename : Filenames) {
if (isYAML(Filename))
report_error(Filename, "cannot mix YAML and legacy formats");
@@ -265,9 +266,25 @@ void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
"cannot mix profile collected in BOLT and non-BOLT deployments");
}
- outs() << Buf;
+ SmallVector<StringRef, 10> Lines;
+ SplitString(Buf, Lines, "\n");
+ for (StringRef Line : Lines) {
+ size_t Pos = Line.rfind(" ");
+ if (Pos == StringRef::npos)
+ report_error(Filename, "Malformed / corrupted profile");
+ StringRef Signature = Line.substr(0, Pos);
+ uint64_t Count;
+ if (Line.substr(Pos + 1, Line.size() - Pos).getAsInteger(10, Count))
+ report_error(Filename, "Malformed / corrupted profile counter");
+ Count += Entries.lookup(Signature);
+ Entries.insert_or_assign(Signature, Count);
+ }
First = false;
}
+
+ for (const auto &Entry : Entries)
+ outs() << Entry.getKey() << " " << Entry.getValue() << "\n";
+
errs() << "Profile from " << Filenames.size() << " files merged.\n";
}