Use A2_DELTA_MILLIS for timing critical code.

pull/1/head
Tatsuhiro Tsujikawa 2011-03-27 20:54:51 +09:00
parent a4ddec44d1
commit 891c9e60ac
5 changed files with 12 additions and 12 deletions

View File

@ -242,7 +242,7 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval, bool humanReadable):
void void
ConsoleStatCalc::calculateStat(const DownloadEngine* e) ConsoleStatCalc::calculateStat(const DownloadEngine* e)
{ {
if(cp_.differenceInMillis(global::wallclock) < 900) { if(cp_.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS < 1000) {
return; return;
} }
cp_ = global::wallclock; cp_ = global::wallclock;
@ -271,7 +271,8 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
std::ostringstream o; std::ostringstream o;
if(e->getRequestGroupMan()->countRequestGroup() > 0) { if(e->getRequestGroupMan()->countRequestGroup() > 0) {
if((summaryInterval_ > 0) && if((summaryInterval_ > 0) &&
lastSummaryNotified_.difference(global::wallclock) >= summaryInterval_) { lastSummaryNotified_.differenceInMillis(global::wallclock)+
A2_DELTA_MILLIS >= summaryInterval_*1000) {
lastSummaryNotified_ = global::wallclock; lastSummaryNotified_ = global::wallclock;
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e, printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
sizeFormatter); sizeFormatter);

View File

@ -246,7 +246,8 @@ TransferStat calculateStatFor(const SharedHandle<Peer>& peer)
TransferStat DefaultPeerStorage::calculateStat() TransferStat DefaultPeerStorage::calculateStat()
{ {
TransferStat stat; TransferStat stat;
if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock) >= 250) { if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock)+
A2_DELTA_MILLIS >= 250) {
A2_LOG_DEBUG("Updating TransferStat of PeerStorage"); A2_LOG_DEBUG("Updating TransferStat of PeerStorage");
lastTransferStatMapUpdated_ = global::wallclock; lastTransferStatMapUpdated_ = global::wallclock;
peerTransferStatMap_.clear(); peerTransferStatMap_.clear();

View File

@ -141,13 +141,6 @@ void executeCommand(std::deque<Command*>& commands,
} }
} // namespace } // namespace
namespace {
// Rounding error in millis
const int A2_DELTA = 10;
} // namespace
void DownloadEngine::run() void DownloadEngine::run()
{ {
Timer cp; Timer cp;
@ -155,7 +148,8 @@ void DownloadEngine::run()
while(!commands_.empty() || !routineCommands_.empty()) { while(!commands_.empty() || !routineCommands_.empty()) {
global::wallclock.reset(); global::wallclock.reset();
calculateStatistics(); calculateStatistics();
if(cp.differenceInMillis(global::wallclock) >= refreshInterval_-A2_DELTA) { if(cp.differenceInMillis(global::wallclock)+A2_DELTA_MILLIS >=
refreshInterval_) {
refreshInterval_ = DEFAULT_REFRESH_INTERVAL; refreshInterval_ = DEFAULT_REFRESH_INTERVAL;
cp = global::wallclock; cp = global::wallclock;
executeCommand(commands_, Command::STATUS_ALL); executeCommand(commands_, Command::STATUS_ALL);

View File

@ -404,7 +404,8 @@ void SegmentMan::updateFastestPeerStat(const SharedHandle<PeerStat>& peerStat)
unsigned int SegmentMan::calculateDownloadSpeed() unsigned int SegmentMan::calculateDownloadSpeed()
{ {
unsigned int speed = 0; unsigned int speed = 0;
if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock) >= 250){ if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock)+
A2_DELTA_MILLIS >= 250){
lastPeerStatDlspdMapUpdated_ = global::wallclock; lastPeerStatDlspdMapUpdated_ = global::wallclock;
peerStatDlspdMap_.clear(); peerStatDlspdMap_.clear();
for(std::vector<SharedHandle<PeerStat> >::const_iterator i = for(std::vector<SharedHandle<PeerStat> >::const_iterator i =

View File

@ -75,4 +75,7 @@
# endif // !__MINGW32__ # endif // !__MINGW32__
#endif // !HAVE_CLOCK_GETTIME #endif // !HAVE_CLOCK_GETTIME
// Rounding error in millis
#define A2_DELTA_MILLIS 10
#endif // D_A2TIME_H #endif // D_A2TIME_H