jansvoboda11 created this revision. jansvoboda11 added a reviewer: akyrtzi. Herald added a subscriber: ributzka. Herald added a project: All. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This patch adds new `-print-timing` option to `clang-scan-deps`. It measures the wall and process time taken to scan dependencies for the compilation database. This provides more representative data compared to measuring the timing for the whole tool invocation, since that includes parsing and generating JSON files, which can be significant for larger inputs. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147815 Files: clang/test/ClangScanDeps/print-timing.c clang/tools/clang-scan-deps/ClangScanDeps.cpp Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp =================================================================== --- clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ 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 <mutex> #include <optional> @@ -189,6 +191,11 @@ llvm::cl::desc("The names of dependency targets for the dependency file"), llvm::cl::cat(DependencyScannerCategory)); +static llvm::cl::opt<bool> + 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; Index: clang/test/ClangScanDeps/print-timing.c =================================================================== --- /dev/null +++ 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 +[]
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp =================================================================== --- clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ 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 <mutex> #include <optional> @@ -189,6 +191,11 @@ llvm::cl::desc("The names of dependency targets for the dependency file"), llvm::cl::cat(DependencyScannerCategory)); +static llvm::cl::opt<bool> + 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; Index: clang/test/ClangScanDeps/print-timing.c =================================================================== --- /dev/null +++ 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 +[]
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits