"Failed to store {} as raw file {}: {}", path, raw_file, e.what());
}
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.increment(Statistic::cache_size_kibibyte, size_delta);
- m_ctx.counter_updates.increment(Statistic::files_in_cache, files_delta);
+ m_ctx.counter_updates.increment(
+ Statistic::cache_size_kibibyte,
+ Util::size_change_kibibyte(old_stat, new_stat));
+ m_ctx.counter_updates.increment(Statistic::files_in_cache,
+ (new_stat ? 1 : 0) - (old_stat ? 1 : 0));
}
} // namespace Result
// Set environment variable `name` to `value`.
void setenv(const std::string& name, const std::string& value);
+// Return size change in KiB between `old_stat` and `new_stat`.
+inline int64_t
+size_change_kibibyte(const Stat& old_stat, const Stat& new_stat)
+{
+ return (static_cast<int64_t>(new_stat.size_on_disk())
+ - static_cast<int64_t>(old_stat.size_on_disk()))
+ / 1024;
+}
+
// Split `input` into words at any of the characters listed in `separators`.
// These words are a view into `input`; empty words are omitted. `separators`
// must neither be the empty string nor a nullptr.
log("Failed to add result name to {}", ctx.manifest_path());
} else {
const auto st = Stat::stat(ctx.manifest_path(), Stat::OnError::log);
-
- const int64_t size_delta_kibibyte =
- (st.size_on_disk() - old_st.size_on_disk()) / 1024;
+ const int64_t size_delta_kibibyte = Util::size_change_kibibyte(old_st, st);
const int64_t files_delta = !old_st && st ? 1 : 0;
if (ctx.stats_file() == ctx.manifest_stats_file()) {
if (!new_dest_stat) {
throw Failure(Statistic::internal_error);
}
- const auto size_delta =
- (new_dest_stat.size_on_disk() - orig_dest_stat.size_on_disk()) / 1024;
- ctx.counter_updates.increment(Statistic::cache_size_kibibyte, size_delta);
+ ctx.counter_updates.increment(
+ Statistic::cache_size_kibibyte,
+ Util::size_change_kibibyte(orig_dest_stat, new_dest_stat));
ctx.counter_updates.increment(Statistic::files_in_cache,
orig_dest_stat ? 0 : 1);
atomic_new_file.commit();
auto new_stat = Stat::stat(cache_file.path(), Stat::OnError::log);
- const uint64_t size_delta =
- (new_stat.size_on_disk() - old_stat.size_on_disk()) / 1024;
Statistics::update(stats_file, [=](Counters& cs) {
- cs.increment(Statistic::cache_size_kibibyte, size_delta);
+ cs.increment(Statistic::cache_size_kibibyte,
+ Util::size_change_kibibyte(old_stat, new_stat));
});
statistics.update(content_size, old_stat.size(), new_stat.size(), 0);