[llvm] r307609 - [llvm-cov] Add a cl::opt to control the number of threads
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 10 18:23:29 PDT 2017
Author: vedantk
Date: Mon Jul 10 18:23:29 2017
New Revision: 307609
URL: http://llvm.org/viewvc/llvm-project?rev=307609&view=rev
Log:
[llvm-cov] Add a cl::opt to control the number of threads
When an output directory is specified, llvm-cov spawns some threads to
speed up the process of writing out file reports. Add an option which
allows users to control how many threads llvm-cov uses.
A CommandGuide.rst update + test is included.
Added:
llvm/trunk/test/tools/llvm-cov/threads.c
Modified:
llvm/trunk/docs/CommandGuide/llvm-cov.rst
llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
Modified: llvm/trunk/docs/CommandGuide/llvm-cov.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-cov.rst?rev=307609&r1=307608&r2=307609&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-cov.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-cov.rst Mon Jul 10 18:23:29 2017
@@ -262,6 +262,12 @@ OPTIONS
The demangler is expected to read a newline-separated list of symbols from
stdin and write a newline-separated list of the same length to stdout.
+.. option:: -num-threads=N, -j=N
+
+ Use N threads to write file reports (only applicable when -output-dir is
+ specified). When N=0, llvm-cov auto-detects an appropriate number of threads to
+ use. This is the default.
+
.. option:: -line-coverage-gt=<N>
Show code coverage only for functions with line coverage greater than the
Added: llvm/trunk/test/tools/llvm-cov/threads.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/threads.c?rev=307609&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/threads.c (added)
+++ llvm/trunk/test/tools/llvm-cov/threads.c Mon Jul 10 18:23:29 2017
@@ -0,0 +1,11 @@
+// Coverage/profile data recycled from the showLineExecutionCounts.cpp test.
+//
+// RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata
+// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -j 1 -o %t1.dir -instr-profile %t.profdata -filename-equivalence %S/showLineExecutionCounts.cpp
+// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -num-threads 2 -o %t2.dir -instr-profile %t.profdata -filename-equivalence %S/showLineExecutionCounts.cpp
+// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t3.dir -instr-profile %t.profdata -filename-equivalence %S/showLineExecutionCounts.cpp
+//
+// RUN: diff %t1.dir/index.txt %t2.dir/index.txt
+// RUN: diff %t1.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %t2.dir/coverage/tmp/showLineExecutionCounts.cpp.txt
+// RUN: diff %t1.dir/index.txt %t3.dir/index.txt
+// RUN: diff %t1.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %t3.dir/coverage/tmp/showLineExecutionCounts.cpp.txt
Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=307609&r1=307608&r2=307609&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Mon Jul 10 18:23:29 2017
@@ -32,6 +32,7 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/Threading.h"
#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/ToolOutputFile.h"
#include <functional>
@@ -705,6 +706,12 @@ int CodeCoverageTool::show(int argc, con
"project-title", cl::Optional,
cl::desc("Set project title for the coverage report"));
+ cl::opt<unsigned> NumThreads(
+ "num-threads", cl::init(0),
+ cl::desc("Number of merge threads to use (default: autodetect)"));
+ cl::alias NumThreadsA("j", cl::desc("Alias for --num-threads"),
+ cl::aliasopt(NumThreads));
+
auto Err = commandLineParser(argc, argv);
if (Err)
return Err;
@@ -790,15 +797,19 @@ int CodeCoverageTool::show(int argc, con
}
}
- // FIXME: Sink the hardware_concurrency() == 1 check into ThreadPool.
- if (!ViewOpts.hasOutputDirectory() ||
- std::thread::hardware_concurrency() == 1) {
+ // If NumThreads is not specified, auto-detect a good default.
+ if (NumThreads == 0)
+ NumThreads =
+ std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(),
+ unsigned(SourceFiles.size())));
+
+ if (!ViewOpts.hasOutputDirectory() || NumThreads == 1) {
for (const std::string &SourceFile : SourceFiles)
writeSourceFileView(SourceFile, Coverage.get(), Printer.get(),
ShowFilenames);
} else {
// In -output-dir mode, it's safe to use multiple threads to print files.
- ThreadPool Pool;
+ ThreadPool Pool(NumThreads);
for (const std::string &SourceFile : SourceFiles)
Pool.async(&CodeCoverageTool::writeSourceFileView, this, SourceFile,
Coverage.get(), Printer.get(), ShowFilenames);
More information about the llvm-commits
mailing list