From c197798d1b7364e8225beaaa716399441288203e Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Mon, 9 Nov 2015 11:45:07 +0100 Subject: [PATCH] [Qt] simple mempool info in debug window --- src/qt/clientmodel.cpp | 12 +++ src/qt/clientmodel.h | 6 ++ src/qt/forms/debugwindow.ui | 148 +++++++++++++++++++++++++----------- src/qt/rpcconsole.cpp | 12 +++ src/qt/rpcconsole.h | 2 + 5 files changed, 136 insertions(+), 44 deletions(-) diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 0900a35cc4..566e8fa62d 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -13,6 +13,7 @@ #include "checkpoints.h" #include "clientversion.h" #include "net.h" +#include "txmempool.h" #include "ui_interface.h" #include "util.h" @@ -88,6 +89,16 @@ QDateTime ClientModel::getLastBlockDate() const return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network } +long ClientModel::getMempoolSize() const +{ + return mempool.size(); +} + +size_t ClientModel::getMempoolDynamicUsage() const +{ + return mempool.DynamicMemoryUsage(); +} + double ClientModel::getVerificationProgress() const { LOCK(cs_main); @@ -122,6 +133,7 @@ void ClientModel::updateTimer() Q_EMIT numBlocksChanged(newNumBlocks, newBlockDate); } + Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage()); Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent()); } diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 627bdf862d..493a759331 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -51,6 +51,11 @@ public: int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const; int getNumBlocks() const; + //! Return number of transactions in the mempool + long getMempoolSize() const; + //! Return the dynamic memory usage of the mempool + size_t getMempoolDynamicUsage() const; + quint64 getTotalBytesRecv() const; quint64 getTotalBytesSent() const; @@ -89,6 +94,7 @@ private: Q_SIGNALS: void numConnectionsChanged(int count); void numBlocksChanged(int count, const QDateTime& blockDate); + void mempoolSizeChanged(long count, size_t mempoolSizeInBytes); void alertsChanged(const QString &warnings); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index 4117da57f5..e81a27a830 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -23,7 +23,7 @@ &Information - + 12 @@ -47,7 +47,7 @@ - + IBeamCursor @@ -70,7 +70,7 @@ - + IBeamCursor @@ -96,7 +96,7 @@ - + IBeamCursor @@ -122,7 +122,7 @@ - + IBeamCursor @@ -148,7 +148,7 @@ - + IBeamCursor @@ -171,7 +171,7 @@ - + IBeamCursor @@ -194,7 +194,7 @@ - + IBeamCursor @@ -210,19 +210,6 @@ - - - - - 75 - true - - - - Network - - - @@ -230,7 +217,7 @@ - + IBeamCursor @@ -253,7 +240,7 @@ - + IBeamCursor @@ -289,7 +276,7 @@ - + IBeamCursor @@ -306,13 +293,13 @@ - + Last block time - + IBeamCursor @@ -329,20 +316,43 @@ - - - Qt::Vertical + + + + 75 + true + - - - 20 - 20 - + + Memory Pool - + - + + + Current number of transactions + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + 75 @@ -350,24 +360,74 @@ - Debug log file + Network - - - Open the Bitcoin Core debug log file from the current data directory. This can take a few seconds for large log files. + + + Memory usage + + + + + + + IBeamCursor - &Open + N/A - - false + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + + + + 3 + + + + + Qt::Vertical + + + + 10 + 5 + + + + + + + + Debug log file + + + + + + + Open the Bitcoin Core debug log file from the current data directory. This can take a few seconds for large log files. + + + &Open + + + false + + + + + + Qt::Vertical diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 8401701821..07ce0c2845 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -343,6 +343,8 @@ void RPCConsole::setClientModel(ClientModel *model) updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent()); connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64))); + connect(model, SIGNAL(mempoolSizeChanged(long,size_t)), this, SLOT(setMempoolSize(long,size_t))); + // set up peer table ui->peerWidget->setModel(model->getPeerTableModel()); ui->peerWidget->verticalHeader()->hide(); @@ -523,6 +525,16 @@ void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate) ui->lastBlockTime->setText(blockDate.toString()); } +void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage) +{ + ui->mempoolNumberTxs->setText(QString::number(numberOfTxs)); + + if (dynUsage < 1000000) + ui->mempoolSize->setText(QString::number(dynUsage/1000.0, 'f', 2) + " KB"); + else + ui->mempoolSize->setText(QString::number(dynUsage/1000000.0, 'f', 2) + " MB"); +} + void RPCConsole::on_lineEdit_returnPressed() { QString cmd = ui->lineEdit->text(); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index d5932ff149..5e749336cf 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -77,6 +77,8 @@ public Q_SLOTS: void setNumConnections(int count); /** Set number of blocks and last block date shown in the UI */ void setNumBlocks(int count, const QDateTime& blockDate); + /** Set size (number of transactions and memory usage) of the mempool in the UI */ + void setMempoolSize(long numberOfTxs, size_t dynUsage); /** Go forward or back in history */ void browseHistory(int offset); /** Scroll console view to end */