Skip to content

partial rebase and fixup of stats qt branch #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: 2016/08/stats_qt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contrib/debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ License: GPL-2+

Files: src/qt/res/icons/add.png
src/qt/res/icons/address-book.png
src/qt/res/icons/chart.png
src/qt/res/icons/chevron.png
src/qt/res/icons/configure.png
src/qt/res/icons/debugwindow.png
Expand Down Expand Up @@ -79,6 +80,7 @@ Comment: Modifications of Stephan Hutchings Typicons

Files: src/qt/res/icons/about.png
src/qt/res/icons/bitcoin.*
src/qt/res/icons/button_*
share/pixmaps/bitcoin*
src/qt/res/src/bitcoin.svg
Copyright: Bitboy, Jonas Schnelli
Expand Down
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ BITCOIN_CORE_H = \
script/sign.h \
script/standard.h \
script/ismine.h \
stats/stats.h \
stats/stats_mempool.h \
streams.h \
support/allocators/secure.h \
support/allocators/zeroafterfree.h \
Expand Down Expand Up @@ -215,6 +217,9 @@ libbitcoin_server_a_SOURCES = \
rpc/server.cpp \
script/sigcache.cpp \
script/ismine.cpp \
stats/rpc_stats.cpp \
stats/stats.cpp \
stats/stats_mempool.cpp \
timedata.cpp \
torcontrol.cpp \
txdb.cpp \
Expand Down
5 changes: 5 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ QT_FORMS_UI = \
qt/forms/coincontroldialog.ui \
qt/forms/editaddressdialog.ui \
qt/forms/helpmessagedialog.ui \
qt/forms/mempoolstats.ui \
qt/forms/intro.ui \
qt/forms/modaloverlay.ui \
qt/forms/openuridialog.ui \
Expand Down Expand Up @@ -133,6 +134,7 @@ QT_MOC_CPP = \
qt/moc_macdockiconhandler.cpp \
qt/moc_macnotificationhandler.cpp \
qt/moc_modaloverlay.cpp \
qt/moc_mempoolstats.cpp \
qt/moc_notificator.cpp \
qt/moc_openuridialog.cpp \
qt/moc_optionsdialog.cpp \
Expand Down Expand Up @@ -203,6 +205,7 @@ BITCOIN_QT_H = \
qt/macdockiconhandler.h \
qt/macnotificationhandler.h \
qt/modaloverlay.h \
qt/mempoolstats.h \
qt/networkstyle.h \
qt/notificator.h \
qt/openuridialog.h \
Expand Down Expand Up @@ -245,6 +248,7 @@ RES_ICONS = \
qt/res/icons/bitcoin.ico \
qt/res/icons/bitcoin_testnet.ico \
qt/res/icons/bitcoin.png \
qt/res/icons/chart.png \
qt/res/icons/chevron.png \
qt/res/icons/clock1.png \
qt/res/icons/clock2.png \
Expand Down Expand Up @@ -305,6 +309,7 @@ BITCOIN_QT_BASE_CPP = \
qt/guiutil.cpp \
qt/intro.cpp \
qt/modaloverlay.cpp \
qt/mempoolstats.cpp \
qt/networkstyle.cpp \
qt/notificator.cpp \
qt/optionsdialog.cpp \
Expand Down
8 changes: 8 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "script/standard.h"
#include "script/sigcache.h"
#include "scheduler.h"
#include "stats/stats.h"
#include "timedata.h"
#include "txdb.h"
#include "txmempool.h"
Expand Down Expand Up @@ -506,6 +507,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT));
}

strUsage += CStats::getHelpString(showDebug);
return strUsage;
}

Expand Down Expand Up @@ -1145,6 +1147,10 @@ bool AppInitParameterInteraction()
}
}
}

if (!CStats::parameterInteraction())
return false;

return true;
}

Expand Down Expand Up @@ -1727,5 +1733,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
StartWallets(scheduler);
#endif

CStats::DefaultStats()->startCollecting(scheduler);

return !fRequestShutdown;
}
1 change: 1 addition & 0 deletions src/memusage.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BITCOIN_MEMUSAGE_H

#include "indirectmap.h"
#include "prevector.h"

#include <stdlib.h>

Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoin.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<file alias="hd_enabled">res/icons/hd_enabled.png</file>
<file alias="hd_disabled">res/icons/hd_disabled.png</file>
<file alias="network_disabled">res/icons/network_disabled.png</file>
<file alias="chart">res/icons/chart.png</file>
</qresource>
<qresource prefix="/movies">
<file alias="spinner-000">res/movies/spinner-000.png</file>
Expand Down
26 changes: 26 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "guiconstants.h"
#include "guiutil.h"
#include "modaloverlay.h"
#include "mempoolstats.h"
#include "networkstyle.h"
#include "notificator.h"
#include "openuridialog.h"
Expand Down Expand Up @@ -113,12 +114,14 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
openRPCConsoleAction(0),
openAction(0),
showHelpMessageAction(0),
showMempoolStatsAction(0),
trayIcon(0),
trayIconMenu(0),
notificator(0),
rpcConsole(0),
helpMessageDialog(0),
modalOverlay(0),
mempoolStats(0),
prevBlocks(0),
spinnerFrame(0),
platformStyle(_platformStyle)
Expand Down Expand Up @@ -369,6 +372,11 @@ void BitcoinGUI::createActions()
// initially disable the debug window menu item
openRPCConsoleAction->setEnabled(false);

showMempoolStatsAction = new QAction(platformStyle->TextColorIcon(":/icons/chart"), tr("&Mempool Statistics"), this);
showMempoolStatsAction->setStatusTip(tr("Mempool Statistics"));
// initially disable the mempool stats menu item
showMempoolStatsAction->setEnabled(false);

usedSendingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
usedReceivingAddressesAction = new QAction(platformStyle->TextColorIcon(":/icons/address-book"), tr("&Receiving addresses..."), this);
Expand All @@ -388,6 +396,8 @@ void BitcoinGUI::createActions()
connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden()));
connect(showHelpMessageAction, SIGNAL(triggered()), this, SLOT(showHelpMessageClicked()));
connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showDebugWindow()));
connect(showMempoolStatsAction, SIGNAL(triggered()), this, SLOT(showMempoolStatsWindow()));

// prevents an open debug window from becoming stuck/unusable on client shutdown
connect(quitAction, SIGNAL(triggered()), rpcConsole, SLOT(hide()));

Expand Down Expand Up @@ -448,6 +458,7 @@ void BitcoinGUI::createMenuBar()
{
help->addAction(openRPCConsoleAction);
}
help->addAction(showMempoolStatsAction);
help->addAction(showHelpMessageAction);
help->addSeparator();
help->addAction(aboutAction);
Expand Down Expand Up @@ -618,6 +629,7 @@ void BitcoinGUI::createTrayIconMenu()
trayIconMenu->addSeparator();
trayIconMenu->addAction(optionsAction);
trayIconMenu->addAction(openRPCConsoleAction);
trayIconMenu->addAction(showMempoolStatsAction);
#ifndef Q_OS_MAC // This is built-in on Mac
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
Expand Down Expand Up @@ -673,6 +685,19 @@ void BitcoinGUI::showHelpMessageClicked()
helpMessageDialog->show();
}

void BitcoinGUI::showMempoolStatsWindow()
{
// only build the mempool stats window if its requested
if (!mempoolStats)
mempoolStats = new MempoolStats(this);
if (clientModel)
mempoolStats->setClientModel(clientModel);
mempoolStats->showNormal();
mempoolStats->show();
mempoolStats->raise();
mempoolStats->activateWindow();
}

#ifdef ENABLE_WALLET
void BitcoinGUI::openClicked()
{
Expand Down Expand Up @@ -981,6 +1006,7 @@ void BitcoinGUI::showEvent(QShowEvent *event)
{
// enable the debug window when the main window shows up
openRPCConsoleAction->setEnabled(true);
showMempoolStatsAction->setEnabled(true);
aboutAction->setEnabled(true);
optionsAction->setEnabled(true);
}
Expand Down
5 changes: 5 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WalletFrame;
class WalletModel;
class HelpMessageDialog;
class ModalOverlay;
class MempoolStats;

QT_BEGIN_NAMESPACE
class QAction;
Expand Down Expand Up @@ -111,13 +112,15 @@ class BitcoinGUI : public QMainWindow
QAction *openRPCConsoleAction;
QAction *openAction;
QAction *showHelpMessageAction;
QAction *showMempoolStatsAction;

QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
Notificator *notificator;
RPCConsole *rpcConsole;
HelpMessageDialog *helpMessageDialog;
ModalOverlay *modalOverlay;
MempoolStats *mempoolStats;

/** Keep track of previous number of blocks, to detect progress */
int prevBlocks;
Expand Down Expand Up @@ -218,6 +221,8 @@ private Q_SLOTS:
void showDebugWindowActivateConsole();
/** Show help message dialog */
void showHelpMessageClicked();
/** Show mempool stats window */
void showMempoolStatsWindow();
#ifndef Q_OS_MAC
/** Handle tray icon clicked */
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
Expand Down
26 changes: 26 additions & 0 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "clientversion.h"
#include "validation.h"
#include "net.h"
#include "stats/stats.h"
#include "txmempool.h"
#include "ui_interface.h"
#include "util.h"
Expand Down Expand Up @@ -251,6 +252,22 @@ void ClientModel::updateBanlist()
banTableModel->refresh();
}

void ClientModel::updateMempoolStats()
{
Q_EMIT mempoolStatsDidUpdate();
}

MempoolSamplesVector ClientModel::getMempoolStatsInRange(unsigned int precision, QDateTime &from)
{
// get stats from the core stats model
uint64_t timeFrom = from.toTime_t();

MempoolSamplesVector samples = CStats::DefaultStats()->mempoolCollector->getSamplesForPrecision(precision, timeFrom);

from.setTime_t(timeFrom);
return samples;
}

// Handlers for core signals
static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress)
{
Expand Down Expand Up @@ -313,6 +330,11 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
}
}

static void MempoolStatsDidChange(ClientModel *clientmodel)
{
QMetaObject::invokeMethod(clientmodel, "updateMempoolStats", Qt::QueuedConnection);
}

void ClientModel::subscribeToCoreSignals()
{
// Connect signals to client
Expand All @@ -323,6 +345,8 @@ void ClientModel::subscribeToCoreSignals()
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false));
uiInterface.NotifyHeaderTip.connect(boost::bind(BlockTipChanged, this, _1, _2, true));

CStats::DefaultStats()->MempoolStatsDidChange.connect(boost::bind(MempoolStatsDidChange, this));
}

void ClientModel::unsubscribeFromCoreSignals()
Expand All @@ -335,4 +359,6 @@ void ClientModel::unsubscribeFromCoreSignals()
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false));
uiInterface.NotifyHeaderTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, true));

CStats::DefaultStats()->MempoolStatsDidChange.disconnect(boost::bind(MempoolStatsDidChange, this));
}
11 changes: 11 additions & 0 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include <atomic>

#include "stats/stats.h"

class AddressTableModel;
class BanTableModel;
class OptionsModel;
class PeerTableModel;
Expand Down Expand Up @@ -84,6 +87,9 @@ class ClientModel : public QObject
mutable std::atomic<int> cachedBestHeaderHeight;
mutable std::atomic<int64_t> cachedBestHeaderTime;

MempoolSamplesVector getMempoolStatsInRange(unsigned int precision, QDateTime &from);
// , QDateTime &to);

private:
OptionsModel *optionsModel;
PeerTableModel *peerTableModel;
Expand All @@ -108,12 +114,17 @@ class ClientModel : public QObject
// Show progress dialog e.g. for verifychain
void showProgress(const QString &title, int nProgress);

void mempoolStatsDidUpdate();

public Q_SLOTS:
void updateTimer();
void updateNumConnections(int numConnections);
void updateNetworkActive(bool networkActive);
void updateAlert();
void updateBanlist();

/* stats stack */
void updateMempoolStats();
};

#endif // BITCOIN_QT_CLIENTMODEL_H
44 changes: 44 additions & 0 deletions src/qt/forms/mempoolstats.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MempoolStats</class>
<widget class="QWidget" name="MempoolStats">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>380</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>480</width>
<height>380</height>
</size>
</property>
<property name="windowTitle">
<string>Mempool Stats</string>
</property>
<widget class="QGraphicsView" name="graphicsView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>256</width>
<height>200</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Loading