]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Add `--print-log-stats` (#1381)
authorKaspar Schleiser <kaspar@schleiser.de>
Sat, 20 Jan 2024 19:42:15 +0000 (20:42 +0100)
committerGitHub <noreply@github.com>
Sat, 20 Jan 2024 19:42:15 +0000 (20:42 +0100)
This adds a "machine readable" variant of `--show-log-stats`, similar to
`--print-stats` as a variant of `--show-stats`.

doc/MANUAL.adoc
src/core/mainoptions.cpp

index 52eb00d2cbe04803c5bac8b25cae3c644839e588..572eb0a275f6eda844b1e121f0f6547997c1cd42 100644 (file)
@@ -276,6 +276,11 @@ directory to a certain size, use `CCACHE_MAXSIZE=_SIZE_ ccache -c`.
     the file content. This option is only useful when debugging ccache and its
     behavior.
 
+*--print-log-stats*::
+
+    Print statistics counters from the stats log in machine-parseable
+    (tab-separated) format. See <<config_stats_log,*stats_log*>>.
+
 *--print-stats*::
 
     Print statistics counter IDs and corresponding values in machine-parsable
index 8374823fed0c0acb2c909fc06edb6e96cfc3f60d..d11e6c43c74078f1238e4ba835651848f0ed5a7a 100644 (file)
@@ -173,6 +173,9 @@ Options for scripting or debugging:
                                PATH
         --inspect PATH         print result/manifest file at PATH in
                                human-readable format
+        --print-log-stats      print statistics counter IDs and corresponding
+                               values from the stats log in machine-parseable
+                               format
         --print-stats          print statistics counter IDs and corresponding
                                values in machine-parsable format
 
@@ -422,6 +425,7 @@ enum {
   EXTRACT_RESULT,
   HASH_FILE,
   INSPECT,
+  PRINT_LOG_STATS,
   PRINT_STATS,
   RECOMPRESS_THREADS,
   SHOW_LOG_STATS,
@@ -451,6 +455,7 @@ const option long_options[] = {
   {"inspect", required_argument, nullptr, INSPECT},
   {"max-files", required_argument, nullptr, 'F'},
   {"max-size", required_argument, nullptr, 'M'},
+  {"print-log-stats", no_argument, nullptr, PRINT_LOG_STATS},
   {"print-stats", no_argument, nullptr, PRINT_STATS},
   {"recompress", required_argument, nullptr, 'X'},
   {"recompress-threads", required_argument, nullptr, RECOMPRESS_THREADS},
@@ -733,6 +738,17 @@ process_main_options(int argc, const char* const* argv)
       break;
     }
 
+    case PRINT_LOG_STATS: {
+      if (config.stats_log().empty()) {
+        throw Fatal("No stats log has been configured");
+      }
+      Statistics statistics(StatsLog(config.stats_log()).read());
+      const auto timestamp =
+        DirEntry(config.stats_log(), DirEntry::LogOnError::yes).mtime();
+      PRINT_RAW(stdout, statistics.format_machine_readable(config, timestamp));
+      break;
+    }
+
     case 's': { // --show-stats
       const auto [counters, last_updated] =
         storage::local::LocalStorage(config).get_all_statistics();