Add sortable sent/recv bytes to Peers debug table

See GH #2240.
This commit is contained in:
chromatic 2021-06-03 18:37:38 -07:00
parent ce54d88b56
commit c5165e9b83
4 changed files with 51 additions and 2 deletions

View file

@ -1,4 +1,5 @@
// Copyright (c) 2011-2016 The Bitcoin Core developers
// Copyright (c) 2021 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -941,6 +942,38 @@ QString formatPingTime(double dPingTime)
return (dPingTime == std::numeric_limits<int64_t>::max()/1e6 || dPingTime == 0) ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(dPingTime * 1000), 10));
}
QString formatDataSizeValue(uint64_t uValue)
{
// Why handle these comparisons directly, instead of a clever algorithm?
// This is likely to be called in a tight loop, so avoid the overhead of
// setting up a constant list and walking an iterator.
static const uint64_t TERABYTE_SIZE = UINT64_C(1024*1024*1024*1024);
static const uint64_t GIGABYTE_SIZE = UINT64_C(1024*1024*1024);
static const uint64_t MEGABYTE_SIZE = UINT64_C(1024*1024);
static const uint64_t KILOBYTE_SIZE = UINT64_C(1024);
QString unitFormat = QObject::tr("%1 B");
if (uValue == std::numeric_limits<int64_t>::max()/1e6 || uValue == 0)
return QObject::tr("N/A");
if (uValue > TERABYTE_SIZE) {
unitFormat = QObject::tr("%1 TB");
uValue /= TERABYTE_SIZE;
} else if (uValue > GIGABYTE_SIZE) {
unitFormat = QObject::tr("%1 GB");
uValue /= GIGABYTE_SIZE;
} else if (uValue > MEGABYTE_SIZE) {
unitFormat = QObject::tr("%1 MB");
uValue /= MEGABYTE_SIZE;
} else if (uValue > KILOBYTE_SIZE) {
unitFormat = QObject::tr("%1 KB");
uValue /= KILOBYTE_SIZE;
}
return QString(unitFormat).arg(QString::number(uValue), 10);
}
QString formatTimeOffset(int64_t nTimeOffset)
{
return QString(QObject::tr("%1 s")).arg(QString::number((int)nTimeOffset, 10));

View file

@ -1,4 +1,5 @@
// Copyright (c) 2011-2016 The Bitcoin Core developers
// Copyright (c) 2021 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -197,6 +198,9 @@ namespace GUIUtil
/* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
QString formatPingTime(double dPingTime);
/* Format a uint64_t into a user-readable data size string (KB, MB, GB, TB) or display N/A, if 0*/
QString formatDataSizeValue(uint64_t uValue);
/* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
QString formatTimeOffset(int64_t nTimeOffset);

View file

@ -1,4 +1,5 @@
// Copyright (c) 2011-2016 The Bitcoin Core developers
// Copyright (c) 2021 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -33,6 +34,10 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
case PeerTableModel::Ping:
return pLeft->dMinPing < pRight->dMinPing;
case PeerTableModel::BytesSent:
return pLeft->nSendBytes < pRight->nSendBytes;
case PeerTableModel::BytesReceived:
return pLeft->nRecvBytes < pRight->nRecvBytes;
}
return false;
@ -114,7 +119,7 @@ PeerTableModel::PeerTableModel(ClientModel *parent) :
clientModel(parent),
timer(0)
{
columns << tr("NodeId") << tr("Node/Service") << tr("User Agent") << tr("Ping");
columns << tr("NodeId") << tr("Node/Service") << tr("User Agent") << tr("Ping") << tr("Bytes Sent") << tr("Bytes Received");
priv.reset(new PeerTablePriv());
// default to unsorted
priv->sortColumn = -1;
@ -173,6 +178,10 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
return QString::fromStdString(rec->nodeStats.cleanSubVer);
case Ping:
return GUIUtil::formatPingTime(rec->nodeStats.dMinPing);
case BytesSent:
return GUIUtil::formatDataSizeValue(rec->nodeStats.nSendBytes);
case BytesReceived:
return GUIUtil::formatDataSizeValue(rec->nodeStats.nRecvBytes);
}
} else if (role == Qt::TextAlignmentRole) {
if (index.column() == Ping)

View file

@ -1,4 +1,5 @@
// Copyright (c) 2011-2016 The Bitcoin Core developers
// Copyright (c) 2021 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -56,7 +57,9 @@ public:
NetNodeId = 0,
Address = 1,
Subversion = 2,
Ping = 3
Ping = 3,
BytesSent = 4,
BytesReceived = 5
};
/** @name Methods overridden from QAbstractTableModel