diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-12-21 13:36:44 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-12-21 13:36:44 +0000 |
commit | 9a18a4c09cc32e5ac3668c884a600136dfd97779 (patch) | |
tree | 9856b3a72695a0e9be5e17dbe1e632c1de0fe145 /lib | |
parent | 0c910b30670b4095670e10b356b678dc630ffacd (diff) |
Fix computation of fractional second part of ShortSleep().
Reduce precision in log messages from microseconds to milliseconds.
Log the amount of time actually slept in ShortSleep().
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common/BoxTime.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp index f62b1c35..78269def 100644 --- a/lib/common/BoxTime.cpp +++ b/lib/common/BoxTime.cpp @@ -83,7 +83,7 @@ std::string FormatTime(box_time_t time, bool includeDate, bool showMicros) if (showMicros) { - buf << "." << std::setw(6) << micros; + buf << "." << std::setw(3) << (int)(micros / 1000); } } else @@ -108,8 +108,7 @@ void ShortSleep(box_time_t duration, bool logDuration) { if(logDuration) { - BOX_TRACE("Sleeping for " << BoxTimeToMicroSeconds(duration) << - " microseconds"); + BOX_TRACE("Sleeping for " << BOX_FORMAT_MICROSECONDS(duration)); } #ifdef WIN32 @@ -118,7 +117,9 @@ void ShortSleep(box_time_t duration, bool logDuration) struct timespec ts; memset(&ts, 0, sizeof(ts)); ts.tv_sec = duration / MICRO_SEC_IN_SEC; - ts.tv_nsec = duration % MICRO_SEC_IN_SEC; + ts.tv_nsec = (duration % MICRO_SEC_IN_SEC) * 1000; + + box_time_t start_time = GetCurrentBoxTime(); while (nanosleep(&ts, &ts) == -1 && errno == EINTR) { @@ -140,6 +141,10 @@ void ShortSleep(box_time_t duration, bool logDuration) BOX_TRACE("nanosleep interrupted with " << remain_ns << " nanosecs remaining, sleeping again"); } + + box_time_t sleep_time = GetCurrentBoxTime() - start_time; + BOX_TRACE("Actually slept for " << BOX_FORMAT_MICROSECONDS(sleep_time) << + ", was aiming for " << BOX_FORMAT_MICROSECONDS(duration)); #endif } |