From: Joel Rosdahl Date: Fri, 4 Sep 2020 07:40:21 +0000 (+0200) Subject: Improve variable names related to statistics counters X-Git-Tag: v4.0~134 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd473ca091333156864ece168727b2a921505a04;p=thirdparty%2Fccache.git Improve variable names related to statistics counters --- diff --git a/src/ccache.cpp b/src/ccache.cpp index d1a97605f..27676261a 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1948,12 +1948,12 @@ cache_compilation(int argc, const char* const* argv) MTR_END("main", "find_compiler"); try { - Statistic stat = do_cache_compilation(*ctx, argv); - stats_update(*ctx, stat); + Statistic statistic = do_cache_compilation(*ctx, argv); + stats_update(*ctx, statistic); return EXIT_SUCCESS; } catch (const Failure& e) { - if (e.stat() != Statistic::none) { - stats_update(*ctx, e.stat()); + if (e.statistic() != Statistic::none) { + stats_update(*ctx, e.statistic()); } if (e.exit_code()) { diff --git a/src/exceptions.hpp b/src/exceptions.hpp index b308bef32..a6a6e670b 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -84,22 +84,23 @@ inline Fatal::Fatal(T&&... args) // Throw a Failure if ccache did not succeed in getting or putting a result in // the cache. If `exit_code` is set, just exit with that code directly, // otherwise execute the real compiler and exit with its exit code. Also updates -// statistics counter `stat` if it's not `Statistic::none`. +// statistics counter `statistic` if it's not `Statistic::none`. class Failure : public std::exception { public: - Failure(Statistic stat, nonstd::optional exit_code = nonstd::nullopt); + Failure(Statistic statistic, + nonstd::optional exit_code = nonstd::nullopt); nonstd::optional exit_code() const; - Statistic stat() const; + Statistic statistic() const; private: - Statistic m_stat; + Statistic m_statistic; nonstd::optional m_exit_code; }; -inline Failure::Failure(Statistic stat, nonstd::optional exit_code) - : m_stat(stat), m_exit_code(exit_code) +inline Failure::Failure(Statistic statistic, nonstd::optional exit_code) + : m_statistic(statistic), m_exit_code(exit_code) { } @@ -110,7 +111,7 @@ Failure::exit_code() const } inline Statistic -Failure::stat() const +Failure::statistic() const { - return m_stat; + return m_statistic; } diff --git a/src/stats.cpp b/src/stats.cpp index b8eea4c6a..5059f7c19 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -50,12 +50,12 @@ static std::string format_timestamp(uint64_t timestamp); // Statistics fields in display order. static const struct { - Statistic stat; + Statistic statistic; const char* id; // for --print-stats const char* message; // for --show-stats format_fn format; // nullptr -> use plain integer format unsigned flags; -} stats_info[] = { +} k_statistics_fields[] = { {Statistic::stats_zeroed_timestamp, "stats_zeroed_timestamp", "stats zeroed", @@ -352,9 +352,9 @@ stats_flush_to_file(const Config& config, } if (!config.log_file().empty() || config.debug()) { - for (auto& info : stats_info) { - if (updates[info.stat] != 0 && !(info.flags & FLAG_NOZERO)) { - log("Result: {}", info.message); + for (auto& field : k_statistics_fields) { + if (updates[field.statistic] != 0 && !(field.flags & FLAG_NOZERO)) { + log("Result: {}", field.message); } } } @@ -416,12 +416,12 @@ stats_flush(Context& ctx) stats_flush_to_file(ctx.config, ctx.stats_file(), ctx.counter_updates); } -// Update a normal stat. +// Update a normal statistics counter. void -stats_update(Context& ctx, Statistic stat) +stats_update(Context& ctx, Statistic statistic) { - assert(stat > Statistic::none && stat < Statistic::END); - ctx.counter_updates[stat] += 1; + assert(statistic > Statistic::none && statistic < Statistic::END); + ctx.counter_updates[statistic] += 1; } // Sum and display the total stats for all cache dirs. @@ -448,27 +448,28 @@ stats_summary(const Context& ctx) } // ...and display them. - for (int i = 0; stats_info[i].message; i++) { - Statistic stat = stats_info[i].stat; + for (size_t i = 0; k_statistics_fields[i].message; i++) { + Statistic statistic = k_statistics_fields[i].statistic; - if (stats_info[i].flags & FLAG_NEVER) { + if (k_statistics_fields[i].flags & FLAG_NEVER) { continue; } - if (counters[stat] == 0 && !(stats_info[i].flags & FLAG_ALWAYS)) { + if (counters[statistic] == 0 + && !(k_statistics_fields[i].flags & FLAG_ALWAYS)) { continue; } std::string value; - if (stats_info[i].format) { - value = stats_info[i].format(counters[stat]); + if (k_statistics_fields[i].format) { + value = k_statistics_fields[i].format(counters[statistic]); } else { - value = fmt::format("{:8}", counters[stat]); + value = fmt::format("{:8}", counters[statistic]); } if (!value.empty()) { - fmt::print("{:31} {}\n", stats_info[i].message, value); + fmt::print("{:31} {}\n", k_statistics_fields[i].message, value); } - if (stat == Statistic::cache_miss) { + if (statistic == Statistic::cache_miss) { double percent = stats_hit_rate(counters); fmt::print("cache hit rate {:6.2f} %\n", percent); } @@ -494,9 +495,11 @@ stats_print(const Config& config) fmt::print("stats_updated_timestamp\t{}\n", last_updated); - for (int i = 0; stats_info[i].message; i++) { - if (!(stats_info[i].flags & FLAG_NEVER)) { - fmt::print("{}\t{}\n", stats_info[i].id, counters[stats_info[i].stat]); + for (size_t i = 0; k_statistics_fields[i].message; i++) { + if (!(k_statistics_fields[i].flags & FLAG_NEVER)) { + fmt::print("{}\t{}\n", + k_statistics_fields[i].id, + counters[k_statistics_fields[i].statistic]); } } } @@ -520,9 +523,9 @@ stats_zero(const Context& ctx) Lockfile lock(fname); if (lock.acquired()) { stats_read(fname, counters); - for (unsigned i = 0; stats_info[i].message; i++) { - if (!(stats_info[i].flags & FLAG_NOZERO)) { - counters[stats_info[i].stat] = 0; + for (size_t i = 0; k_statistics_fields[i].message; i++) { + if (!(k_statistics_fields[i].flags & FLAG_NOZERO)) { + counters[k_statistics_fields[i].statistic] = 0; } } counters[Statistic::stats_zeroed_timestamp] = timestamp; diff --git a/src/stats.hpp b/src/stats.hpp index 0a36124d4..4561dace7 100644 --- a/src/stats.hpp +++ b/src/stats.hpp @@ -66,7 +66,7 @@ enum class Statistic { END }; -void stats_update(Context& ctx, Statistic stat); +void stats_update(Context& ctx, Statistic statistic); void stats_flush(Context& ctx); void stats_flush_to_file(const Config& config, const std::string& sfile,