aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchromatic <[email protected]>2021-06-03 18:37:38 -0700
committerchromatic <[email protected]>2021-06-08 10:13:37 -0700
commitc5165e9b8311d07df0ea9914a04596e145a2a552 (patch)
tree4f53c55ae76822ebaabbffe456c6f26c365d0832 /src
parentMerge pull request #2111 from rnicoll/contributing (diff)
downloaddiscoin-c5165e9b8311d07df0ea9914a04596e145a2a552.tar.xz
discoin-c5165e9b8311d07df0ea9914a04596e145a2a552.zip
Add sortable sent/recv bytes to Peers debug table
See GH #2240.
Diffstat (limited to 'src')
-rw-r--r--src/qt/guiutil.cpp33
-rw-r--r--src/qt/guiutil.h4
-rw-r--r--src/qt/peertablemodel.cpp11
-rw-r--r--src/qt/peertablemodel.h5
4 files changed, 51 insertions, 2 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 6912b9312..cfd5b0e98 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -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));
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 913aa5e24..5ac303125 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -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);
diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp
index fff072fd4..f55564890 100644
--- a/src/qt/peertablemodel.cpp
+++ b/src/qt/peertablemodel.cpp
@@ -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)
diff --git a/src/qt/peertablemodel.h b/src/qt/peertablemodel.h
index cc47b67ec..85502527b 100644
--- a/src/qt/peertablemodel.h
+++ b/src/qt/peertablemodel.h
@@ -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