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

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.

>From 2dd85fad0502773c6a3e46f7c654b959ddc5a1c4 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svob...@apple.com>
Date: Fri, 25 Oct 2024 11:42:58 -0700
Subject: [PATCH] [clang][deps] Improve timing output

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.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 16 ++++++++++++----
 clang/tools/clang-scan-deps/Opts.td           |  1 +
 2 files changed, 13 insertions(+), 4 deletions(-)

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">;
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to