From: Joel Rosdahl Date: Thu, 3 Aug 2023 11:24:32 +0000 (+0200) Subject: feat: Include maximum size/files in --print-stats X-Git-Tag: v4.9~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=babf276da4d52957fb6a38161f6b7df5ad09d9f2;p=thirdparty%2Fccache.git feat: Include maximum size/files in --print-stats New output: - max_cache_size_kibibyte: maximum size of local storage in KiB (0 for no limit) - max_files_in_cache: maximum number of files in local storage (0 for no limit) Closes #1315. --- diff --git a/src/core/Statistics.cpp b/src/core/Statistics.cpp index df776d494..240fa1337 100644 --- a/src/core/Statistics.cpp +++ b/src/core/Statistics.cpp @@ -511,19 +511,26 @@ Statistics::format_human_readable(const Config& config, } std::string -Statistics::format_machine_readable(const util::TimePoint& last_updated) const +Statistics::format_machine_readable(const Config& config, + const util::TimePoint& last_updated) const { std::vector lines; lines.push_back(FMT("stats_updated_timestamp\t{}\n", last_updated.sec())); + auto add_line = [&](auto id, auto value) { + lines.push_back(FMT("{}\t{}\n", id, value)); + }; + for (const auto& field : k_statistics_fields) { if (!(field.flags & FLAG_NEVER)) { - lines.push_back( - FMT("{}\t{}\n", field.id, m_counters.get(field.statistic))); + add_line(field.id, m_counters.get(field.statistic)); } } + add_line("max_cache_size_kibibyte", config.max_size() / 1024); + add_line("max_files_in_cache", config.max_files()); + std::sort(lines.begin(), lines.end()); return util::join(lines, ""); } diff --git a/src/core/Statistics.hpp b/src/core/Statistics.hpp index fcf27afcf..b2deab712 100644 --- a/src/core/Statistics.hpp +++ b/src/core/Statistics.hpp @@ -47,7 +47,8 @@ public: // Format cache statistics in machine-readable format. std::string - format_machine_readable(const util::TimePoint& last_updated) const; + format_machine_readable(const Config& config, + const util::TimePoint& last_updated) const; const StatisticsCounters& counters() const; diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp index 2233962b0..312a17906 100644 --- a/src/core/mainoptions.cpp +++ b/src/core/mainoptions.cpp @@ -638,7 +638,8 @@ process_main_options(int argc, const char* const* argv) const auto [counters, last_updated] = storage::local::LocalStorage(config).get_all_statistics(); Statistics statistics(counters); - PRINT_RAW(stdout, statistics.format_machine_readable(last_updated)); + PRINT_RAW(stdout, + statistics.format_machine_readable(config, last_updated)); break; }