[PATCH] D147815: [clang][deps] Print timing information

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 20 11:18:44 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe766e3afedeb: [clang][deps] Print timing information (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D147815?vs=511802&id=515401#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147815/new/

https://reviews.llvm.org/D147815

Files:
  clang/test/ClangScanDeps/print-timing.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  clang/tools/clang-scan-deps/Opts.td


Index: clang/tools/clang-scan-deps/Opts.td
===================================================================
--- clang/tools/clang-scan-deps/Opts.td
+++ 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
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===================================================================
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ 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 <mutex>
 #include <optional>
@@ -90,6 +92,7 @@
 static bool DeprecatedDriverCommand;
 static ResourceDirRecipeKind ResourceDirRecipe;
 static bool Verbose;
+static bool PrintTiming;
 static std::vector<const char *> 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;
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
+[]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147815.515401.patch
Type: text/x-patch
Size: 3011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230420/3d295fd1/attachment.bin>


More information about the cfe-commits mailing list