From 891c9e60ac3c6687af02de90eae818221c7c44f3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 27 Mar 2011 20:54:51 +0900 Subject: [PATCH] Use A2_DELTA_MILLIS for timing critical code. --- src/ConsoleStatCalc.cc | 5 +++-- src/DefaultPeerStorage.cc | 3 ++- src/DownloadEngine.cc | 10 ++-------- src/SegmentMan.cc | 3 ++- src/a2time.h | 3 +++ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index df5fe404..601da994 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -242,7 +242,7 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval, bool humanReadable): void ConsoleStatCalc::calculateStat(const DownloadEngine* e) { - if(cp_.differenceInMillis(global::wallclock) < 900) { + if(cp_.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS < 1000) { return; } cp_ = global::wallclock; @@ -271,7 +271,8 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e) std::ostringstream o; if(e->getRequestGroupMan()->countRequestGroup() > 0) { if((summaryInterval_ > 0) && - lastSummaryNotified_.difference(global::wallclock) >= summaryInterval_) { + lastSummaryNotified_.differenceInMillis(global::wallclock)+ + A2_DELTA_MILLIS >= summaryInterval_*1000) { lastSummaryNotified_ = global::wallclock; printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e, sizeFormatter); diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index 8c8141e9..c06c262d 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -246,7 +246,8 @@ TransferStat calculateStatFor(const SharedHandle& peer) TransferStat DefaultPeerStorage::calculateStat() { TransferStat stat; - if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock) >= 250) { + if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock)+ + A2_DELTA_MILLIS >= 250) { A2_LOG_DEBUG("Updating TransferStat of PeerStorage"); lastTransferStatMapUpdated_ = global::wallclock; peerTransferStatMap_.clear(); diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 7738701c..a18e36ad 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -141,13 +141,6 @@ void executeCommand(std::deque& commands, } } // namespace -namespace { - -// Rounding error in millis -const int A2_DELTA = 10; - -} // namespace - void DownloadEngine::run() { Timer cp; @@ -155,7 +148,8 @@ void DownloadEngine::run() while(!commands_.empty() || !routineCommands_.empty()) { global::wallclock.reset(); calculateStatistics(); - if(cp.differenceInMillis(global::wallclock) >= refreshInterval_-A2_DELTA) { + if(cp.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS >= + refreshInterval_) { refreshInterval_ = DEFAULT_REFRESH_INTERVAL; cp = global::wallclock; executeCommand(commands_, Command::STATUS_ALL); diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc index 15048257..dcc04334 100644 --- a/src/SegmentMan.cc +++ b/src/SegmentMan.cc @@ -404,7 +404,8 @@ void SegmentMan::updateFastestPeerStat(const SharedHandle& peerStat) unsigned int SegmentMan::calculateDownloadSpeed() { unsigned int speed = 0; - if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock) >= 250){ + if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock)+ + A2_DELTA_MILLIS >= 250){ lastPeerStatDlspdMapUpdated_ = global::wallclock; peerStatDlspdMap_.clear(); for(std::vector >::const_iterator i = diff --git a/src/a2time.h b/src/a2time.h index 86c94224..a6a58e35 100644 --- a/src/a2time.h +++ b/src/a2time.h @@ -75,4 +75,7 @@ # endif // !__MINGW32__ #endif // !HAVE_CLOCK_GETTIME +// Rounding error in millis +#define A2_DELTA_MILLIS 10 + #endif // D_A2TIME_H