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,6 +19,7 @@ #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/LLVMDriver.h" @@ -26,6 +27,7 @@ #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 @@ -90,6 +92,7 @@ static bool DeprecatedDriverCommand; static ResourceDirRecipeKind ResourceDirRecipe; static bool Verbose; +static bool PrintTiming; static std::vector CommandLine; #ifndef NDEBUG @@ -200,6 +203,8 @@ ResourceDirRecipe = *Kind; } + PrintTiming = Args.hasArg(OPT_print_timing); + Verbose = Args.hasArg(OPT_verbose); RoundTripArgs = Args.hasArg(OPT_round_trip_args); @@ -857,6 +862,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; @@ -946,6 +955,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; diff --git a/clang/tools/clang-scan-deps/Opts.td b/clang/tools/clang-scan-deps/Opts.td --- a/clang/tools/clang-scan-deps/Opts.td +++ b/clang/tools/clang-scan-deps/Opts.td @@ -31,8 +31,10 @@ defm resource_dir_recipe : Eq<"resource-dir-recipe", "How to produce missing '-resource-dir' argument">; +def print_timing : F<"print-timing", "Print timing information">; + def verbose : F<"v", "Use verbose output">; def round_trip_args : F<"round-trip-args", "verify that command-line arguments are canonical by parsing and re-serializing">; def DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>; \ No newline at end of file