]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Context: move stats_file
authorThomas Otto <thomas.otto@pdv-fs.de>
Sat, 25 Jan 2020 09:24:35 +0000 (10:24 +0100)
committerThomas Otto <thomas.otto@pdv-fs.de>
Sun, 16 Feb 2020 12:20:15 +0000 (13:20 +0100)
src/Context.cpp
src/Context.hpp
src/ccache.cpp
src/legacy_globals.cpp
src/legacy_globals.hpp
src/result.cpp
src/stats.cpp

index 27ab9c146c2e3dcf557ee101df8a1ac0c3dac3f1..5403f377209e4363bfdba61c823aeaa092ae8d75 100644 (file)
@@ -20,4 +20,5 @@
 
 Context::~Context()
 {
+  free(stats_file);
 }
index 4fd8187eafe86c4b42b5b4940deb8eedd2d6834c..a12f34885019e1f4639289ff2ab3594dc27f8f31 100644 (file)
@@ -31,4 +31,8 @@ struct Context : NonCopyable
 
   ArgsInfo args_info;
   Config config;
+
+  // Full path to the statistics file in the subdirectory where the cached
+  // result belongs (<cache_dir>/<x>/stats).
+  char* stats_file = nullptr;
 };
index 5a55b7446b9a82322d2c428e4a7743aadee73640..610732e0c3ae41a0cad4ebd8968a0c7762ee09b5 100644 (file)
@@ -1101,7 +1101,7 @@ update_cached_result_globals(Context& ctx, struct digest* result_name)
                                      result_name_string,
                                      ".result")
                .c_str());
-  stats_file = format(
+  ctx.stats_file = format(
     "%s/%c/stats", ctx.config.cache_dir().c_str(), result_name_string[0]);
 }
 
@@ -1373,7 +1373,7 @@ to_cache(Context& ctx,
     failed();
   }
   stats_update_size(ctx,
-                    stats_file,
+                    ctx.stats_file,
                     new_dest_stat.size_on_disk()
                       - orig_dest_stat.size_on_disk(),
                     orig_dest_stat ? 0 : 1);
@@ -1386,7 +1386,7 @@ to_cache(Context& ctx,
   // be done almost anywhere, but we might as well do it near the end as we
   // save the stat call if we exit early.
   {
-    char* first_level_dir = x_dirname(stats_file);
+    char* first_level_dir = x_dirname(ctx.stats_file);
     if (!create_cachedir_tag(first_level_dir) != 0) {
       cc_log("Failed to create %s/CACHEDIR.TAG (%s)",
              first_level_dir,
@@ -3569,7 +3569,6 @@ cc_reset(Config& config)
   has_absolute_include_headers = false;
   i_tmpfile = NULL;
   free_and_nullify(cpp_stderr);
-  free_and_nullify(stats_file);
   output_is_precompiled_header = false;
 }
 
index 19b72e0ed3dc82d84aeeeeeb4160e3dfbceb03aa..d174b98246371b99adcf7dd88228534f59aa23f1 100644 (file)
@@ -64,10 +64,6 @@ char* i_tmpfile;
 // The name of the cpp stderr file.
 char* cpp_stderr;
 
-// Full path to the statistics file in the subdirectory where the cached result
-// belongs (<cache_dir>/<x>/stats).
-char* stats_file = nullptr;
-
 // The stats file to use for the manifest.
 char* manifest_stats_file;
 
index 5719426ad25fef7977da74b85a19fed308e8b11e..08affbd4aef2bc43f4649a7022c661b99add58a9 100644 (file)
@@ -29,7 +29,7 @@
 // variable descriptions are in the .cpp file
 
 extern char* current_working_dir;
-extern char* stats_file;
+
 extern unsigned lock_staleness_limit;
 
 extern struct args* orig_args;
index 3685447c4bff2639d6096f0c1548259623ca4e21..7ac21bd85d8350eb10ee1a9deb82c4ab80467c6d 100644 (file)
@@ -85,8 +85,6 @@
 //
 // 1: Introduced in ccache 4.0.
 
-extern char* stats_file;
-
 const uint8_t k_result_magic[4] = {'c', 'C', 'r', 'S'};
 const uint8_t k_result_version = 1;
 
@@ -416,7 +414,7 @@ write_raw_file_entry(Context& ctx,
   auto new_stat = Stat::stat(raw_file);
 
   stats_update_size(ctx,
-                    stats_file,
+                    ctx.stats_file,
                     new_stat.size_on_disk() - old_stat.size_on_disk(),
                     (new_stat ? 1 : 0) - (old_stat ? 1 : 0));
 }
index 446d58e596d19ea11d2328f2c44a41e8915116b5..4e2fff0b8bf3e54c4f6fbd09a57309f870612231 100644 (file)
@@ -39,7 +39,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-extern char* stats_file;
 extern unsigned lock_staleness_limit;
 
 static struct counters* counter_updates;
@@ -305,7 +304,7 @@ stats_update_size(Context& ctx, const char* sfile, int64_t size, int files)
   }
 
   struct counters* updates;
-  if (sfile == stats_file) {
+  if (sfile == ctx.stats_file) {
     init_counter_updates();
     updates = counter_updates;
   } else {
@@ -313,7 +312,7 @@ stats_update_size(Context& ctx, const char* sfile, int64_t size, int files)
   }
   updates->data[STATS_NUMFILES] += files;
   updates->data[STATS_TOTALSIZE] += size / 1024;
-  if (sfile != stats_file) {
+  if (sfile != ctx.stats_file) {
     stats_flush_to_file(ctx.config, sfile, updates);
     counters_free(updates);
   }
@@ -429,7 +428,7 @@ void
 stats_flush(void* context)
 {
   Context& ctx = *static_cast<Context*>(context);
-  stats_flush_to_file(ctx.config, stats_file, counter_updates);
+  stats_flush_to_file(ctx.config, ctx.stats_file, counter_updates);
   counters_free(counter_updates);
   counter_updates = NULL;
 }