Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from code-mancers/implement-cpu-actions
Implement cpu actions
- Loading branch information
Showing
20 changed files
with
876 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef COMMON_H | ||
#define COMMON_H | ||
|
||
#include <QSharedPointer> | ||
#include <QDebug> | ||
#include <QString> | ||
|
||
#endif // COMMON_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#cpu_profiling { | ||
} | ||
|
||
#ribbon_toolbar QToolButton { | ||
background: #EDEDED; | ||
border: none; | ||
} | ||
|
||
#start_gc { | ||
padding: 3px; | ||
} | ||
|
||
#ribbon_tab_container { | ||
background: #EDEDED; | ||
} | ||
|
||
#ribbon_tab_container QToolButton { | ||
padding: 2px; | ||
} | ||
|
||
#ribbon_toolbar QToolButton:hover { | ||
background: #CCCCCC; | ||
} | ||
#ribbon_toolbar QToolButton:pressed { | ||
background: #b4b4b4; | ||
} | ||
|
||
/* Style the tab using the tab sub-control. Note that | ||
it reads QTabBar _not_ QTabWidget */ | ||
QTabBar::tab#action_tabbar { | ||
background: #d3d3d3; | ||
min-width: 12ex; | ||
border: 1px solid #f6f6f6; | ||
padding-left: 30px; | ||
padding-right: 30px; | ||
padding-top: 1px; | ||
padding-bottom: 1px; | ||
} | ||
|
||
QTabBar::tab:selected#action_tabbar { | ||
background: #EDEDED; | ||
border: none; | ||
} | ||
|
||
QTabBar::tab:hover#action_tabbar { | ||
background: #e3e3e3; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef LAYOUTUTIL_HPP | ||
#define LAYOUTUTIL_HPP | ||
|
||
#include <QBoxLayout> | ||
#include "common.h" | ||
|
||
inline void makeMarginSpacingZero(QBoxLayout *layout) { | ||
layout->setSpacing(0); | ||
layout->setMargin(0); | ||
layout->setContentsMargins(0, 0, 0, 0); | ||
} | ||
|
||
inline void makeMarginSpacingZero(QSharedPointer<QBoxLayout> layout) { | ||
makeMarginSpacingZero(layout.data()); | ||
} | ||
|
||
#endif // LAYOUTUTIL_HPP | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,209 @@ | ||
#include "actiontoolbar.h" | ||
|
||
#include "ui_rbkitmainwindow.h" | ||
#include <QIcon> | ||
#include <QToolButton> | ||
#include <QStatusBar> | ||
#include <QMessageBox> | ||
#include <QVariantMap> | ||
|
||
ActionToolbar::ActionToolbar(Ui::RbkitMainWindow *_ui) | ||
: ui(_ui) | ||
#include "centralwidget.h" | ||
#include "processdetail.h" | ||
|
||
static void toggleConnectButtonState(ConnectionStates state, QToolButton *btn) { | ||
switch (state) { | ||
case CONNECTED: | ||
btn->setText("&Disconnect"); | ||
btn->setIcon(QIcon(":/icons/disconnect-32.png")); | ||
break; | ||
case DISCONNECTED: | ||
btn->setText("&Connect"); | ||
btn->setIcon(QIcon(":/icons/connect-32.png")); | ||
break; | ||
default: | ||
btn->setText("&Disconnect"); | ||
btn->setIcon(QIcon(":/icons/disconnect-32.png")); | ||
break; | ||
} | ||
} | ||
|
||
ActionToolbar::ActionToolbar(CentralWidget *widget) | ||
: centralWidget(widget) | ||
{ | ||
Q_INIT_RESOURCE(tool_icons); | ||
connectionState = DISCONNECTED; | ||
setupToolBar(); | ||
} | ||
|
||
void ActionToolbar::enableProfileActions() | ||
{ | ||
ui->actionCompare_Heapsnapshots->setEnabled(true); | ||
ui->actionHeap_Snapshot->setEnabled(true); | ||
ui->action_Trigger_GC->setEnabled(true); | ||
gcButton->setEnabled(true); | ||
compareSnapshotButton->setEnabled(true); | ||
snapshotButton->setEnabled(true); | ||
gcButton->setEnabled(true); | ||
} | ||
|
||
void ActionToolbar::disableProfileActions() | ||
{ | ||
ui->actionCompare_Heapsnapshots->setDisabled(true); | ||
ui->actionHeap_Snapshot->setDisabled(true); | ||
ui->action_Trigger_GC->setDisabled(true); | ||
gcButton->setDisabled(true); | ||
compareSnapshotButton->setDisabled(true); | ||
snapshotButton->setDisabled(true); | ||
gcButton->setDisabled(true); | ||
} | ||
|
||
RibbonToolBar *ActionToolbar::getToolBar() const | ||
{ | ||
return toolBar; | ||
} | ||
|
||
void ActionToolbar::setupSubscriber() | ||
{ | ||
//Create a subscriber and move it to it's own thread | ||
subscriber = new Subscriber(memoryView()->getJsBridge()); | ||
subscriber->moveToThread(&subscriberThread); | ||
|
||
//Events to/from parent/subcriber thread | ||
connect(&subscriberThread, &QThread::finished, subscriber, &QObject::deleteLater); | ||
connect(&subscriberThread, SIGNAL(started()), subscriber, SLOT(startSubscriber())); | ||
connect(this, SIGNAL(connectToSocket(QString, QString)), | ||
subscriber, SLOT(startListening(QString, QString))); | ||
connect(this, SIGNAL(triggerGc()), subscriber, SLOT(triggerGc())); | ||
connect(this, SIGNAL(takeSnapshot()), subscriber, SLOT(takeSnapshot())); | ||
|
||
connect(subscriber, &Subscriber::errored, centralWidget, &CentralWidget::onError); | ||
connect(subscriber, &Subscriber::connected, this, &ActionToolbar::connectedToSocket); | ||
connect(subscriber, &Subscriber::disconnected, this, | ||
&ActionToolbar::disconnectedFromSocket); | ||
connect(subscriber, &Subscriber::objectDumpAvailable, | ||
centralWidget, &CentralWidget::objectDumpAvailable); | ||
|
||
connect(subscriber, &Subscriber::youngGenStats, | ||
centralWidget, &CentralWidget::receiveYoungGenStats); | ||
connect(subscriber, &Subscriber::secondGenStats, | ||
centralWidget, &CentralWidget::receiveSecondGenStats); | ||
connect(subscriber, &Subscriber::oldGenStats, | ||
centralWidget, &CentralWidget::receiveOldGenStats); | ||
|
||
subscriberThread.start(); | ||
} | ||
|
||
void ActionToolbar::askForServerInfo() | ||
{ | ||
if(host.size() == 0) { | ||
askHost = new AskHost(); | ||
connect(askHost, SIGNAL(userHasSelectedHost(QString, QString)), | ||
this, SLOT(useSelectedHost(QString, QString))); | ||
askHost->show(); | ||
} | ||
} | ||
|
||
RBKit::MemoryView *ActionToolbar::memoryView() const | ||
{ | ||
return centralWidget->getMemoryView().data(); | ||
} | ||
|
||
void ActionToolbar::disconnectFromSocket() | ||
{ | ||
qDebug() << "Attempting to stop the thread"; | ||
subscriberThread.requestInterruption(); | ||
subscriberThread.exit(); | ||
subscriberThread.wait(); | ||
qDebug() << "Thread has been stopped"; | ||
} | ||
|
||
void ActionToolbar::shutDownApp() | ||
{ | ||
disconnectFromSocket(); | ||
} | ||
|
||
void ActionToolbar::setupToolBar() | ||
{ | ||
toolBar = new RibbonToolBar(centralWidget); | ||
connectButton = toolBar->addRibbonAction("Connect", "connect_action", QIcon(":/icons/connect-32.png")); | ||
connect(connectButton, &QToolButton::clicked, this, &ActionToolbar::attemptConnection); | ||
|
||
|
||
toolBar->addRibbonTab("Memory Profiling", "memory_profiling"); | ||
toolBar->addRibbonTab("CPU Profiling", "cpu_profiling"); | ||
|
||
compareSnapshotButton = toolBar->addRibbonAction("Compare Snapshot", | ||
"compare_snapshot", | ||
QIcon(":/icons/Compare-32.png"), | ||
"memory_profiling"); | ||
connect(compareSnapshotButton, &QToolButton::clicked, | ||
this, &ActionToolbar::compareSnapshots); | ||
|
||
snapshotButton = toolBar->addRibbonAction("Take Snapshot", "take_snapshot", | ||
QIcon(":/icons/snapshot-32.png"), | ||
"memory_profiling"); | ||
connect(snapshotButton, &QToolButton::clicked, this, &ActionToolbar::takeSnapshotAction); | ||
|
||
gcButton = toolBar->addRibbonAction("Start GC", | ||
"start_gc", | ||
QIcon(":/icons/startgc-32.png"), | ||
"memory_profiling"); | ||
connect(gcButton, &QToolButton::clicked, this, &ActionToolbar::performGCAction); | ||
|
||
|
||
toolBar->addRibbonAction("Start CPU Profiling", | ||
"start_cpu_profile", | ||
QIcon(":/icons/disconnect-32.png"), | ||
"cpu_profiling"); | ||
toolBar->addRibbonAction("Stop Profiling", | ||
"stop_cpu_profiling", | ||
QIcon(":/icons/Compare-32.png"), | ||
"cpu_profiling"); | ||
toolBar->loadStyleSheet(":/icons/style.css"); | ||
} | ||
|
||
void ActionToolbar::performGCAction() | ||
{ | ||
emit triggerGc(); | ||
} | ||
|
||
void ActionToolbar::takeSnapshotAction() | ||
{ | ||
if (centralWidget->attemptMemorySnapshot()) { | ||
emit takeSnapshot(); | ||
} | ||
} | ||
|
||
void ActionToolbar::attemptConnection() | ||
{ | ||
if (connectionState == DISCONNECTED) { | ||
setupSubscriber(); | ||
askForServerInfo(); | ||
} else { | ||
disconnectFromSocket(); | ||
} | ||
} | ||
|
||
void ActionToolbar::compareSnapshots() | ||
{ | ||
centralWidget->compareSnapshots(); | ||
} | ||
|
||
void ActionToolbar::useSelectedHost(QString commandSocket, QString eventSocket) | ||
{ | ||
askHost->close(); | ||
connectionState = CONNECTION_IN_PROGRESS; | ||
toggleConnectButtonState(connectionState, connectButton); | ||
emit connectToSocket(commandSocket, eventSocket); | ||
} | ||
|
||
void ActionToolbar::connectedToSocket() | ||
{ | ||
RBKit::SqlConnectionPool::getInstance()->setupDatabase(); | ||
enableProfileActions(); | ||
connectionState = CONNECTED; | ||
toggleConnectButtonState(connectionState, connectButton); | ||
centralWidget->showStatusMessage("Currently Profiling Ruby application"); | ||
memoryView()->processDetail->displayProcessDetail(); | ||
} | ||
|
||
void ActionToolbar::disconnectedFromSocket() | ||
{ | ||
connectionState = DISCONNECTED; | ||
toggleConnectButtonState(connectionState, connectButton); | ||
centralWidget->appDisconnected(); | ||
disableProfileActions(); | ||
} |
Oops, something went wrong.