summaryrefslogtreecommitdiff
path: root/unittests/ProfileData
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-07-19 01:17:20 +0000
committerVedant Kumar <vsk@apple.com>2016-07-19 01:17:20 +0000
commitd91d378e3a63e93145509521a5ed404af7ea8f5d (patch)
tree14aad7957a1c1aa3a14eef7c552ace9733dbd43a /unittests/ProfileData
parent40a2c5247c293749c005681aba150f7ae9f0cc51 (diff)
Retry: [llvm-profdata] Speed up merging by using a thread pool
Add a "-j" option to llvm-profdata to control the number of threads used. Auto-detect NumThreads when it isn't specified, and avoid spawning threads when they wouldn't be beneficial. I tested this patch using a raw profile produced by clang (147MB). Here is the time taken to merge 4 copies together on my laptop: No thread pool: 112.87s user 5.92s system 97% cpu 2:01.08 total With 2 threads: 134.99s user 26.54s system 164% cpu 1:33.31 total Changes since the initial commit: - When handling odd-length inputs, call ThreadPool::wait() before merging the last profile. Should fix a race/off-by-one (see r275937). Differential Revision: https://reviews.llvm.org/D22438 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275938 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ProfileData')
-rw-r--r--unittests/ProfileData/InstrProfTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp
index c13f31251de..4efb17ecc26 100644
--- a/unittests/ProfileData/InstrProfTest.cpp
+++ b/unittests/ProfileData/InstrProfTest.cpp
@@ -204,6 +204,31 @@ TEST_F(InstrProfTest, get_profile_summary) {
delete PSFromMD;
}
+TEST_F(InstrProfTest, test_writer_merge) {
+ InstrProfRecord Record1("func1", 0x1234, {42});
+ NoError(Writer.addRecord(std::move(Record1)));
+
+ InstrProfWriter Writer2;
+ InstrProfRecord Record2("func2", 0x1234, {0, 0});
+ NoError(Writer2.addRecord(std::move(Record2)));
+
+ NoError(Writer.mergeRecordsFromWriter(std::move(Writer2)));
+
+ auto Profile = Writer.writeBuffer();
+ readProfile(std::move(Profile));
+
+ Expected<InstrProfRecord> R = Reader->getInstrProfRecord("func1", 0x1234);
+ ASSERT_TRUE(NoError(R.takeError()));
+ ASSERT_EQ(1U, R->Counts.size());
+ ASSERT_EQ(42U, R->Counts[0]);
+
+ R = Reader->getInstrProfRecord("func2", 0x1234);
+ ASSERT_TRUE(NoError(R.takeError()));
+ ASSERT_EQ(2U, R->Counts.size());
+ ASSERT_EQ(0U, R->Counts[0]);
+ ASSERT_EQ(0U, R->Counts[1]);
+}
+
static const char callee1[] = "callee1";
static const char callee2[] = "callee2";
static const char callee3[] = "callee3";