From 39830986c260b2695e5d2febc585ea24a14ddc3e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 1 Jun 2019 11:28:37 +0800 Subject: [PATCH 1/2] Use alert's timestamp This way has better accuracy than running our own timer. --- src/base/bittorrent/session.cpp | 5 +++-- src/base/bittorrent/session.h | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 4ed8cf4ed..669401559 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -508,7 +508,6 @@ Session::Session(QObject *parent) new PortForwarderImpl {m_nativeSession}; initMetrics(); - m_statsUpdateTimer.start(); qDebug("* BitTorrent Session constructed"); } @@ -4207,7 +4206,9 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) { - const qreal interval = m_statsUpdateTimer.restart() / 1000.; + const qreal interval = lt::total_milliseconds(p->timestamp() - m_statsLastTimestamp) / 1000.; + m_statsLastTimestamp = p->timestamp(); + #if (LIBTORRENT_VERSION_NUM < 10200) const auto &stats = p->values; #else diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 8fff70235..30c73ae1a 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -34,7 +34,6 @@ #include -#include #include #include #include @@ -701,7 +700,7 @@ namespace BitTorrent QTimer *m_recentErroredTorrentsTimer; SessionMetricIndices m_metricIndices; - QElapsedTimer m_statsUpdateTimer; + lt::time_point m_statsLastTimestamp = lt::clock_type::now(); SessionStatus m_status; CacheStatus m_cacheStatus; From 3f2ce8a2b7a5665122e9d4ea28d5ed5f3217bcde Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 1 Jun 2019 11:40:51 +0800 Subject: [PATCH 2/2] Remove unused stats_alert handler Fixup 0fe9cd05c4aca8be9820cd489c8fa57173df6ed3. --- src/base/bittorrent/session.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 669401559..dc9d41937 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3787,7 +3787,6 @@ void Session::handleAlert(const lt::alert *a) { try { switch (a->type()) { - case lt::stats_alert::alert_type: case lt::file_renamed_alert::alert_type: case lt::file_completed_alert::alert_type: case lt::torrent_finished_alert::alert_type: