From: James Turner Date: Thu, 24 Oct 2013 22:35:34 +0000 (+0100) Subject: Add total bytes downloaded tracking. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d896e71ae91009e19a3a490920684209a7eec2c0;p=simgear.git Add total bytes downloaded tracking. --- diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index 4cc93f2f..1686fb21 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -87,6 +87,7 @@ public: SGTimeStamp timeTransferSample; unsigned int bytesTransferred; unsigned int lastTransferRate; + uint64_t totalBytesDownloaded; }; class Connection : public NetChat @@ -603,6 +604,7 @@ Client::Client() : d->bytesTransferred = 0; d->lastTransferRate = 0; d->timeTransferSample.stamp(); + d->totalBytesDownloaded = 0; setUserAgent("SimGear-" SG_STRINGIZE(SIMGEAR_VERSION)); } @@ -784,6 +786,7 @@ bool Client::hasActiveRequests() const void Client::receivedBytes(unsigned int count) { d->bytesTransferred += count; + d->totalBytesDownloaded += count; } unsigned int Client::transferRateBytesPerSec() const @@ -812,6 +815,11 @@ unsigned int Client::transferRateBytesPerSec() const return smoothed; } +uint64_t Client::totalBytesDownloaded() const +{ + return d->totalBytesDownloaded; +} + } // of namespace HTTP } // of namespace simgear diff --git a/simgear/io/HTTPClient.hxx b/simgear/io/HTTPClient.hxx index 7f19d95a..0831d8ae 100644 --- a/simgear/io/HTTPClient.hxx +++ b/simgear/io/HTTPClient.hxx @@ -25,6 +25,7 @@ #define SG_HTTP_CLIENT_HXX #include // for std::auto_ptr +#include // for uint_64t #include @@ -73,6 +74,12 @@ public: * suitable for user feedback and rough profiling, nothing more. */ unsigned int transferRateBytesPerSec() const; + + /** + * total bytes downloaded by this HTTP client, for bandwidth usage + * monitoring + */ + uint64_t totalBytesDownloaded() const; private: void requestFinished(Connection* con); diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index 38cd0c96..afe89639 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -243,6 +243,9 @@ public: volatile int _allowed_errors; volatile int _cache_hits; volatile int _transfer_rate; + // kbytes, not bytes, because bytes might overflow 2^31 + volatile int _total_kb_downloaded; + private: virtual void run(); @@ -293,6 +296,7 @@ SGTerraSync::SvnThread::SvnThread() : _allowed_errors(6), _cache_hits(0), _transfer_rate(0), + _total_kb_downloaded(0), _use_built_in(true), _is_dirty(false), _stop(false), @@ -609,6 +613,9 @@ void SGTerraSync::SvnThread::runInternal() while (!_stop) { _http.update(100); _transfer_rate = _http.transferRateBytesPerSec(); + // convert from bytes to kbytes + _total_kb_downloaded = static_cast(_http.totalBytesDownloaded() / 1024); + if (_stop) break; @@ -835,6 +842,10 @@ void SGTerraSync::bind() _tiedProperties.Tie( _terraRoot->getNode("cache-hits", true), (int*) &_svnThread->_cache_hits ); _tiedProperties.Tie( _terraRoot->getNode("transfer-rate-bytes-sec", true), (int*) &_svnThread->_transfer_rate ); + // use kbytes here because propety doesn't support 64-bit and we might conceivably + // download more than 2G in a single session + _tiedProperties.Tie( _terraRoot->getNode("downloaded-kbytes", true), (int*) &_svnThread->_total_kb_downloaded ); + _terraRoot->getNode("busy", true)->setAttribute(SGPropertyNode::WRITE,false); _terraRoot->getNode("active", true)->setAttribute(SGPropertyNode::WRITE,false); _terraRoot->getNode("update-count", true)->setAttribute(SGPropertyNode::WRITE,false);