[clang] [clang][deps] Improve timing output (PR #113726)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 25 11:45:45 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

<details>
<summary>Changes</summary>

This patch adds the number of executed instructions into the timing output, which provides more stable results compared to wall or process time.

The format itself is also tweaked so that it's more amenable for direct import into a spreadsheet editor. The new `-no-print-timing-header` flag can be used so that only the first out of multiple runs prints the header annotating the data.

---
Full diff: https://github.com/llvm/llvm-project/pull/113726.diff


2 Files Affected:

- (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+12-4) 
- (modified) clang/tools/clang-scan-deps/Opts.td (+1) 


``````````diff
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 7d36cee7a22b39..f6d121d86c22d8 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -88,6 +88,7 @@ static bool DeprecatedDriverCommand;
 static ResourceDirRecipeKind ResourceDirRecipe;
 static bool Verbose;
 static bool PrintTiming;
+static bool NoPrintTimingHeader;
 static llvm::BumpPtrAllocator Alloc;
 static llvm::StringSaver Saver{Alloc};
 static std::vector<const char *> CommandLine;
@@ -220,6 +221,7 @@ static void ParseArgs(int argc, char **argv) {
   }
 
   PrintTiming = Args.hasArg(OPT_print_timing);
+  NoPrintTimingHeader = Args.hasArg(OPT_no_print_timing_header);
 
   Verbose = Args.hasArg(OPT_verbose);
 
@@ -1080,10 +1082,16 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
                  << NumExistsCalls << " exists() calls\n"
                  << NumIsLocalCalls << " isLocal() calls\n";
 
-  if (PrintTiming)
-    llvm::errs() << llvm::format(
-        "clang-scan-deps timing: %0.2fs wall, %0.2fs process\n",
-        T.getTotalTime().getWallTime(), T.getTotalTime().getProcessTime());
+  if (PrintTiming) {
+    if (!NoPrintTimingHeader)
+      llvm::errs() << "wall time [s]\t"
+                   << "process time [s]\t"
+                   << "instruction count\n";
+    const llvm::TimeRecord &R = T.getTotalTime();
+    llvm::errs() << llvm::format("%0.4f", R.getWallTime()) << "\t"
+                 << llvm::format("%0.4f", R.getProcessTime()) << "\t"
+                 << llvm::format("%llu", R.getInstructionsExecuted()) << "\n";
+  }
 
   if (RoundTripArgs)
     if (FD && FD->roundTripCommands(llvm::errs()))
diff --git a/clang/tools/clang-scan-deps/Opts.td b/clang/tools/clang-scan-deps/Opts.td
index 4837ce6f070d73..2ddcdf5f90fec9 100644
--- a/clang/tools/clang-scan-deps/Opts.td
+++ b/clang/tools/clang-scan-deps/Opts.td
@@ -34,6 +34,7 @@ def deprecated_driver_command : F<"deprecated-driver-command", "use a single dri
 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 no_print_timing_header : F<"no-print-timing-header", "Do not print the timing information header">;
 
 def verbose : F<"v", "Use verbose output">;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/113726


More information about the cfe-commits mailing list