Browse Source

Use A2_DELTA_MILLIS for timing critical code.

Tatsuhiro Tsujikawa 14 năm trước cách đây
mục cha
commit
891c9e60ac
5 tập tin đã thay đổi với 12 bổ sung12 xóa
  1. 3 2
      src/ConsoleStatCalc.cc
  2. 2 1
      src/DefaultPeerStorage.cc
  3. 2 8
      src/DownloadEngine.cc
  4. 2 1
      src/SegmentMan.cc
  5. 3 0
      src/a2time.h

+ 3 - 2
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);

+ 2 - 1
src/DefaultPeerStorage.cc

@@ -246,7 +246,8 @@ TransferStat calculateStatFor(const SharedHandle<Peer>& 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();

+ 2 - 8
src/DownloadEngine.cc

@@ -141,13 +141,6 @@ void executeCommand(std::deque<Command*>& 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);

+ 2 - 1
src/SegmentMan.cc

@@ -404,7 +404,8 @@ void SegmentMan::updateFastestPeerStat(const SharedHandle<PeerStat>& 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<SharedHandle<PeerStat> >::const_iterator i =

+ 3 - 0
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