From 0b5a24e75f223f8c3bf826a2200eff6d1d29193e Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Sat, 25 Jan 2020 10:24:35 +0100 Subject: [PATCH] Context: move stats_file --- src/Context.cpp | 1 + src/Context.hpp | 4 ++++ src/ccache.cpp | 7 +++---- src/legacy_globals.cpp | 4 ---- src/legacy_globals.hpp | 2 +- src/result.cpp | 4 +--- src/stats.cpp | 7 +++---- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 27ab9c146..5403f3772 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -20,4 +20,5 @@ Context::~Context() { + free(stats_file); } diff --git a/src/Context.hpp b/src/Context.hpp index 4fd8187ea..a12f34885 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -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 (//stats). + char* stats_file = nullptr; }; diff --git a/src/ccache.cpp b/src/ccache.cpp index 5a55b7446..610732e0c 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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; } diff --git a/src/legacy_globals.cpp b/src/legacy_globals.cpp index 19b72e0ed..d174b9824 100644 --- a/src/legacy_globals.cpp +++ b/src/legacy_globals.cpp @@ -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 (//stats). -char* stats_file = nullptr; - // The stats file to use for the manifest. char* manifest_stats_file; diff --git a/src/legacy_globals.hpp b/src/legacy_globals.hpp index 5719426ad..08affbd4a 100644 --- a/src/legacy_globals.hpp +++ b/src/legacy_globals.hpp @@ -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; diff --git a/src/result.cpp b/src/result.cpp index 3685447c4..7ac21bd85 100644 --- a/src/result.cpp +++ b/src/result.cpp @@ -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)); } diff --git a/src/stats.cpp b/src/stats.cpp index 446d58e59..4e2fff0b8 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -39,7 +39,6 @@ #include #include -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); - 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; } -- 2.47.2