diff --git a/clang/test/ClangScanDeps/print-timing.c b/clang/test/ClangScanDeps/print-timing.c new file mode 100644 --- /dev/null +++ b/clang/test/ClangScanDeps/print-timing.c @@ -0,0 +1,9 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: split-file %s %t + +// RUN: clang-scan-deps -compilation-database %t/cdb.json -print-timing > %t/result.json 2>%t/errs +// RUN: cat %t/errs | FileCheck %s +// CHECK: clang-scan-deps timing: {{[0-9]+}}.{{[0-9][0-9]}}s wall, {{[0-9]+}}.{{[0-9][0-9]}}s process + +//--- cdb.json +[] diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -19,12 +19,14 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/Format.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/JSON.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/ThreadPool.h" #include "llvm/Support/Threading.h" +#include "llvm/Support/Timer.h" #include "llvm/TargetParser/Host.h" #include #include @@ -189,6 +191,11 @@ llvm::cl::desc("The names of dependency targets for the dependency file"), llvm::cl::cat(DependencyScannerCategory)); +static llvm::cl::opt + PrintTiming("print-timing", llvm::cl::desc("Print timing information"), + llvm::cl::init(false), + llvm::cl::cat(DependencyScannerCategory)); + enum ResourceDirRecipeKind { RDRK_ModifyCompilerPath, RDRK_InvokeCompiler, @@ -800,6 +807,10 @@ llvm::outs() << "Running clang-scan-deps on " << Inputs.size() << " files using " << Pool.getThreadCount() << " workers\n"; } + + llvm::Timer T; + T.startTimer(); + for (unsigned I = 0; I < Pool.getThreadCount(); ++I) { Pool.async([&, I]() { llvm::StringSet<> AlreadySeenModules; @@ -889,6 +900,12 @@ } Pool.wait(); + T.stopTimer(); + if (PrintTiming) + llvm::errs() << llvm::format( + "clang-scan-deps timing: %0.2fs wall, %0.2fs process\n", + T.getTotalTime().getWallTime(), T.getTotalTime().getProcessTime()); + if (RoundTripArgs) if (FD && FD->roundTripCommands(llvm::errs())) HadErrors = true;