Don't use removed stat metric in libtorrent 2.0

For now, the metric is not entirely removed due to WebAPI still needs to
access it.
This commit is contained in:
Chocobo1 2020-12-24 11:54:33 +08:00
parent 0ebd864db9
commit 90a1ea4281
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
6 changed files with 20 additions and 6 deletions

View file

@ -38,6 +38,6 @@ namespace BitTorrent
quint64 jobQueueLength = 0;
quint64 averageJobTime = 0;
quint64 queuedBytes = 0;
qreal readRatio = 0.0;
qreal readRatio = 0; // TODO: remove when LIBTORRENT_VERSION_NUM >= 20000
};
}

View file

@ -1220,8 +1220,10 @@ void Session::initMetrics()
m_metricIndices.disk.numBlocksRead = lt::find_metric_idx("disk.num_blocks_read");
Q_ASSERT(m_metricIndices.disk.numBlocksRead >= 0);
#if (LIBTORRENT_VERSION_NUM < 20000)
m_metricIndices.disk.numBlocksCacheHits = lt::find_metric_idx("disk.num_blocks_cache_hits");
Q_ASSERT(m_metricIndices.disk.numBlocksCacheHits >= 0);
#endif
m_metricIndices.disk.writeJobs = lt::find_metric_idx("disk.num_write_ops");
Q_ASSERT(m_metricIndices.disk.writeJobs >= 0);
@ -4908,11 +4910,14 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
m_status.peersCount = stats[m_metricIndices.peer.numPeersConnected];
const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead];
const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits];
m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse];
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max<int64_t>(numBlocksCacheHits + numBlocksRead, 1);
m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs];
#if (LIBTORRENT_VERSION_NUM < 20000)
const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits];
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max<int64_t>((numBlocksCacheHits + numBlocksRead), 1);
#endif
const int64_t totalJobs = stats[m_metricIndices.disk.writeJobs] + stats[m_metricIndices.disk.readJobs]
+ stats[m_metricIndices.disk.hashJobs];
m_cacheStatus.averageJobTime = (totalJobs > 0)

View file

@ -197,7 +197,9 @@ namespace BitTorrent
{
int diskBlocksInUse = -1;
int numBlocksRead = -1;
#if (LIBTORRENT_VERSION_NUM < 20000)
int numBlocksCacheHits = -1;
#endif
int writeJobs = -1;
int readJobs = -1;
int hashJobs = -1;

View file

@ -52,6 +52,11 @@ StatsDialog::StatsDialog(QWidget *parent)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatsDialog::update);
#if (LIBTORRENT_VERSION_NUM >= 20000)
m_ui->labelCacheHitsText->hide();
m_ui->labelCacheHits->hide();
#endif
Utils::Gui::resize(this);
show();
}
@ -78,11 +83,13 @@ void StatsDialog::update()
((atd > 0) && (atu > 0))
? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2)
: "-");
#if (LIBTORRENT_VERSION_NUM < 20000)
// Cache hits
qreal readRatio = cs.readRatio;
const qreal readRatio = cs.readRatio;
m_ui->labelCacheHits->setText(QString::fromLatin1("%1%").arg((readRatio > 0)
? Utils::String::fromDouble(100 * readRatio, 2)
: QLatin1String("0")));
#endif
// Buffers size
m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers * 16 * 1024));
// Disk overload (100%) equivalent

View file

@ -35,7 +35,7 @@ namespace Ui
class StatsDialog;
}
class StatsDialog : public QDialog
class StatsDialog final : public QDialog
{
Q_OBJECT

View file

@ -134,7 +134,7 @@ namespace
map[KEY_TRANSFER_GLOBAL_RATIO] = ((atd > 0) && (atu > 0)) ? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2) : "-";
map[KEY_TRANSFER_TOTAL_PEER_CONNECTIONS] = sessionStatus.peersCount;
const qreal readRatio = cacheStatus.readRatio;
const qreal readRatio = cacheStatus.readRatio; // TODO: remove when LIBTORRENT_VERSION_NUM >= 20000
map[KEY_TRANSFER_READ_CACHE_HITS] = (readRatio > 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "0";
map[KEY_TRANSFER_TOTAL_BUFFERS_SIZE] = cacheStatus.totalUsedBuffers * 16 * 1024;