X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=disk_space_estimator.cpp;h=86e5e877f65aeaad39cd7423cc3c0577ed499a94;hb=fa54f2630c56a1df0046923d6a77b1bd58abf240;hp=1cb7d6fcfe10f5e10b7fc699e52467d8a7d49282;hpb=b561d43a60201395f1354a585aa37670eda45883;p=nageru diff --git a/disk_space_estimator.cpp b/disk_space_estimator.cpp index 1cb7d6f..86e5e87 100644 --- a/disk_space_estimator.cpp +++ b/disk_space_estimator.cpp @@ -1,14 +1,17 @@ +#include "disk_space_estimator.h" + +#include #include -#include -#include -#include +#include +#include -#include "disk_space_estimator.h" +#include "metrics.h" #include "timebase.h" DiskSpaceEstimator::DiskSpaceEstimator(DiskSpaceEstimator::callback_t callback) : callback(callback) { + global_metrics.add("disk_free_bytes", &metric_disk_free_bytes, Metrics::TYPE_GAUGE); } void DiskSpaceEstimator::report_write(const std::string &filename, uint64_t pts) @@ -40,12 +43,19 @@ void DiskSpaceEstimator::report_write(const std::string &filename, uint64_t pts) return; } + off_t free_bytes = off_t(fst.f_bavail) * fst.f_frsize; + metric_disk_free_bytes = free_bytes; + if (!measure_points.empty()) { - off_t free_bytes = off_t(fst.f_bavail) * fst.f_frsize; double bytes_per_second = double(st.st_size - measure_points.front().size) / (pts - measure_points.front().pts) * TIMEBASE; double seconds_left = free_bytes / bytes_per_second; - callback(free_bytes, seconds_left); + + // Only report every second, since updating the UI can be expensive. + if (last_pts_reported == 0 || pts - last_pts_reported >= TIMEBASE) { + callback(free_bytes, seconds_left); + last_pts_reported = pts; + } } measure_points.push_back({ pts, st.st_size });