From: Joel Rosdahl Date: Sun, 8 Aug 2021 17:00:22 +0000 (+0200) Subject: feat: Sort output of --print-stats X-Git-Tag: v4.4~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75d2a1916ec30fb2ab84f2d0d0edd8ee421b2957;p=thirdparty%2Fccache.git feat: Sort output of --print-stats --- diff --git a/src/core/Statistics.cpp b/src/core/Statistics.cpp index 61014df66..6ff89afcc 100644 --- a/src/core/Statistics.cpp +++ b/src/core/Statistics.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace core { @@ -266,19 +267,20 @@ Statistics::format_config_footer(const Config& config) std::string Statistics::format_machine_readable(const time_t last_updated) const { - std::string result; + std::vector lines; - result += FMT("stats_updated_timestamp\t{}\n", last_updated); + lines.push_back(FMT("stats_updated_timestamp\t{}\n", last_updated)); for (size_t i = 0; k_statistics_fields[i].message; i++) { if (!(k_statistics_fields[i].flags & FLAG_NEVER)) { - result += FMT("{}\t{}\n", - k_statistics_fields[i].id, - m_counters.get(k_statistics_fields[i].statistic)); + lines.push_back(FMT("{}\t{}\n", + k_statistics_fields[i].id, + m_counters.get(k_statistics_fields[i].statistic))); } } - return result; + std::sort(lines.begin(), lines.end()); + return util::join(lines, ""); } std::unordered_map