Result::Writer::write_raw_file_entry(const std::string& path,
uint32_t entry_number)
{
- auto raw_file = get_raw_file_path(m_result_path, entry_number);
- auto old_stat = Stat::stat(raw_file);
+ const auto raw_file = get_raw_file_path(m_result_path, entry_number);
+ const auto old_stat = Stat::stat(raw_file);
try {
Util::clone_hard_link_or_copy_file(m_ctx, path, raw_file, true);
} catch (Error& e) {
throw Error(
"Failed to store {} as raw file {}: {}", path, raw_file, e.what());
}
- auto new_stat = Stat::stat(raw_file);
- stats_update_size(m_ctx.counter_updates,
- new_stat.size_on_disk() - old_stat.size_on_disk(),
- (new_stat ? 1 : 0) - (old_stat ? 1 : 0));
+ const auto new_stat = Stat::stat(raw_file);
+ const auto size_delta =
+ (new_stat.size_on_disk() - old_stat.size_on_disk()) / 1024;
+ const auto files_delta = (new_stat ? 1 : 0) - (old_stat ? 1 : 0);
+ m_ctx.counter_updates[Statistic::cache_size_kibibyte] += size_delta;
+ m_ctx.counter_updates[Statistic::files_in_cache] += files_delta;
}
} // namespace Result
save_timestamp)) {
log("Failed to add result name to {}", ctx.manifest_path());
} else {
- auto st = Stat::stat(ctx.manifest_path(), Stat::OnError::log);
+ const auto st = Stat::stat(ctx.manifest_path(), Stat::OnError::log);
- int64_t size_delta = st.size_on_disk() - old_st.size_on_disk();
- int nof_files_delta = !old_st && st ? 1 : 0;
+ const int64_t size_delta =
+ (st.size_on_disk() - old_st.size_on_disk()) / 1024;
+ const int64_t files_delta = !old_st && st ? 1 : 0;
if (ctx.stats_file() == ctx.manifest_stats_file()) {
- stats_update_size(ctx.counter_updates, size_delta, nof_files_delta);
+ ctx.counter_updates[Statistic::cache_size_kibibyte] += size_delta;
+ ctx.counter_updates[Statistic::files_in_cache] += files_delta;
} else {
Counters counters;
- stats_update_size(counters, size_delta, nof_files_delta);
+ counters[Statistic::cache_size_kibibyte] += size_delta;
+ counters[Statistic::files_in_cache] += files_delta;
stats_flush_to_file(ctx.config, ctx.manifest_stats_file(), counters);
}
}
if (!new_dest_stat) {
throw Failure(Statistic::internal_error);
}
- stats_update_size(ctx.counter_updates,
- new_dest_stat.size_on_disk()
- - orig_dest_stat.size_on_disk(),
- orig_dest_stat ? 0 : 1);
+ 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;
MTR_END("file", "file_put");
atomic_new_file.commit();
auto new_stat = Stat::stat(cache_file.path(), Stat::OnError::log);
- size_t size_on_disk_delta = new_stat.size_on_disk() - old_stat.size_on_disk();
+ const size_t size_delta =
+ (new_stat.size_on_disk() - old_stat.size_on_disk()) / 1024;
if (ctx.stats_file() == stats_file) {
- stats_update_size(ctx.counter_updates, size_on_disk_delta, 0);
+ ctx.counter_updates[Statistic::cache_size_kibibyte] += size_delta;
} else {
Counters counters;
- stats_update_size(counters, size_on_disk_delta, 0);
+ counters[Statistic::cache_size_kibibyte] += size_delta;
stats_flush_to_file(ctx.config, stats_file, counters);
}
counters[Statistic::stats_zeroed_timestamp] = zero_timestamp;
}
-// Record that a number of bytes and files have been added to the cache. Size
-// is in bytes.
-void
-stats_update_size(Counters& counters, int64_t size, int files)
-{
- if (size == 0 && files == 0) {
- return;
- }
-
- counters[Statistic::cache_size_kibibyte] += size / 1024;
- counters[Statistic::files_in_cache] += files;
-}
-
// Read in the stats from one directory and add to the counters.
void
stats_read(const std::string& path, Counters& counters)
void stats_summary(const Context& ctx);
void stats_print(const Config& config);
-void stats_update_size(Counters& counters, int64_t size, int files);
void stats_get_obsolete_limits(const std::string& dir,
uint64_t* maxfiles,
uint64_t* maxsize);