summaryrefslogtreecommitdiff
path: root/src/DownloadContext.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-10-25 23:33:45 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-10-25 23:33:45 +0900
commit0ecfa19925453e3e4bf8ca947dc72a597654e401 (patch)
tree09e2a91ca926e58489bee5c4ba2ae3ba2ba102de /src/DownloadContext.cc
parent46bdaf0e8dae04d223d9b8b65ac80bc0773d8398 (diff)
Reworked download/upload statistics calculation
The old implementation calculates download/upload statistics for a RequestGroup by summing up all PeerStat objects. For global statistics, those are summed together. This clearly incurs runtime penalty and we introduced some kind of caching which updates statistics every 250ms but it did not work right. This change removes all these aggregation code, and instead makes RequestGroup and RequestGroupMan objects hold NetStat object and download/upload bytes are directly calculated by thier own NetStat. This is far more simplar than the old way and less runtime penalty and brings more accuracy.
Diffstat (limited to 'src/DownloadContext.cc')
-rw-r--r--src/DownloadContext.cc34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc
index dbc355ea..1191259a 100644
--- a/src/DownloadContext.cc
+++ b/src/DownloadContext.cc
@@ -43,6 +43,7 @@
#include "DlAbortEx.h"
#include "a2functional.h"
#include "Signature.h"
+#include "RequestGroupMan.h"
namespace aria2 {
@@ -52,8 +53,7 @@ DownloadContext::DownloadContext():
knowsTotalLength_(true),
ownerRequestGroup_(0),
attrs_(MAX_CTX_ATTR),
- downloadStartTime_(0),
- downloadStopTime_(downloadStartTime_),
+ downloadStopTime_(0),
acceptMetalink_(true) {}
DownloadContext::DownloadContext(int32_t pieceLength,
@@ -64,7 +64,6 @@ DownloadContext::DownloadContext(int32_t pieceLength,
knowsTotalLength_(true),
ownerRequestGroup_(0),
attrs_(MAX_CTX_ATTR),
- downloadStartTime_(0),
downloadStopTime_(0),
acceptMetalink_(true)
{
@@ -76,23 +75,20 @@ DownloadContext::~DownloadContext() {}
void DownloadContext::resetDownloadStartTime()
{
- downloadStartTime_ = global::wallclock();
downloadStopTime_.reset(0);
+ netStat_.downloadStart();
}
void DownloadContext::resetDownloadStopTime()
{
downloadStopTime_ = global::wallclock();
+ netStat_.downloadStop();
}
int64_t DownloadContext::calculateSessionTime() const
{
- if(downloadStopTime_ > downloadStartTime_) {
- return
- downloadStartTime_.differenceInMillis(downloadStopTime_);
- } else {
- return 0;
- }
+ const Timer& startTime = netStat_.getDownloadStartTime();
+ return startTime.differenceInMillis(downloadStopTime_);
}
SharedHandle<FileEntry>
@@ -283,4 +279,22 @@ void DownloadContext::setSignature(const SharedHandle<Signature>& signature)
signature_ = signature;
}
+void DownloadContext::updateDownloadLength(size_t bytes)
+{
+ netStat_.updateDownloadLength(bytes);
+ RequestGroupMan* rgman = ownerRequestGroup_->getRequestGroupMan();
+ if(rgman) {
+ rgman->getNetStat().updateDownloadLength(bytes);
+ }
+}
+
+void DownloadContext::updateUploadLength(size_t bytes)
+{
+ netStat_.updateUploadLength(bytes);
+ RequestGroupMan* rgman = ownerRequestGroup_->getRequestGroupMan();
+ if(rgman) {
+ rgman->getNetStat().updateUploadLength(bytes);
+ }
+}
+
} // namespace aria2