llvm.org GIT mirror llvm / 574c516
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307609 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
3 changed file(s) with 32 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
261261 The demangler is expected to read a newline-separated list of symbols from
262262 stdin and write a newline-separated list of the same length to stdout.
263263
264 .. option:: -num-threads=N, -j=N
265
266 Use N threads to write file reports (only applicable when -output-dir is
267 specified). When N=0, llvm-cov auto-detects an appropriate number of threads to
268 use. This is the default.
269
264270 .. option:: -line-coverage-gt=
265271
266272 Show code coverage only for functions with line coverage greater than the
0 // Coverage/profile data recycled from the showLineExecutionCounts.cpp test.
1 //
2 // RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata
3 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -j 1 -o %t1.dir -instr-profile %t.profdata -filename-equivalence %S/showLineExecutionCounts.cpp
4 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -num-threads 2 -o %t2.dir -instr-profile %t.profdata -filename-equivalence %S/showLineExecutionCounts.cpp
5 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t3.dir -instr-profile %t.profdata -filename-equivalence %S/showLineExecutionCounts.cpp
6 //
7 // RUN: diff %t1.dir/index.txt %t2.dir/index.txt
8 // RUN: diff %t1.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %t2.dir/coverage/tmp/showLineExecutionCounts.cpp.txt
9 // RUN: diff %t1.dir/index.txt %t3.dir/index.txt
10 // RUN: diff %t1.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %t3.dir/coverage/tmp/showLineExecutionCounts.cpp.txt
3131 #include "llvm/Support/Process.h"
3232 #include "llvm/Support/Program.h"
3333 #include "llvm/Support/ScopedPrinter.h"
34 #include "llvm/Support/Threading.h"
3435 #include "llvm/Support/ThreadPool.h"
3536 #include "llvm/Support/ToolOutputFile.h"
3637 #include
704705 "project-title", cl::Optional,
705706 cl::desc("Set project title for the coverage report"));
706707
708 cl::opt NumThreads(
709 "num-threads", cl::init(0),
710 cl::desc("Number of merge threads to use (default: autodetect)"));
711 cl::alias NumThreadsA("j", cl::desc("Alias for --num-threads"),
712 cl::aliasopt(NumThreads));
713
707714 auto Err = commandLineParser(argc, argv);
708715 if (Err)
709716 return Err;
789796 }
790797 }
791798
792 // FIXME: Sink the hardware_concurrency() == 1 check into ThreadPool.
793 if (!ViewOpts.hasOutputDirectory() ||
794 std::thread::hardware_concurrency() == 1) {
799 // If NumThreads is not specified, auto-detect a good default.
800 if (NumThreads == 0)
801 NumThreads =
802 std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(),
803 unsigned(SourceFiles.size())));
804
805 if (!ViewOpts.hasOutputDirectory() || NumThreads == 1) {
795806 for (const std::string &SourceFile : SourceFiles)
796807 writeSourceFileView(SourceFile, Coverage.get(), Printer.get(),
797808 ShowFilenames);
798809 } else {
799810 // In -output-dir mode, it's safe to use multiple threads to print files.
800 ThreadPool Pool;
811 ThreadPool Pool(NumThreads);
801812 for (const std::string &SourceFile : SourceFiles)
802813 Pool.async(&CodeCoverageTool::writeSourceFileView, this, SourceFile,
803814 Coverage.get(), Printer.get(), ShowFilenames);