Increase frequency of progres updates on long jobs (#900).
authorCarl Hetherington <cth@carlh.net>
Wed, 29 Jun 2016 15:33:50 +0000 (16:33 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 29 Jun 2016 15:33:50 +0000 (16:33 +0100)
ChangeLog
src/lib/job.cc
src/lib/job.h

index 6442b5633ee75361fd86612eebcf8cddfe75800a..6d760643db33d8b352105a70cf231c729e6abacc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-06-29  Carl Hetherington  <cth@carlh.net>
 
+       * Increase frequency of progress reporting on long
+       encodes (#900).
+
        * Obey specified colour conversion when previewing
        RGB and XYZ JPEG2000 files.
 
index ba91debb79f7565e956196604468ec52985b5610..0699c532c0fa4c69582bf954efa194b9b1ebcce4 100644 (file)
@@ -270,9 +270,19 @@ Job::elapsed_time () const
 void
 Job::set_progress (float p, bool force)
 {
-       if (!force && fabs (p - progress().get_value_or(0)) < 0.01) {
-               /* Calm excessive progress reporting */
-               return;
+       if (!force) {
+               /* Check for excessively frequent progress reporting */
+               boost::mutex::scoped_lock lm (_progress_mutex);
+               struct timeval now;
+               gettimeofday (&now, 0);
+               if (_last_progress_update && _last_progress_update->tv_sec > 0) {
+                       double const elapsed = (now.tv_sec + now.tv_usec / 1000000.0)
+                               - (_last_progress_update->tv_sec + _last_progress_update->tv_usec / 1000000.0);
+                       if (elapsed < 0.5) {
+                               return;
+                       }
+               }
+               _last_progress_update = now;
        }
 
        set_progress_common (p);
index a6777bc449e4a805c3db74d72c6c9d25938bba8e..7bc051142c5507802d022c479c03befadd22b911 100644 (file)
@@ -125,9 +125,10 @@ private:
        time_t _start_time;
        std::string _sub_name;
 
-       /** mutex for _progress */
+       /** mutex for _progress and _last_progress_update */
        mutable boost::mutex _progress_mutex;
        boost::optional<float> _progress;
+       boost::optional<struct timeval> _last_progress_update;
 
        /** condition to signal changes to pause/resume so that we know when to wake;
            this could be a general _state_change if it made more sense.