diff --git a/ChangeLog b/ChangeLog index 36a19961..81d47570 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-11-11 Tatsuhiro Tsujikawa + + Show an average download speed in Download results. + * src/BtFileAllocationEntry.cc + * src/DefaultPieceStorage.cc + * src/DownloadContext.cc + * src/DownloadContext.h + * src/DownloadResult.h + * src/RequestGroup.cc + * src/RequestGroupMan.cc + * src/StreamFileAllocationEntry.cc + 2008-11-11 Tatsuhiro Tsujikawa Fixed the bug that metalink file is not processed if Content-Type diff --git a/src/BtFileAllocationEntry.cc b/src/BtFileAllocationEntry.cc index 7d0b67cd..1c9c1112 100644 --- a/src/BtFileAllocationEntry.cc +++ b/src/BtFileAllocationEntry.cc @@ -33,11 +33,14 @@ */ /* copyright --> */ #include "BtFileAllocationEntry.h" + +#include + #include "BtSetup.h" #include "RequestGroup.h" #include "Command.h" #include "DownloadEngine.h" -#include +#include "DownloadContext.h" namespace aria2 { @@ -51,6 +54,7 @@ void BtFileAllocationEntry::prepareForNextAction(std::deque& commands, { BtSetup().setup(commands, _requestGroup, e, e->option); if(!_requestGroup->downloadFinished()) { + _requestGroup->getDownloadContext()->resetDownloadStartTime(); _requestGroup->createNextCommandWithAdj(commands, e, 0); } } diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 4f0b36c3..85c7c6f0 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -335,6 +335,7 @@ void DefaultPieceStorage::completePiece(const PieceHandle& piece) bitfieldMan->unsetUseBit(piece->getIndex()); addPieceStats(piece->getIndex()); if(downloadFinished()) { + downloadContext->resetDownloadStopTime(); diskAdaptor->onDownloadComplete(); if(isSelectiveDownloadingMode()) { logger->notice(MSG_SELECTIVE_DOWNLOAD_COMPLETED); diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index 1c40b096..1426b001 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -36,7 +36,10 @@ namespace aria2 { -DownloadContext::DownloadContext():_dir(".") {} +DownloadContext::DownloadContext(): + _dir("."), + _downloadStartTime(0), + _downloadStopTime(_downloadStartTime) {} DownloadContext::~DownloadContext() {} @@ -60,4 +63,24 @@ void DownloadContext::setSignature(const SharedHandle& signature) _signature = signature; } +void DownloadContext::resetDownloadStartTime() +{ + _downloadStartTime.reset(); +} + +void DownloadContext::resetDownloadStopTime() +{ + _downloadStopTime.reset(); +} + +int64_t DownloadContext::calculateSessionTime() const +{ + if(_downloadStopTime.isNewer(_downloadStartTime)) { + return + _downloadStopTime.getTimeInMillis()-_downloadStartTime.getTimeInMillis(); + } else { + return 0; + } +} + } // namespace aria2 diff --git a/src/DownloadContext.h b/src/DownloadContext.h index 9e4f0711..179f159c 100644 --- a/src/DownloadContext.h +++ b/src/DownloadContext.h @@ -36,11 +36,14 @@ #define _D_DOWNLOAD_CONTEXT_H_ #include "common.h" -#include "SharedHandle.h" -#include "Signature.h" + #include #include +#include "SharedHandle.h" +#include "Signature.h" +#include "TimeA2.h" + namespace aria2 { class FileEntry; @@ -51,8 +54,11 @@ protected: std::string _dir; private: - SharedHandle _signature; + Time _downloadStartTime; + Time _downloadStopTime; + + SharedHandle _signature; public: DownloadContext(); @@ -98,6 +104,12 @@ public: SharedHandle getSignature() const; void setSignature(const SharedHandle& signature); + + void resetDownloadStartTime(); + + void resetDownloadStopTime(); + + int64_t calculateSessionTime() const; }; typedef SharedHandle DownloadContextHandle; diff --git a/src/DownloadResult.h b/src/DownloadResult.h index c8fc13d9..92fe1b84 100644 --- a/src/DownloadResult.h +++ b/src/DownloadResult.h @@ -60,6 +60,10 @@ public: size_t numUri; + uint64_t sessionDownloadLength; + + int64_t sessionTime; + RESULT result; DownloadResult(int32_t gid, @@ -67,12 +71,16 @@ public: uint64_t totalLength, const std::string& uri, size_t numUri, + uint64_t sessionDownloadLength, + int64_t sessionTime, RESULT result): gid(gid), filePath(filePath), totalLength(totalLength), uri(uri), numUri(numUri), + sessionDownloadLength(sessionDownloadLength), + sessionTime(sessionTime), result(result) {} }; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 4db4f21a..2124164f 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -877,15 +877,32 @@ DownloadResultHandle RequestGroup::createDownloadResult() const { std::deque uris; getURIs(uris); + + uint64_t sessionDownloadLength = 0; + +#ifdef ENABLE_BITTORRENT + if(!_peerStorage.isNull()) { + sessionDownloadLength = + _peerStorage->calculateStat().getSessionDownloadLength(); + } else +#endif // ENABLE_BITTORRENT + if(!_segmentMan.isNull()) { + sessionDownloadLength = + _segmentMan->calculateSessionDownloadLength(); + } + return - SharedHandle(new DownloadResult(_gid, - getFilePath(), - getTotalLength(), - uris.empty() ? A2STR::NIL:uris.front(), - uris.size(), - downloadFinished()? - DownloadResult::FINISHED : - DownloadResult::NOT_YET)); + SharedHandle + (new DownloadResult(_gid, + getFilePath(), + getTotalLength(), + uris.empty() ? A2STR::NIL:uris.front(), + uris.size(), + sessionDownloadLength, + _downloadContext->calculateSessionTime(), + downloadFinished()? + DownloadResult::FINISHED : + DownloadResult::NOT_YET)); } void RequestGroup::registerServerHost(const ServerHostHandle& serverHost) diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 4af5cff5..205374e9 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -33,6 +33,14 @@ */ /* copyright --> */ #include "RequestGroupMan.h" + +#include +#include +#include +#include +#include +#include + #include "BtProgressInfoFile.h" #include "RecoverableException.h" #include "RequestGroup.h" @@ -52,12 +60,7 @@ #include "Option.h" #include "prefs.h" #include "File.h" -#include -#include -#include -#include -#include -#include +#include "Util.h" namespace aria2 { @@ -384,8 +387,8 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const // ===+====+======================================================================= o << "\n" <<_("Download Results:") << "\n" - << "gid|stat|path/URI" << "\n" - << "===+====+======================================================================" << "\n"; + << "gid|stat|avg speed |path/URI" << "\n" + << "===+====+===========+==========================================================" << "\n"; int ok = 0; int err = 0; @@ -411,6 +414,12 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const status = MARK_OK; ++ok; } else { + // Since this RequestGroup is not processed by ProcessStoppedRequestGroup, + // its download stop time is not reseted. + // Reset download stop time and assign sessionTime here. + (*itr)->getDownloadContext()->resetDownloadStopTime(); + result->sessionTime = + (*itr)->getDownloadContext()->calculateSessionTime(); status = MARK_INPR; ++inpr; } @@ -437,7 +446,16 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con { std::stringstream o; o << std::setw(3) << downloadResult->gid << "|" - << std::setw(4) << status << "|"; + << std::setw(4) << status << "|" + << std::setw(11); + if(downloadResult->sessionTime > 0) { + o << Util::abbrevSize + (downloadResult->sessionDownloadLength*1000/downloadResult->sessionTime)+ + "B/s"; + } else { + o << "n/a"; + } + o << "|"; if(downloadResult->result == DownloadResult::FINISHED) { o << downloadResult->filePath; } else { diff --git a/src/StreamFileAllocationEntry.cc b/src/StreamFileAllocationEntry.cc index e9ba48a0..c152f6fb 100644 --- a/src/StreamFileAllocationEntry.cc +++ b/src/StreamFileAllocationEntry.cc @@ -42,6 +42,7 @@ #include "prefs.h" #include "RequestGroup.h" #include "InitiateConnectionCommandFactory.h" +#include "DownloadContext.h" namespace aria2 { @@ -57,6 +58,7 @@ StreamFileAllocationEntry::~StreamFileAllocationEntry() {} void StreamFileAllocationEntry::prepareForNextAction(std::deque& commands, DownloadEngine* e) { + _requestGroup->getDownloadContext()->resetDownloadStartTime(); if(_nextCommand) { // give _nextCommand a chance to execute in the next execution loop. _nextCommand->setStatus(Command::STATUS_ONESHOT_REALTIME);