]> git.sesse.net Git - nageru/commitdiff
Only report disk space anew every second. Saves 20% CPU or so on the UI thread (!).
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Jun 2017 20:53:24 +0000 (22:53 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Jun 2017 20:53:24 +0000 (22:53 +0200)
disk_space_estimator.cpp
disk_space_estimator.h

index a1961057dc79257f4e1ecdebce95306f803ec507..86e5e877f65aeaad39cd7423cc3c0577ed499a94 100644 (file)
@@ -50,7 +50,12 @@ void DiskSpaceEstimator::report_write(const std::string &filename, uint64_t pts)
                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 });
index c5b63bfac22c25455bdf48e53ed61424f38c9853..73b392cc586e43c57c82fa4c6195d20d294c82bf 100644 (file)
@@ -44,6 +44,7 @@ private:
                off_t size;
        };
        std::deque<MeasurePoint> measure_points;
+       uint64_t last_pts_reported = 0;
 
        // Metrics.
        std::atomic<int64_t> metric_disk_free_bytes{-1};