Skip to content

Commit 6157e8c

Browse files
committed
Merge #11499: [Qt] Add upload and download info to the peerlist (debug menu)
6b1891e Add Sent and Received information to the debug menu peer list (Aaron Golliver) 8e4aa35 move human-readable byte formatting to guiutil (Aaron Golliver) Pull request description: Makes the peer list display how much you've uploaded/downloaded from each peer. Here's a screenshot ~~[outdated](https://i.imgur.com/MhPbItp.png)~~, [current](https://i.imgur.com/K1htrVv.png) of how it looks. You can now sort to see who are the peers you've uploaded the most too. I also moved `RPCConsole::FormatBytes` to `guiutil::formatBytes` so I could use it in the peerlist Tree-SHA512: 8845ef406e4cbe7f981879a78c063542ce90f50f45c8fa3514ba3e6e1164b4c70bb2093c4e1cac268aef0328b7b63545bc1dfa435c227f28fdb4cb0a596800f5
2 parents c0e5139 + 6b1891e commit 6157e8c

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

src/qt/guiutil.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,18 @@ QString formatNiceTimeOffset(qint64 secs)
984984
return timeBehindText;
985985
}
986986

987+
QString formatBytes(uint64_t bytes)
988+
{
989+
if(bytes < 1024)
990+
return QString(QObject::tr("%1 B")).arg(bytes);
991+
if(bytes < 1024 * 1024)
992+
return QString(QObject::tr("%1 KB")).arg(bytes / 1024);
993+
if(bytes < 1024 * 1024 * 1024)
994+
return QString(QObject::tr("%1 MB")).arg(bytes / 1024 / 1024);
995+
996+
return QString(QObject::tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024);
997+
}
998+
987999
void ClickableLabel::mouseReleaseEvent(QMouseEvent *event)
9881000
{
9891001
Q_EMIT clicked(event->pos());

src/qt/guiutil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ namespace GUIUtil
199199

200200
QString formatNiceTimeOffset(qint64 secs);
201201

202+
QString formatBytes(uint64_t bytes);
203+
202204
class ClickableLabel : public QLabel
203205
{
204206
Q_OBJECT

src/qt/peertablemodel.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
3333
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
3434
case PeerTableModel::Ping:
3535
return pLeft->dMinPing < pRight->dMinPing;
36+
case PeerTableModel::Sent:
37+
return pLeft->nSendBytes < pRight->nSendBytes;
38+
case PeerTableModel::Received:
39+
return pLeft->nRecvBytes < pRight->nRecvBytes;
3640
}
3741

3842
return false;
@@ -114,7 +118,7 @@ PeerTableModel::PeerTableModel(ClientModel *parent) :
114118
clientModel(parent),
115119
timer(0)
116120
{
117-
columns << tr("NodeId") << tr("Node/Service") << tr("User Agent") << tr("Ping");
121+
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");
118122
priv.reset(new PeerTablePriv());
119123
// default to unsorted
120124
priv->sortColumn = -1;
@@ -173,10 +177,20 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
173177
return QString::fromStdString(rec->nodeStats.cleanSubVer);
174178
case Ping:
175179
return GUIUtil::formatPingTime(rec->nodeStats.dMinPing);
180+
case Sent:
181+
return GUIUtil::formatBytes(rec->nodeStats.nSendBytes);
182+
case Received:
183+
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
176184
}
177185
} else if (role == Qt::TextAlignmentRole) {
178-
if (index.column() == Ping)
179-
return (QVariant)(Qt::AlignRight | Qt::AlignVCenter);
186+
switch (index.column()) {
187+
case Ping:
188+
case Sent:
189+
case Received:
190+
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
191+
default:
192+
return QVariant();
193+
}
180194
}
181195

182196
return QVariant();

src/qt/peertablemodel.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ class PeerTableModel : public QAbstractTableModel
5555
enum ColumnIndex {
5656
NetNodeId = 0,
5757
Address = 1,
58-
Subversion = 2,
59-
Ping = 3
58+
Ping = 2,
59+
Sent = 3,
60+
Received = 4,
61+
Subversion = 5
6062
};
6163

6264
/** @name Methods overridden from QAbstractTableModel

src/qt/rpcconsole.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -935,18 +935,6 @@ void RPCConsole::on_sldGraphRange_valueChanged(int value)
935935
setTrafficGraphRange(mins);
936936
}
937937

938-
QString RPCConsole::FormatBytes(quint64 bytes)
939-
{
940-
if(bytes < 1024)
941-
return QString(tr("%1 B")).arg(bytes);
942-
if(bytes < 1024 * 1024)
943-
return QString(tr("%1 KB")).arg(bytes / 1024);
944-
if(bytes < 1024 * 1024 * 1024)
945-
return QString(tr("%1 MB")).arg(bytes / 1024 / 1024);
946-
947-
return QString(tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024);
948-
}
949-
950938
void RPCConsole::setTrafficGraphRange(int mins)
951939
{
952940
ui->trafficGraph->setGraphRangeMins(mins);
@@ -955,8 +943,8 @@ void RPCConsole::setTrafficGraphRange(int mins)
955943

956944
void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
957945
{
958-
ui->lblBytesIn->setText(FormatBytes(totalBytesIn));
959-
ui->lblBytesOut->setText(FormatBytes(totalBytesOut));
946+
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalBytesIn));
947+
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
960948
}
961949

962950
void RPCConsole::peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
@@ -1050,8 +1038,8 @@ void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
10501038
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStats.nServices));
10511039
ui->peerLastSend->setText(stats->nodeStats.nLastSend ? GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nLastSend) : tr("never"));
10521040
ui->peerLastRecv->setText(stats->nodeStats.nLastRecv ? GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nLastRecv) : tr("never"));
1053-
ui->peerBytesSent->setText(FormatBytes(stats->nodeStats.nSendBytes));
1054-
ui->peerBytesRecv->setText(FormatBytes(stats->nodeStats.nRecvBytes));
1041+
ui->peerBytesSent->setText(GUIUtil::formatBytes(stats->nodeStats.nSendBytes));
1042+
ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
10551043
ui->peerConnTime->setText(GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nTimeConnected));
10561044
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingTime));
10571045
ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingWait));

src/qt/rpcconsole.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ public Q_SLOTS:
123123
void cmdRequest(const QString &command);
124124

125125
private:
126-
static QString FormatBytes(quint64 bytes);
127126
void startExecutor();
128127
void setTrafficGraphRange(int mins);
129128
/** show detailed information on ui about selected node */

0 commit comments

Comments
 (0)