X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjob.cc;h=b316cddf7fa2740af8ff0de774d5a425af66107d;hb=ecb39d0ec32af217a7490935323083cfb376244a;hp=ba91debb79f7565e956196604468ec52985b5610;hpb=01884ed880e5519bd9d37db882216a81dfafdf8b;p=dcpomatic.git diff --git a/src/lib/job.cc b/src/lib/job.cc index ba91debb7..b316cddf7 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -52,6 +52,7 @@ Job::Job (shared_ptr film) , _thread (0) , _state (NEW) , _start_time (0) + , _sub_start_time (0) , _progress (0) , _ran_for (0) { @@ -81,6 +82,7 @@ Job::start () { set_state (RUNNING); _start_time = time (0); + _sub_start_time = time (0); _thread = new boost::thread (boost::bind (&Job::run_wrapper, this)); } @@ -242,7 +244,7 @@ Job::set_state (State s) _state = s; if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) { - _ran_for = elapsed_time (); + _ran_for = time(0) - _start_time; finished = true; _sub_name.clear (); } @@ -255,13 +257,13 @@ Job::set_state (State s) /** @return DCPTime (in seconds) that this sub-job has been running */ int -Job::elapsed_time () const +Job::elapsed_sub_time () const { - if (_start_time == 0) { + if (_sub_start_time == 0) { return 0; } - return time (0) - _start_time; + return time (0) - _sub_start_time; } /** Set the progress of the current part of the job. @@ -270,9 +272,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); @@ -314,6 +326,7 @@ Job::sub (string n) } set_progress (0, true); + _sub_start_time = time (0); } string @@ -360,7 +373,7 @@ string Job::status () const { optional p = progress (); - int const t = elapsed_time (); + int const t = elapsed_sub_time (); int const r = remaining_time (); SafeStringStream s; @@ -417,10 +430,10 @@ int Job::remaining_time () const { if (progress().get_value_or(0) == 0) { - return elapsed_time (); + return elapsed_sub_time (); } - return elapsed_time() / progress().get() - elapsed_time(); + return elapsed_sub_time() / progress().get() - elapsed_sub_time(); } void