mirror of https://github.com/aria2/aria2
2009-05-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added SEED to console output, which represents the number of seeders currently the client is connecting to. * src/ConsoleStatCalc.cc * src/ConsoleStatCalc.h * src/DownloadEngine.cc * src/NullStatCalc.h * src/StatCalc.hpull/1/head
parent
20e215047c
commit
579457eae0
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2009-05-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added SEED to console output, which represents the number of
|
||||||
|
seeders currently the client is connecting to.
|
||||||
|
* src/ConsoleStatCalc.cc
|
||||||
|
* src/ConsoleStatCalc.h
|
||||||
|
* src/DownloadEngine.cc
|
||||||
|
* src/NullStatCalc.h
|
||||||
|
* src/StatCalc.h
|
||||||
|
|
||||||
2009-05-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-05-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Added source filename(__FILE__) and line number(__LINE__) to
|
Added source filename(__FILE__) and line number(__LINE__) to
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
#include "DownloadEngine.h"
|
||||||
#include "RequestGroupMan.h"
|
#include "RequestGroupMan.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "FileAllocationMan.h"
|
#include "FileAllocationMan.h"
|
||||||
|
@ -58,11 +59,19 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "BtContext.h"
|
# include "BtContext.h"
|
||||||
|
# include "Peer.h"
|
||||||
|
# include "PeerStorage.h"
|
||||||
|
# include "BtRegistry.h"
|
||||||
|
# include "BtProgressInfoFile.h"
|
||||||
|
# include "BtRuntime.h"
|
||||||
|
# include "BtAnnounce.h"
|
||||||
|
# include "PieceStorage.h"
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
static void printProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg)
|
static void printProgress
|
||||||
|
(std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e)
|
||||||
{
|
{
|
||||||
TransferStat stat = rg->calculateStat();
|
TransferStat stat = rg->calculateStat();
|
||||||
unsigned int eta = 0;
|
unsigned int eta = 0;
|
||||||
|
@ -72,9 +81,12 @@ static void printProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg)
|
||||||
|
|
||||||
o << "["
|
o << "["
|
||||||
<< "#" << rg->getGID() << " ";
|
<< "#" << rg->getGID() << " ";
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(rg->downloadFinished() &&
|
SharedHandle<BtContext> btctx =
|
||||||
!dynamic_pointer_cast<BtContext>(rg->getDownloadContext()).isNull()) {
|
dynamic_pointer_cast<BtContext>(rg->getDownloadContext());
|
||||||
|
|
||||||
|
if(!btctx.isNull() && rg->downloadFinished()) {
|
||||||
o << "SEEDING" << "(" << "ratio:";
|
o << "SEEDING" << "(" << "ratio:";
|
||||||
if(rg->getCompletedLength() > 0) {
|
if(rg->getCompletedLength() > 0) {
|
||||||
o << std::fixed << std::setprecision(1)
|
o << std::fixed << std::setprecision(1)
|
||||||
|
@ -101,6 +113,17 @@ static void printProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg)
|
||||||
o << " "
|
o << " "
|
||||||
<< "CN:"
|
<< "CN:"
|
||||||
<< rg->getNumConnection();
|
<< rg->getNumConnection();
|
||||||
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
if(!btctx.isNull()) {
|
||||||
|
SharedHandle<PeerStorage> ps =
|
||||||
|
e->getBtRegistry()->getPeerStorage(btctx->getInfoHashAsString());
|
||||||
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
|
ps->getActivePeers(peers);
|
||||||
|
o << " " << "SEED:"
|
||||||
|
<< std::count_if(peers.begin(), peers.end(), mem_fun_sh(&Peer::isSeeder));
|
||||||
|
}
|
||||||
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
if(!rg->downloadFinished()) {
|
if(!rg->downloadFinished()) {
|
||||||
o << " "
|
o << " "
|
||||||
<< "SPD:"
|
<< "SPD:"
|
||||||
|
@ -124,20 +147,23 @@ class PrintSummary
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
size_t _cols;
|
size_t _cols;
|
||||||
|
const DownloadEngine* _e;
|
||||||
public:
|
public:
|
||||||
PrintSummary(size_t cols):_cols(cols) {}
|
PrintSummary(size_t cols, const DownloadEngine* e):_cols(cols), _e(e) {}
|
||||||
|
|
||||||
void operator()(const SharedHandle<RequestGroup>& rg)
|
void operator()(const SharedHandle<RequestGroup>& rg)
|
||||||
{
|
{
|
||||||
const char SEP_CHAR = '-';
|
const char SEP_CHAR = '-';
|
||||||
printProgress(std::cout, rg);
|
printProgress(std::cout, rg, _e);
|
||||||
std::cout << "\n"
|
std::cout << "\n"
|
||||||
<< "FILE: " << rg->getFilePath() << "\n"
|
<< "FILE: " << rg->getFilePath() << "\n"
|
||||||
<< std::setfill(SEP_CHAR) << std::setw(_cols) << SEP_CHAR << "\n";
|
<< std::setfill(SEP_CHAR) << std::setw(_cols) << SEP_CHAR << "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printProgressSummary(const std::deque<SharedHandle<RequestGroup> >& groups, size_t cols)
|
static void printProgressSummary
|
||||||
|
(const std::deque<SharedHandle<RequestGroup> >& groups, size_t cols,
|
||||||
|
const DownloadEngine* e)
|
||||||
{
|
{
|
||||||
const char SEP_CHAR = '=';
|
const char SEP_CHAR = '=';
|
||||||
time_t now;
|
time_t now;
|
||||||
|
@ -158,7 +184,7 @@ static void printProgressSummary(const std::deque<SharedHandle<RequestGroup> >&
|
||||||
}
|
}
|
||||||
std::cout << " *** " << "\n"
|
std::cout << " *** " << "\n"
|
||||||
<< std::setfill(SEP_CHAR) << std::setw(cols) << SEP_CHAR << "\n";
|
<< std::setfill(SEP_CHAR) << std::setw(cols) << SEP_CHAR << "\n";
|
||||||
std::for_each(groups.begin(), groups.end(), PrintSummary(cols));
|
std::for_each(groups.begin(), groups.end(), PrintSummary(cols, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval):
|
ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval):
|
||||||
|
@ -166,10 +192,7 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval):
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
ConsoleStatCalc::calculateStat
|
ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
(const RequestGroupManHandle& requestGroupMan,
|
|
||||||
const SharedHandle<FileAllocationMan>& fileAllocationMan,
|
|
||||||
const SharedHandle<CheckIntegrityMan>& checkIntegrityMan)
|
|
||||||
{
|
{
|
||||||
if(!_cp.elapsed(1)) {
|
if(!_cp.elapsed(1)) {
|
||||||
return;
|
return;
|
||||||
|
@ -188,35 +211,35 @@ ConsoleStatCalc::calculateStat
|
||||||
std::cout << '\r' << std::setfill(' ') << std::setw(cols) << ' ' << '\r';
|
std::cout << '\r' << std::setfill(' ') << std::setw(cols) << ' ' << '\r';
|
||||||
}
|
}
|
||||||
std::ostringstream o;
|
std::ostringstream o;
|
||||||
if(requestGroupMan->countRequestGroup() > 0) {
|
if(e->_requestGroupMan->countRequestGroup() > 0) {
|
||||||
if((_summaryInterval > 0) &&
|
if((_summaryInterval > 0) &&
|
||||||
_lastSummaryNotified.elapsed(_summaryInterval)) {
|
_lastSummaryNotified.elapsed(_summaryInterval)) {
|
||||||
_lastSummaryNotified.reset();
|
_lastSummaryNotified.reset();
|
||||||
printProgressSummary(requestGroupMan->getRequestGroups(), cols);
|
printProgressSummary(e->_requestGroupMan->getRequestGroups(), cols, e);
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestGroupHandle firstRequestGroup = requestGroupMan->getRequestGroup(0);
|
RequestGroupHandle firstRequestGroup = e->_requestGroupMan->getRequestGroup(0);
|
||||||
|
|
||||||
printProgress(o, firstRequestGroup);
|
printProgress(o, firstRequestGroup, e);
|
||||||
|
|
||||||
if(requestGroupMan->countRequestGroup() > 1) {
|
if(e->_requestGroupMan->countRequestGroup() > 1) {
|
||||||
o << "("
|
o << "("
|
||||||
<< requestGroupMan->countRequestGroup()-1
|
<< e->_requestGroupMan->countRequestGroup()-1
|
||||||
<< "more...)";
|
<< "more...)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(requestGroupMan->countRequestGroup() > 1 &&
|
if(e->_requestGroupMan->countRequestGroup() > 1 &&
|
||||||
!requestGroupMan->downloadFinished()) {
|
!e->_requestGroupMan->downloadFinished()) {
|
||||||
TransferStat stat = requestGroupMan->calculateStat();
|
TransferStat stat = e->_requestGroupMan->calculateStat();
|
||||||
o << " "
|
o << " "
|
||||||
<< "[TOTAL SPD:"
|
<< "[TOTAL SPD:"
|
||||||
<< std::fixed << std::setprecision(2) << stat.getDownloadSpeed()/1024.0 << "KiB/s" << "]";
|
<< std::fixed << std::setprecision(2) << stat.getDownloadSpeed()/1024.0 << "KiB/s" << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SharedHandle<FileAllocationEntry> entry=fileAllocationMan->getPickedEntry();
|
SharedHandle<FileAllocationEntry> entry=e->_fileAllocationMan->getPickedEntry();
|
||||||
if(!entry.isNull()) {
|
if(!entry.isNull()) {
|
||||||
o << " "
|
o << " "
|
||||||
<< "[FileAlloc:"
|
<< "[FileAlloc:"
|
||||||
|
@ -234,16 +257,16 @@ ConsoleStatCalc::calculateStat
|
||||||
}
|
}
|
||||||
o << "%)"
|
o << "%)"
|
||||||
<< "]";
|
<< "]";
|
||||||
if(fileAllocationMan->hasNext()) {
|
if(e->_fileAllocationMan->hasNext()) {
|
||||||
o << "("
|
o << "("
|
||||||
<< fileAllocationMan->countEntryInQueue()
|
<< e->_fileAllocationMan->countEntryInQueue()
|
||||||
<< "waiting...)";
|
<< "waiting...)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
{
|
{
|
||||||
CheckIntegrityEntryHandle entry = checkIntegrityMan->getPickedEntry();
|
CheckIntegrityEntryHandle entry = e->_checkIntegrityMan->getPickedEntry();
|
||||||
if(!entry.isNull()) {
|
if(!entry.isNull()) {
|
||||||
o << " "
|
o << " "
|
||||||
<< "[Checksum:"
|
<< "[Checksum:"
|
||||||
|
@ -257,9 +280,9 @@ ConsoleStatCalc::calculateStat
|
||||||
<< 100*entry->getCurrentLength()/entry->getTotalLength()
|
<< 100*entry->getCurrentLength()/entry->getTotalLength()
|
||||||
<< "%)"
|
<< "%)"
|
||||||
<< "]";
|
<< "]";
|
||||||
if(checkIntegrityMan->hasNext()) {
|
if(e->_checkIntegrityMan->hasNext()) {
|
||||||
o << "("
|
o << "("
|
||||||
<< checkIntegrityMan->countEntryInQueue()
|
<< e->_checkIntegrityMan->countEntryInQueue()
|
||||||
<< "waiting...)";
|
<< "waiting...)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,7 @@ public:
|
||||||
|
|
||||||
virtual ~ConsoleStatCalc() {}
|
virtual ~ConsoleStatCalc() {}
|
||||||
|
|
||||||
virtual void
|
virtual void calculateStat(const DownloadEngine* e);
|
||||||
calculateStat(const SharedHandle<RequestGroupMan>& requestGroupMan,
|
|
||||||
const SharedHandle<FileAllocationMan>& fileAllocationMan,
|
|
||||||
const SharedHandle<CheckIntegrityMan>& checkIntegrityMan);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<ConsoleStatCalc> ConsoleStatCalcHandle;
|
typedef SharedHandle<ConsoleStatCalc> ConsoleStatCalcHandle;
|
||||||
|
|
|
@ -191,7 +191,7 @@ bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket,
|
||||||
void DownloadEngine::calculateStatistics()
|
void DownloadEngine::calculateStatistics()
|
||||||
{
|
{
|
||||||
if(!_statCalc.isNull()) {
|
if(!_statCalc.isNull()) {
|
||||||
_statCalc->calculateStat(_requestGroupMan, _fileAllocationMan, _checkIntegrityMan);
|
_statCalc->calculateStat(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,7 @@ class NullStatCalc:public StatCalc {
|
||||||
public:
|
public:
|
||||||
virtual ~NullStatCalc() {}
|
virtual ~NullStatCalc() {}
|
||||||
|
|
||||||
virtual void
|
virtual void calculateStat(const DownloadEngine* e) {}
|
||||||
calculateStat(const SharedHandle<RequestGroupMan>& requestGroupMan,
|
|
||||||
const SharedHandle<FileAllocationMan>& fileAllocationMan,
|
|
||||||
const SharedHandle<CheckIntegrityMan>& checkIntegrityMan) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -37,21 +37,16 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
#include "FileAllocationMan.h"
|
|
||||||
#include "CheckIntegrityMan.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class RequestGroupMan;
|
class DownloadEngine;
|
||||||
|
|
||||||
class StatCalc {
|
class StatCalc {
|
||||||
public:
|
public:
|
||||||
virtual ~StatCalc() {}
|
virtual ~StatCalc() {}
|
||||||
|
|
||||||
virtual void
|
virtual void calculateStat(const DownloadEngine* e) = 0;
|
||||||
calculateStat(const SharedHandle<RequestGroupMan>& requestGroupMan,
|
|
||||||
const SharedHandle<FileAllocationMan>& fileAllocationMan,
|
|
||||||
const SharedHandle<CheckIntegrityMan>& checkIntegrityMan) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<StatCalc> StatCalcHandle;
|
typedef SharedHandle<StatCalc> StatCalcHandle;
|
||||||
|
|
Loading…
Reference in New Issue