Browse Source

Collect and save alltime UL/DL samples

adaptive-webui-19844
Nick Tiskov 11 years ago
parent
commit
687e7a1343
  1. 8
      src/qtlibtorrent/qbtsession.cpp
  2. 2
      src/qtlibtorrent/qbtsession.h
  3. 35
      src/qtlibtorrent/torrentspeedmonitor.cpp
  4. 10
      src/qtlibtorrent/torrentspeedmonitor.h

8
src/qtlibtorrent/qbtsession.cpp

@ -2778,6 +2778,14 @@ qlonglong QBtSession::getETA(const QString &hash) const
return m_speedMonitor->getETA(hash); return m_speedMonitor->getETA(hash);
} }
quint64 QBtSession::getAlltimeDL() const {
return m_speedMonitor->getAlltimeDL();
}
quint64 QBtSession::getAlltimeUL() const {
return m_speedMonitor->getAlltimeUL();
}
void QBtSession::handleIPFilterParsed(int ruleCount) void QBtSession::handleIPFilterParsed(int ruleCount)
{ {
addConsoleMessage(tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount)); addConsoleMessage(tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));

2
src/qtlibtorrent/qbtsession.h

@ -107,6 +107,8 @@ public:
inline bool isLSDEnabled() const { return LSDEnabled; } inline bool isLSDEnabled() const { return LSDEnabled; }
inline bool isPexEnabled() const { return PeXEnabled; } inline bool isPexEnabled() const { return PeXEnabled; }
inline bool isQueueingEnabled() const { return queueingEnabled; } inline bool isQueueingEnabled() const { return queueingEnabled; }
quint64 getAlltimeDL() const;
quint64 getAlltimeUL() const;
public slots: public slots:
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);

35
src/qtlibtorrent/torrentspeedmonitor.cpp

@ -35,6 +35,7 @@
#include "qbtsession.h" #include "qbtsession.h"
#include "misc.h" #include "misc.h"
#include "torrentspeedmonitor.h" #include "torrentspeedmonitor.h"
#include "qinisettings.h"
using namespace libtorrent; using namespace libtorrent;
@ -64,12 +65,14 @@ TorrentSpeedMonitor::TorrentSpeedMonitor(QBtSession* session) :
{ {
connect(m_session, SIGNAL(deletedTorrent(QString)), SLOT(removeSamples(QString))); connect(m_session, SIGNAL(deletedTorrent(QString)), SLOT(removeSamples(QString)));
connect(m_session, SIGNAL(pausedTorrent(QTorrentHandle)), SLOT(removeSamples(QTorrentHandle))); connect(m_session, SIGNAL(pausedTorrent(QTorrentHandle)), SLOT(removeSamples(QTorrentHandle)));
loadStats();
} }
TorrentSpeedMonitor::~TorrentSpeedMonitor() { TorrentSpeedMonitor::~TorrentSpeedMonitor() {
m_abort = true; m_abort = true;
m_abortCond.wakeOne(); m_abortCond.wakeOne();
wait(); wait();
saveStats();
} }
void TorrentSpeedMonitor::run() void TorrentSpeedMonitor::run()
@ -77,6 +80,7 @@ void TorrentSpeedMonitor::run()
do { do {
m_mutex.lock(); m_mutex.lock();
getSamples(); getSamples();
saveStats();
m_abortCond.wait(&m_mutex, 1000); m_abortCond.wait(&m_mutex, 1000);
m_mutex.unlock(); m_mutex.unlock();
} while(!m_abort); } while(!m_abort);
@ -153,6 +157,16 @@ qlonglong TorrentSpeedMonitor::getETA(const QString &hash) const
return (h.total_wanted() - h.total_wanted_done()) / speed_average.download; return (h.total_wanted() - h.total_wanted_done()) / speed_average.download;
} }
quint64 TorrentSpeedMonitor::getAlltimeDL() const {
QMutexLocker l(&m_mutex);
return alltimeDL;
}
quint64 TorrentSpeedMonitor::getAlltimeUL() const {
QMutexLocker l(&m_mutex);
return alltimeUL;
}
void TorrentSpeedMonitor::getSamples() void TorrentSpeedMonitor::getSamples()
{ {
const std::vector<torrent_handle> torrents = m_session->getSession()->get_torrents(); const std::vector<torrent_handle> torrents = m_session->getSession()->get_torrents();
@ -163,8 +177,27 @@ void TorrentSpeedMonitor::getSamples()
try { try {
torrent_status st = it->status(0x0); torrent_status st = it->status(0x0);
if (!st.paused) { if (!st.paused) {
m_samples[misc::toQString(it->info_hash())].addSample(st.download_payload_rate, st.upload_payload_rate); int up = st.upload_payload_rate;
int down = st.download_payload_rate;
m_samples[misc::toQString(it->info_hash())].addSample(down, up);
alltimeDL += down;
alltimeUL += up;
} }
} catch(invalid_handle&) {} } catch(invalid_handle&) {}
} }
} }
void TorrentSpeedMonitor::saveStats() const {
QIniSettings s;
QVariantHash v;
v.insert("AlltimeDL", alltimeDL);
v.insert("AlltimeUL", alltimeUL);
s.setValue("Stats/AllStats", v);
}
void TorrentSpeedMonitor::loadStats() {
QIniSettings s;
QVariantHash v(s.value("Stats/AllStats", QVariantHash()).toHash());
alltimeDL = v["AlltimeDL"].toULongLong();
alltimeUL = v["AlltimeUL"].toULongLong();
}

10
src/qtlibtorrent/torrentspeedmonitor.h

@ -49,26 +49,30 @@ public:
explicit TorrentSpeedMonitor(QBtSession* session); explicit TorrentSpeedMonitor(QBtSession* session);
~TorrentSpeedMonitor(); ~TorrentSpeedMonitor();
qlonglong getETA(const QString &hash) const; qlonglong getETA(const QString &hash) const;
quint64 getAlltimeDL() const;
quint64 getAlltimeUL() const;
protected: protected:
void run(); void run();
private: private:
void getSamples(); void getSamples();
void saveStats() const;
void loadStats();
private slots: private slots:
void removeSamples(const QString& hash); void removeSamples(const QString& hash);
void removeSamples(const QTorrentHandle& h); void removeSamples(const QTorrentHandle& h);
private:
static const int sampling_interval = 1000; // 1s
private: private:
bool m_abort; bool m_abort;
QWaitCondition m_abortCond; QWaitCondition m_abortCond;
QHash<QString, SpeedSample> m_samples; QHash<QString, SpeedSample> m_samples;
mutable QMutex m_mutex; mutable QMutex m_mutex;
QBtSession *m_session; QBtSession *m_session;
// Will overflow at 15.9 EiB
quint64 alltimeUL;
quint64 alltimeDL;
}; };
#endif // TORRENTSPEEDMONITOR_H #endif // TORRENTSPEEDMONITOR_H

Loading…
Cancel
Save