const int64_t files_delta = !old_st && st ? 1 : 0;
if (ctx.stats_file() == ctx.manifest_stats_file()) {
- ctx.counter_updates[Statistic::cache_size_kibibyte] += size_delta;
- ctx.counter_updates[Statistic::files_in_cache] += files_delta;
+ ctx.counter_updates.increment(Statistic::cache_size_kibibyte, size_delta);
+ ctx.counter_updates.increment(Statistic::files_in_cache, files_delta);
} else {
Counters counters;
- counters[Statistic::cache_size_kibibyte] += size_delta;
- counters[Statistic::files_in_cache] += files_delta;
+ counters.increment(Statistic::cache_size_kibibyte, size_delta);
+ counters.increment(Statistic::files_in_cache, files_delta);
stats_flush_to_file(ctx.config, ctx.manifest_stats_file(), counters);
}
}
}
const auto size_delta =
(new_dest_stat.size_on_disk() - orig_dest_stat.size_on_disk()) / 1024;
- ctx.counter_updates[Statistic::cache_size_kibibyte] += size_delta;
- ctx.counter_updates[Statistic::files_in_cache] += orig_dest_stat ? 0 : 1;
+ ctx.counter_updates.increment(Statistic::cache_size_kibibyte, size_delta);
+ ctx.counter_updates.increment(Statistic::files_in_cache,
+ orig_dest_stat ? 0 : 1);
MTR_END("file", "file_put");
try {
Statistic statistic = do_cache_compilation(*ctx, argv);
- ctx->counter_updates[statistic] += 1;
+ ctx->counter_updates.increment(statistic);
return EXIT_SUCCESS;
} catch (const Failure& e) {
if (e.statistic() != Statistic::none) {
- ctx->counter_updates[e.statistic()] += 1;
+ ctx->counter_updates.increment(e.statistic());
}
if (e.exit_code()) {
if (p2 == p) {
break;
}
- counters[static_cast<Statistic>(i)] += val;
+ counters.increment(static_cast<Statistic>(i), val);
i++;
p = p2;
}
{
AtomicFile file(path, AtomicFile::Mode::text);
for (size_t i = 0; i < counters.size(); ++i) {
- file.write(fmt::format("{}\n", counters[static_cast<Statistic>(i)]));
+ file.write(fmt::format("{}\n", counters.get(static_cast<Statistic>(i))));
}
try {
file.commit();
static double
stats_hit_rate(const Counters& counters)
{
- uint64_t direct = counters[Statistic::direct_cache_hit];
- uint64_t preprocessed = counters[Statistic::preprocessed_cache_hit];
+ uint64_t direct = counters.get(Statistic::direct_cache_hit);
+ uint64_t preprocessed = counters.get(Statistic::preprocessed_cache_hit);
uint64_t hit = direct + preprocessed;
- uint64_t miss = counters[Statistic::cache_miss];
+ uint64_t miss = counters.get(Statistic::cache_miss);
uint64_t total = hit + miss;
return total > 0 ? (100.0 * hit) / total : 0.0;
}
fname = fmt::format("{}/{:x}/stats", config.cache_dir(), dir);
}
- counters[Statistic::stats_zeroed_timestamp] = 0; // Don't add
+ counters.set(Statistic::stats_zeroed_timestamp, 0); // Don't add
stats_read(fname, counters);
zero_timestamp =
- std::max(counters[Statistic::stats_zeroed_timestamp], zero_timestamp);
+ std::max(counters.get(Statistic::stats_zeroed_timestamp), zero_timestamp);
auto st = Stat::stat(fname);
if (st && st.mtime() > *last_updated) {
*last_updated = st.mtime();
}
}
- counters[Statistic::stats_zeroed_timestamp] = zero_timestamp;
+ counters.set(Statistic::stats_zeroed_timestamp, zero_timestamp);
}
// Read in the stats from one directory and add to the counters.
if (!config.log_file().empty() || config.debug()) {
for (auto& field : k_statistics_fields) {
- if (updates[field.statistic] != 0 && !(field.flags & FLAG_NOZERO)) {
+ if (updates.get(field.statistic) != 0 && !(field.flags & FLAG_NOZERO)) {
log("Result: {}", field.message);
}
}
stats_read(sfile, counters);
for (size_t i = 0; i < static_cast<size_t>(Statistic::END); ++i) {
- counters[static_cast<Statistic>(i)] += updates[static_cast<Statistic>(i)];
+ counters.increment(static_cast<Statistic>(i),
+ updates.get(static_cast<Statistic>(i)));
}
stats_write(sfile, counters);
}
bool need_cleanup = false;
if (config.max_files() != 0
- && counters[Statistic::files_in_cache] > config.max_files() / 16) {
+ && counters.get(Statistic::files_in_cache) > config.max_files() / 16) {
log("Need to clean up {} since it holds {} files (limit: {} files)",
subdir,
- counters[Statistic::files_in_cache],
+ counters.get(Statistic::files_in_cache),
config.max_files() / 16);
need_cleanup = true;
}
if (config.max_size() != 0
- && counters[Statistic::cache_size_kibibyte]
+ && counters.get(Statistic::cache_size_kibibyte)
> config.max_size() / 1024 / 16) {
log("Need to clean up {} since it holds {} KiB (limit: {} KiB)",
subdir,
- counters[Statistic::cache_size_kibibyte],
+ counters.get(Statistic::cache_size_kibibyte),
config.max_size() / 1024 / 16);
need_cleanup = true;
}
if (k_statistics_fields[i].flags & FLAG_NEVER) {
continue;
}
- if (counters[statistic] == 0
+ if (counters.get(statistic) == 0
&& !(k_statistics_fields[i].flags & FLAG_ALWAYS)) {
continue;
}
std::string value;
if (k_statistics_fields[i].format) {
- value = k_statistics_fields[i].format(counters[statistic]);
+ value = k_statistics_fields[i].format(counters.get(statistic));
} else {
- value = fmt::format("{:8}", counters[statistic]);
+ value = fmt::format("{:8}", counters.get(statistic));
}
if (!value.empty()) {
fmt::print("{:31} {}\n", k_statistics_fields[i].message, value);
if (!(k_statistics_fields[i].flags & FLAG_NEVER)) {
fmt::print("{}\t{}\n",
k_statistics_fields[i].id,
- counters[k_statistics_fields[i].statistic]);
+ counters.get(k_statistics_fields[i].statistic));
}
}
}
stats_read(fname, counters);
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.set(k_statistics_fields[i].statistic, 0);
}
}
- counters[Statistic::stats_zeroed_timestamp] = timestamp;
+ counters.set(Statistic::stats_zeroed_timestamp, timestamp);
stats_write(fname, counters);
}
}
Counters counters;
std::string sname = dir + "/stats";
stats_read(sname, counters);
- *maxfiles = counters[Statistic::obsolete_max_files];
- *maxsize = counters[Statistic::obsolete_max_size] * 1024;
+ *maxfiles = counters.get(Statistic::obsolete_max_files);
+ *maxsize = counters.get(Statistic::obsolete_max_size) * 1024;
}
// Set the per-directory sizes.
Lockfile lock(statsfile);
if (lock.acquired()) {
stats_read(statsfile, counters);
- counters[Statistic::files_in_cache] = num_files;
- counters[Statistic::cache_size_kibibyte] = total_size / 1024;
+ counters.set(Statistic::files_in_cache, num_files);
+ counters.set(Statistic::cache_size_kibibyte, total_size / 1024);
stats_write(statsfile, counters);
}
}
Lockfile lock(statsfile);
if (lock.acquired()) {
stats_read(statsfile, counters);
- counters[Statistic::cleanups_performed] += count;
+ counters.increment(Statistic::cleanups_performed, count);
stats_write(statsfile, counters);
}
}