diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 707761ff2..fdfd4a9f4 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -29,10 +29,10 @@ #include "session.h" +#include #include #include #include -#include #include #include @@ -4266,11 +4266,10 @@ void Session::handleSessionStatsAlert(libt::session_stats_alert *p) m_status.diskWriteQueue = p->values[m_metricIndices.peer.numPeersDownDisk]; m_status.peersCount = p->values[m_metricIndices.peer.numPeersConnected]; - const auto numBlocksRead = p->values[m_metricIndices.disk.numBlocksRead]; + const int numBlocksRead = p->values[m_metricIndices.disk.numBlocksRead]; + const int numBlocksCacheHits = p->values[m_metricIndices.disk.numBlocksCacheHits]; m_cacheStatus.totalUsedBuffers = p->values[m_metricIndices.disk.diskBlocksInUse]; - m_cacheStatus.readRatio = numBlocksRead > 0 - ? static_cast(p->values[m_metricIndices.disk.numBlocksCacheHits]) / numBlocksRead - : -1; + m_cacheStatus.readRatio = static_cast(numBlocksCacheHits) / std::max(numBlocksCacheHits + numBlocksRead, 1); m_cacheStatus.jobQueueLength = p->values[m_metricIndices.disk.queuedDiskJobs]; quint64 totalJobs = p->values[m_metricIndices.disk.writeJobs] + p->values[m_metricIndices.disk.readJobs] diff --git a/src/gui/statsdialog.cpp b/src/gui/statsdialog.cpp index 5ec64edc0..15aea6a69 100644 --- a/src/gui/statsdialog.cpp +++ b/src/gui/statsdialog.cpp @@ -77,7 +77,10 @@ void StatsDialog::update() : "-"); // Cache hits qreal readRatio = cs.readRatio; - m_ui->labelCacheHits->setText((readRatio >= 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "-"); + m_ui->labelCacheHits->setText(QString("%1%").arg( + readRatio > 0 + ? Utils::String::fromDouble(100 * readRatio, 2) + : "0")); // Buffers size m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers * 16 * 1024)); // Disk overload (100%) equivalent