Skip to content

Commit 47048d8

Browse files
authored
Merge pull request #8349 from Chocobo1/stats
Improve stats dialog
2 parents 882fa7e + e31ec20 commit 47048d8

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

src/base/bittorrent/session.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
#include "session.h"
3131

32+
#include <algorithm>
3233
#include <cstdlib>
3334
#include <queue>
3435
#include <string>
35-
#include <vector>
3636

3737
#include <QCoreApplication>
3838
#include <QDateTime>
@@ -4288,11 +4288,10 @@ void Session::handleSessionStatsAlert(libt::session_stats_alert *p)
42884288
m_status.diskWriteQueue = p->values[m_metricIndices.peer.numPeersDownDisk];
42894289
m_status.peersCount = p->values[m_metricIndices.peer.numPeersConnected];
42904290

4291-
const auto numBlocksRead = p->values[m_metricIndices.disk.numBlocksRead];
4291+
const int numBlocksRead = p->values[m_metricIndices.disk.numBlocksRead];
4292+
const int numBlocksCacheHits = p->values[m_metricIndices.disk.numBlocksCacheHits];
42924293
m_cacheStatus.totalUsedBuffers = p->values[m_metricIndices.disk.diskBlocksInUse];
4293-
m_cacheStatus.readRatio = numBlocksRead > 0
4294-
? static_cast<qreal>(p->values[m_metricIndices.disk.numBlocksCacheHits]) / numBlocksRead
4295-
: -1;
4294+
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max(numBlocksCacheHits + numBlocksRead, 1);
42964295
m_cacheStatus.jobQueueLength = p->values[m_metricIndices.disk.queuedDiskJobs];
42974296

42984297
quint64 totalJobs = p->values[m_metricIndices.disk.writeJobs] + p->values[m_metricIndices.disk.readJobs]

src/gui/statsdialog.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ void StatsDialog::update()
7777
: "-");
7878
// Cache hits
7979
qreal readRatio = cs.readRatio;
80-
m_ui->labelCacheHits->setText((readRatio >= 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "-");
80+
m_ui->labelCacheHits->setText(QString("%1%").arg(
81+
readRatio > 0
82+
? Utils::String::fromDouble(100 * readRatio, 2)
83+
: "0"));
8184
// Buffers size
8285
m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers * 16 * 1024));
8386
// Disk overload (100%) equivalent

src/gui/statsdialog.ui

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>286</width>
10-
<height>401</height>
9+
<width>265</width>
10+
<height>457</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -20,71 +20,71 @@
2020
<string>User statistics</string>
2121
</property>
2222
<layout class="QGridLayout" name="gridLayout_2">
23-
<item row="11" column="0">
23+
<item row="3" column="1" alignment="Qt::AlignRight">
24+
<widget class="QLabel" name="labelWaste">
25+
<property name="text">
26+
<string notr="true">TextLabel</string>
27+
</property>
28+
</widget>
29+
</item>
30+
<item row="4" column="0">
2431
<widget class="QLabel" name="labelPeersText">
2532
<property name="text">
26-
<string>Total peer connections:</string>
33+
<string>Connected peers:</string>
2734
</property>
2835
</widget>
2936
</item>
30-
<item row="3" column="0">
37+
<item row="2" column="0">
3138
<widget class="QLabel" name="labelGlobalRatioText">
3239
<property name="text">
33-
<string>Global ratio:</string>
40+
<string>All-time share ratio:</string>
3441
</property>
3542
</widget>
3643
</item>
37-
<item row="11" column="1" alignment="Qt::AlignRight">
44+
<item row="4" column="1" alignment="Qt::AlignRight">
3845
<widget class="QLabel" name="labelPeers">
3946
<property name="text">
4047
<string notr="true">TextLabel</string>
4148
</property>
4249
</widget>
4350
</item>
44-
<item row="0" column="0">
51+
<item row="1" column="0">
4552
<widget class="QLabel" name="labelAlltimeDLText">
4653
<property name="text">
47-
<string>Alltime download:</string>
54+
<string>All-time download:</string>
4855
</property>
4956
</widget>
5057
</item>
5158
<item row="1" column="1" alignment="Qt::AlignRight">
52-
<widget class="QLabel" name="labelAlltimeUL">
53-
<property name="text">
54-
<string notr="true">TextLabel</string>
55-
</property>
56-
</widget>
57-
</item>
58-
<item row="0" column="1" alignment="Qt::AlignRight">
5959
<widget class="QLabel" name="labelAlltimeDL">
6060
<property name="text">
6161
<string notr="true">TextLabel</string>
6262
</property>
6363
</widget>
6464
</item>
65-
<item row="1" column="0">
66-
<widget class="QLabel" name="labelAlltimeULText">
65+
<item row="2" column="1" alignment="Qt::AlignRight">
66+
<widget class="QLabel" name="labelGlobalRatio">
6767
<property name="text">
68-
<string>Alltime upload:</string>
68+
<string notr="true">TextLabel</string>
6969
</property>
7070
</widget>
7171
</item>
72-
<item row="3" column="1" alignment="Qt::AlignRight">
73-
<widget class="QLabel" name="labelGlobalRatio">
72+
<item row="3" column="0">
73+
<widget class="QLabel" name="labelWasteText">
7474
<property name="text">
75-
<string notr="true">TextLabel</string>
75+
<string>Session waste:</string>
7676
</property>
7777
</widget>
7878
</item>
79-
<item row="2" column="0">
80-
<widget class="QLabel" name="labelWasteText">
79+
<item row="0" column="0">
80+
<widget class="QLabel" name="labelAlltimeULText">
8181
<property name="text">
82-
<string>Total waste (this session):</string>
82+
<string>All-time upload:</string>
8383
</property>
8484
</widget>
8585
</item>
86-
<item row="2" column="1" alignment="Qt::AlignRight">
87-
<widget class="QLabel" name="labelWaste">
86+
<item row="0" column="1" alignment="Qt::AlignRight">
87+
<widget class="QLabel" name="labelAlltimeUL">
8888
<property name="text">
8989
<string notr="true">TextLabel</string>
9090
</property>
@@ -99,31 +99,31 @@
9999
<string>Cache statistics</string>
100100
</property>
101101
<layout class="QGridLayout" name="gridLayout">
102-
<item row="1" column="0">
102+
<item row="0" column="0">
103103
<widget class="QLabel" name="labelCacheHitsText">
104104
<property name="text">
105105
<string>Read cache hits:</string>
106106
</property>
107107
</widget>
108108
</item>
109-
<item row="1" column="1" alignment="Qt::AlignRight">
109+
<item row="0" column="1" alignment="Qt::AlignRight">
110110
<widget class="QLabel" name="labelCacheHits">
111111
<property name="text">
112112
<string notr="true">TextLabel</string>
113113
</property>
114114
</widget>
115115
</item>
116-
<item row="2" column="1" alignment="Qt::AlignRight">
116+
<item row="1" column="1" alignment="Qt::AlignRight">
117117
<widget class="QLabel" name="labelTotalBuf">
118118
<property name="text">
119119
<string notr="true">TextLabel</string>
120120
</property>
121121
</widget>
122122
</item>
123-
<item row="2" column="0">
123+
<item row="1" column="0">
124124
<widget class="QLabel" name="labelTotalBufText">
125125
<property name="text">
126-
<string>Total buffers size:</string>
126+
<string>Total buffer size:</string>
127127
</property>
128128
</widget>
129129
</item>

0 commit comments

Comments
 (0)