Skip to content

Commit

Permalink
[Qt] simple mempool info in debug window
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Nov 20, 2015
1 parent 6176e9b commit c197798
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 44 deletions.
12 changes: 12 additions & 0 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "checkpoints.h"
#include "clientversion.h"
#include "net.h"
#include "txmempool.h"
#include "ui_interface.h"
#include "util.h"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -122,6 +133,7 @@ void ClientModel::updateTimer()
Q_EMIT numBlocksChanged(newNumBlocks, newBlockDate);
}

Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage());
Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent());
}

Expand Down
6 changes: 6 additions & 0 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class ClientModel : public QObject
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;

Expand Down Expand Up @@ -89,6 +94,7 @@ class ClientModel : public QObject
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);

Expand Down
148 changes: 104 additions & 44 deletions src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<attribute name="title">
<string>&amp;Information</string>
</attribute>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0">
<property name="horizontalSpacing">
<number>12</number>
</property>
Expand All @@ -47,7 +47,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="1" colspan="2">
<widget class="QLabel" name="clientName">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -70,7 +70,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="clientVersion">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -96,7 +96,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="3" column="1" colspan="2">
<widget class="QLabel" name="clientUserAgent">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -122,7 +122,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="4" column="1" colspan="2">
<widget class="QLabel" name="openSSLVersion">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -148,7 +148,7 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="berkeleyDBVersion">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -171,7 +171,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="6" column="1" colspan="2">
<widget class="QLabel" name="buildDate">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -194,7 +194,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="7" column="1" colspan="2">
<widget class="QLabel" name="startupTime">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -210,27 +210,14 @@
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Network</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="9" column="1" colspan="2">
<widget class="QLabel" name="networkName">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -253,7 +240,7 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="10" column="1" colspan="2">
<widget class="QLabel" name="numberOfConnections">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand Down Expand Up @@ -289,7 +276,7 @@
</property>
</widget>
</item>
<item row="12" column="1">
<item row="12" column="1" colspan="2">
<widget class="QLabel" name="numberOfBlocks">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -306,13 +293,13 @@
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="labelLastBlockTime">
<property name="text">
<string>Last block time</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="13" column="1" colspan="2">
<widget class="QLabel" name="lastBlockTime">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -329,45 +316,118 @@
</widget>
</item>
<item row="14" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QLabel" name="labelMempoolTitle">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
<property name="text">
<string>Memory Pool</string>
</property>
</spacer>
</widget>
</item>
<item row="15" column="0">
<widget class="QLabel" name="labelDebugLogfile">
<widget class="QLabel" name="labelNumberOfTransactions">
<property name="text">
<string>Current number of transactions</string>
</property>
</widget>
</item>
<item row="15" column="1">
<widget class="QLabel" name="mempoolNumberTxs">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
<string>N/A</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelNetwork">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Debug log file</string>
<string>Network</string>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QPushButton" name="openDebugLogfileButton">
<property name="toolTip">
<string>Open the Bitcoin Core debug log file from the current data directory. This can take a few seconds for large log files.</string>
<widget class="QLabel" name="labelMemoryUsage">
<property name="text">
<string>Memory usage</string>
</property>
</widget>
</item>
<item row="16" column="1">
<widget class="QLabel" name="mempoolSize">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
<string>&amp;Open</string>
<string>N/A</string>
</property>
<property name="autoDefault">
<bool>false</bool>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="17" column="0">
<item row="14" column="2" rowspan="3">
<layout class="QVBoxLayout" name="verticalLayoutDebugButton">
<property name="spacing">
<number>3</number>
</property>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelDebugLogfile">
<property name="text">
<string>Debug log file</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="openDebugLogfileButton">
<property name="toolTip">
<string>Open the Bitcoin Core debug log file from the current data directory. This can take a few seconds for large log files.</string>
</property>
<property name="text">
<string>&amp;Open</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="18" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand Down
12 changes: 12 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit c197798

Please sign in to comment.