summaryrefslogtreecommitdiffstats
path: root/llvm/test/tools/llvm-cov
diff options
context:
space:
mode:
authorMax Moroz <mmoroz@chromium.org>2018-01-05 16:15:07 +0000
committerMax Moroz <mmoroz@chromium.org>2018-01-05 16:15:07 +0000
commitcc254ba4a7ed7287bf2fcdd2b482089240c4cd2b (patch)
tree2a9f2653f20efae3b733fd40208e3c9a833f7cef /llvm/test/tools/llvm-cov
parente565ebcdad01888233d61514d8c98c2ff894e37e (diff)
downloadbcm5719-llvm-cc254ba4a7ed7287bf2fcdd2b482089240c4cd2b.tar.gz
bcm5719-llvm-cc254ba4a7ed7287bf2fcdd2b482089240c4cd2b.zip
[llvm-cov] Multi-threaded implementation of prepareFileReports method.
Summary: Local testing has demonstrated a great speed improvement, compare the following: 1) Existing version: ``` $ time llvm-cov show -format=html -output-dir=report -instr-profile=... ... The tool has been launched: 00:00:00 Loading coverage data: 00:00:00 Get unique source files: 00:00:33 Creating an index out of the source files: 00:00:34 Going into prepareFileReports: 00:00:34 Going to emit summary information for each file: 00:28:55 <-- 28:21 min! Going to emit links to files with no function: 00:28:55 Launching 32 threads for generating HTML files: 00:28:55 real 37m43.651s user 112m5.540s sys 7m39.872s ``` 2) Multi-threaded version with 32 CPUs: ``` $ time llvm-cov show -format=html -output-dir=report -instr-profile=... ... The tool has been launched: 00:00:00 Loading coverage data: 00:00:00 Get unique source files: 00:00:38 Creating an index out of the source files: 00:00:40 Going into prepareFileReports: 00:00:40 Preparing file reports using 32 threads: 00:00:40 # Creating thread tasks for the following number of files: 16422 Going to emit summary information for each file: 00:01:57 <-- 1:17 min! Going to emit links to files with no function: 00:01:58 Launching 32 threads for generating HTML files: 00:01:58 real 11m2.044s user 134m48.124s sys 7m53.388s ``` Reviewers: vsk, morehouse Reviewed By: vsk Subscribers: Dor1s, llvm-commits, kcc Differential Revision: https://reviews.llvm.org/D41206 llvm-svn: 321871
Diffstat (limited to 'llvm/test/tools/llvm-cov')
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/abs.h7
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.cc15
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.h8
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.cc15
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.covmappingbin0 -> 1428 bytes
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.profdatabin0 -> 1416 bytes
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/pow.h11
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.cc15
-rw-r--r--llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.h8
-rw-r--r--llvm/test/tools/llvm-cov/multithreaded-report.test93
10 files changed, 172 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/abs.h b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/abs.h
new file mode 100644
index 00000000000..41eb2b06c0f
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/abs.h
@@ -0,0 +1,7 @@
+template<typename T>
+T abs(T x) {
+ if (x < 0) {
+ return -x;
+ }
+ return x;
+}
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.cc b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.cc
new file mode 100644
index 00000000000..7df13d8d95d
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.cc
@@ -0,0 +1,15 @@
+#include "abs.h"
+#include "bytes.h"
+#include "pow.h"
+
+bool loopBytes() {
+ uint64_t totalInt = 0;
+ double totalFloat = 0;
+ for (uint8_t i = 1; i != 0; ++i) {
+ double a = logarithm(i);
+ a = abs(a);
+ totalInt += abs(pow(i, static_cast<uint8_t>(a)));
+ totalFloat += pow(static_cast<decltype(a)>(i), a);
+ }
+ return totalInt > totalFloat;
+}
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.h b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.h
new file mode 100644
index 00000000000..c239bb64806
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/bytes.h
@@ -0,0 +1,8 @@
+#include <cmath>
+#include <cstdint>
+
+inline double logarithm(uint8_t v) {
+ return log(v);
+}
+
+bool loopBytes();
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.cc b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.cc
new file mode 100644
index 00000000000..b5bc6547c1b
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.cc
@@ -0,0 +1,15 @@
+#include "bytes.h"
+#include "words.h"
+
+int main() {
+ bool result = false;
+ if (loopBytes())
+ result |= true;
+ if (loopWords())
+ result |= true;
+
+ if (result)
+ return 0;
+
+ return result;
+}
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.covmapping b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.covmapping
new file mode 100644
index 00000000000..75bd4cb760b
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.covmapping
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.profdata b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.profdata
new file mode 100644
index 00000000000..21dfdcfddf9
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.profdata
Binary files differ
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/pow.h b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/pow.h
new file mode 100644
index 00000000000..303d114126d
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/pow.h
@@ -0,0 +1,11 @@
+template<typename T>
+T pow(T b, T p) {
+ if (!p)
+ return 1;
+
+ while (--p) {
+ b *= b;
+ }
+
+ return b;
+}
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.cc b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.cc
new file mode 100644
index 00000000000..7d2b47cf10f
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.cc
@@ -0,0 +1,15 @@
+#include "abs.h"
+#include "bytes.h"
+#include "pow.h"
+
+bool loopWords() {
+ uint64_t totalInt = 0;
+ double totalFloat = 0;
+ for (uint16_t i = 1; i != 0; ++i) {
+ double a = logarithm(i);
+ a = abs(a);
+ totalInt += abs(pow(i, static_cast<uint16_t>(a)));
+ totalFloat += pow(static_cast<decltype(a)>(i), a);
+ }
+ return totalInt > totalFloat;
+}
diff --git a/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.h b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.h
new file mode 100644
index 00000000000..855f7b32e0b
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/Inputs/multithreaded_report/words.h
@@ -0,0 +1,8 @@
+#include <cmath>
+#include <cstdint>
+
+inline double logarithm(uint16_t v) {
+ return log(v);
+}
+
+bool loopWords();
diff --git a/llvm/test/tools/llvm-cov/multithreaded-report.test b/llvm/test/tools/llvm-cov/multithreaded-report.test
new file mode 100644
index 00000000000..d022f2cb850
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/multithreaded-report.test
@@ -0,0 +1,93 @@
+# Test "report" command with and without multiple threads.
+RUN: llvm-cov report -num-threads=1 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.1.report
+
+RUN: llvm-cov report -num-threads=10 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.2.report
+
+RUN: diff %t.1.report %t.2.report
+
+# Test "export" command with and without multiple threads.
+RUN: llvm-cov export -num-threads=1 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.1.json
+
+RUN: llvm-cov export -num-threads=10 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.2.json
+
+RUN: diff %t.1.json %t.2.json
+
+# Test "show" command with and without multiple threads, single text file.
+RUN: llvm-cov show -format=text -num-threads=1 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.1.text
+
+RUN: llvm-cov show -format=text -num-threads=10 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.2.text
+
+RUN: diff %t.1.text %t.2.text
+
+# Test "show" command with and without multiple threads, single HTML file.
+RUN: llvm-cov show -format=html -num-threads=1 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.1.html
+
+RUN: llvm-cov show -format=html -num-threads=10 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping > %t.2.html
+
+RUN: diff %t.1.html %t.2.html
+
+# Test "show" command with and without multiple threads, text directory.
+RUN: llvm-cov show -format=text -num-threads=1 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping -o %t.1.text_dir
+
+RUN: llvm-cov show -format=text -num-threads=10 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping -o %t.2.text_dir
+
+RUN: diff -r %t.1.text_dir %t.2.text_dir
+
+# Test "show" command with and without multiple threads, HTML directory.
+RUN: llvm-cov show -format=html -num-threads=1 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping -o %t.1.html_dir
+
+RUN: llvm-cov show -format=html -num-threads=10 \
+RUN: -path-equivalence=/tmp,%S/Inputs \
+RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
+RUN: %S/Inputs/multithreaded_report/main.covmapping -o %t.2.html_dir
+
+RUN: diff -r %t.1.html_dir %t.2.html_dir
+
+
+Instructions for regenerating the test:
+
+# cd %S/Inputs/multithreaded_report
+
+cp -r . /tmp/multithreaded_report
+
+clang++ -std=c++11 -mllvm -enable-name-compression=false \
+ -fprofile-instr-generate -fcoverage-mapping \
+ /tmp/multithreaded_report/*.cc -o main
+
+LLVM_PROFILE_FILE="main.profraw" ./main
+llvm-profdata merge main.profraw -o main.profdata
+llvm-cov convert-for-testing ./main -o ./main.covmapping
+rm main main.profraw
OpenPOWER on IntegriCloud