Skip to content

Commit

Permalink
Merge pull request #157 from code-mancers/implement-cpu-actions
Browse files Browse the repository at this point in the history
Implement cpu actions
  • Loading branch information
iffyuva committed Mar 10, 2015
2 parents 5500fb4 + b2ad5e8 commit 6c5f71b
Show file tree
Hide file tree
Showing 20 changed files with 876 additions and 408 deletions.
4 changes: 2 additions & 2 deletions rbkit-app/main.cpp
@@ -1,7 +1,7 @@
#include "ui/rbkitmainwindow.h"
#include <QApplication>
#include "model/appstate.h"
#include <QIcon>
#include "ui/appmainwindow.h"

int main(int argc, char *argv[])
{
Expand All @@ -10,7 +10,7 @@ int main(int argc, char *argv[])

RBKit::AppState::getInstance()->setAppState("connection_established", false);

RbkitMainWindow mainWindow;
AppMainwindow mainWindow;
mainWindow.setWindowIcon(QIcon(":/rbkit.icns"));
app.processEvents();
mainWindow.show();
Expand Down
9 changes: 9 additions & 0 deletions rbkit-lib/common.h
@@ -0,0 +1,9 @@
#ifndef COMMON_H
#define COMMON_H

#include <QSharedPointer>
#include <QDebug>
#include <QString>

#endif // COMMON_H

48 changes: 48 additions & 0 deletions rbkit-lib/icons/style.css
@@ -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;
}

18 changes: 18 additions & 0 deletions rbkit-lib/layoututil.hpp
@@ -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

14 changes: 10 additions & 4 deletions rbkit-lib/rbkit-lib.pro
Expand Up @@ -34,15 +34,17 @@ SOURCES += \
ui/diffviewform.cpp \
ui/heapdumpform.cpp \
ui/memoryview.cpp \
ui/rbkitmainwindow.cpp \
ui/actiontoolbar.cpp \
ui/aboutdialog.cpp \
model/parentobject.cpp \
ui/parentviewform.cpp \
model/heap_item_types/baseheapitem.cpp \
model/heap_item_types/heapitem.cpp \
model/heap_item_types/leafitem.cpp \
ui/processdetail.cpp
ui/processdetail.cpp \
ui/appmainwindow.cpp \
ui/centralwidget.cpp \
ui/ribbontoolbar.cpp

HEADERS += \
subscriber.h \
Expand All @@ -65,7 +67,6 @@ HEADERS += \
ui/diffviewform.h \
ui/heapdumpform.h \
ui/memoryview.h \
ui/rbkitmainwindow.h \
ui/actiontoolbar.h \
ui/aboutdialog.h \
model/parentobject.h \
Expand All @@ -74,7 +75,12 @@ HEADERS += \
model/heap_item_types/heapitem.h \
model/heap_item_types/leafitem.h \
model/snapshotstate.h \
ui/processdetail.h
ui/processdetail.h \
ui/appmainwindow.h \
ui/centralwidget.h \
ui/ribbontoolbar.h \
layoututil.hpp \
common.h

FORMS += \
ui/rbkitmainwindow.ui \
Expand Down
2 changes: 0 additions & 2 deletions rbkit-lib/subscriber.cpp
Expand Up @@ -29,8 +29,6 @@ QVariantMap hashToQVarMap(const QHash<K, V>&& hash) {
return map;
}



nzmqt::ZMQContext *Subscriber::getContext() const
{
return context;
Expand Down
1 change: 1 addition & 0 deletions rbkit-lib/tool_icons.qrc
Expand Up @@ -16,5 +16,6 @@
<file>icons/Compare-32.png</file>
<file>icons/Compare-48.png</file>
<file>icons/rbkitlogo-128.png</file>
<file>icons/style.css</file>
</qresource>
</RCC>
205 changes: 196 additions & 9 deletions rbkit-lib/ui/actiontoolbar.cpp
@@ -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();
}

0 comments on commit 6c5f71b

Please sign in to comment.