diff --git a/rbkit-lib/CMakeLists.txt b/rbkit-lib/CMakeLists.txt index 6dd725a..bca16eb 100644 --- a/rbkit-lib/CMakeLists.txt +++ b/rbkit-lib/CMakeLists.txt @@ -18,7 +18,6 @@ include_directories( QT5_WRAP_UI(RBKIT_UI_HEADERS - ui/rbkitmainwindow.ui ui/askhost.ui ui/heapdumpform.ui ui/memoryview.ui @@ -67,6 +66,7 @@ add_library(rbkit ui/centralwidget.cpp ui/ribbontoolbar.cpp ui/cpuview.cpp + ui/stackedwidget.cpp model/cpunode.cpp model/cpuprof.cpp model/cpustorage.cpp @@ -104,6 +104,7 @@ add_library(rbkit ui/centralwidget.h ui/ribbontoolbar.h ui/cpuview.h + ui/stackedwidget.h layoututil.hpp common.h diff --git a/rbkit-lib/model/cpuprof.cpp b/rbkit-lib/model/cpuprof.cpp index b9ad733..7c51258 100644 --- a/rbkit-lib/model/cpuprof.cpp +++ b/rbkit-lib/model/cpuprof.cpp @@ -29,7 +29,6 @@ void RBKit::CpuProf::parseFrames(QMap frames) void RBKit::CpuProf::decodeMap(QList > data) { for(int i = 0; i < data.size() ; i++) { - //qDebug() << data[i]; //detect starting of new frame parseFrames(data[i]); store()->incrementSampleCount(); @@ -37,17 +36,3 @@ void RBKit::CpuProf::decodeMap(QList > data) store()->updateSelfCount(); store()->clearFrameStack(); } - -void RBKit::CpuProf::startTraversals() -{ - qDebug() << "STARTING TRAVERSALS\n\n"; - //flatprofile traversal - //store()->traverseFlatProfile(); - - qDebug() << "\n\n Call Graph"; - //callgraph traversal - //store()->handleCallGraph(); - - //setting the default view as call graph - //store()->changeToCallGraph(); -} diff --git a/rbkit-lib/model/cpuprof.h b/rbkit-lib/model/cpuprof.h index 1c34092..aa97016 100644 --- a/rbkit-lib/model/cpuprof.h +++ b/rbkit-lib/model/cpuprof.h @@ -14,9 +14,6 @@ namespace RBKit void decodeMap(QList> data); void parseFrames(QMap frames); - //handeling traversals - void startTraversals(); - private: inline CpuStoragePtr store() { return CpuStorage::getStorage(); diff --git a/rbkit-lib/model/cpustorage.cpp b/rbkit-lib/model/cpustorage.cpp index a98a8d6..bcbb4f5 100644 --- a/rbkit-lib/model/cpustorage.cpp +++ b/rbkit-lib/model/cpustorage.cpp @@ -10,7 +10,6 @@ RBKit::CpuStorage::CpuStorage() void RBKit::CpuStorage::addNewNode(QMap data) { - //qDebug() << data; auto methodName = data[RBKit::ECeMethodName].toString(); RBKit::CpuNodePtr newNode( new RBKit::CpuNode(methodName, @@ -27,7 +26,6 @@ void RBKit::CpuStorage::addNewNode(QMap data) // increment total count newNode->incrementTotalCount(); - qDebug() << "----------incrementing total count------------"; //add to current frame stack if(currentStack.empty()) { @@ -53,10 +51,8 @@ bool RBKit::CpuStorage::exists(QVariant name) QString methodName = name.toString(); QHash::iterator iter = nodes.find(methodName); if(iter == nodes.end()) { - qDebug() << methodName << " does not exists"; return false; } else { - qDebug() << methodName << " exists"; return true; } } @@ -66,16 +62,8 @@ unsigned long long RBKit::CpuStorage::getSampleCount() return sample_count; } -void RBKit::CpuStorage::traverseNodes() -{ - for(QHash::iterator i = nodes.begin(); i != nodes.end(); i++) { - qDebug() << "" << *i.value(); - } -} - void RBKit::CpuStorage::clearFrameStack() { - qDebug() << "Reset Frame Stack"; currentStack.clear(); } @@ -84,8 +72,6 @@ void RBKit::CpuStorage::traverseFlatProfile(QStandardItem &fgRootNode) int indent; char space = ' '; for(QHash::iterator node = nodes.begin(); node != nodes.end(); node++) { - //qDebug() << "\n=====================\n"; - //qDebug() << "\n" + node.value()->getMethodName(); QList topLevelMethod = prepareRow(node.value()->getMethodName(), node.value()->getSelfCount(), @@ -95,15 +81,12 @@ void RBKit::CpuStorage::traverseFlatProfile(QStandardItem &fgRootNode) QList calledBy = node.value()->getCalledBy(); indent=4; foreach(RBKit::CpuNodePtr node, calledBy) { - //qDebug() << QString(indent, space) + node->getMethodName(); QList innerMethod = prepareRow(node->getMethodName(), node->getSelfCount(), node->getTotalCount()); topLevelMethod.first()->appendRow(innerMethod); } - //qDebug() << "\n=====================\n"; - //qDebug() << calledBy.size(); } } @@ -135,7 +118,6 @@ void RBKit::CpuStorage::updateExistingMethod(QMap data) //increment the method's total count nodes[methodName]->incrementTotalCount(); - qDebug() << "--------updating total count---------"; } void RBKit::CpuStorage::traverseCallGraph(RBKit::CpuNodePtr startingNode, @@ -146,7 +128,6 @@ void RBKit::CpuStorage::traverseCallGraph(RBKit::CpuNodePtr startingNode, QString methodName = startingNode->getMethodName(); if(!notReached.contains(methodName)) { - //qDebug() << QString(indent, space) + methodName; QList currentMethod = prepareRow(methodName, startingNode.data()->getSelfCount(), @@ -159,7 +140,6 @@ void RBKit::CpuStorage::traverseCallGraph(RBKit::CpuNodePtr startingNode, return; } else { - //qDebug() << QString(indent, space) + methodName; QList currentMethod = prepareRow(methodName, startingNode.data()->getSelfCount(), @@ -173,7 +153,6 @@ void RBKit::CpuStorage::traverseCallGraph(RBKit::CpuNodePtr startingNode, notReached.removeOne(startingNode->getMethodName()); foreach(RBKit::CpuNodePtr node, startingNode->getCalls()) { - //qDebug() << QString(indent,space) + node->getMethodName(); traverseCallGraph(node, cgRootNode, currentMethod.first()); } } @@ -189,7 +168,6 @@ QHash RBKit::CpuStorage::getNodes() void RBKit::CpuStorage::handleCallGraph(QStandardItem &cgRootNode) { notReached = nodes.keys(); - //qDebug() << notReached; while(!notReached.empty()) { CpuStorage::traverseCallGraph(nodes[notReached.front()], cgRootNode); } @@ -204,7 +182,6 @@ RBKit::CpuStoragePtr RBKit::CpuStorage::getStorage() void RBKit::CpuStorage::updateSelfCount() { if(!currentStack.isEmpty()) { - qDebug() << "-------updating self count--------"; QString lastMethod = currentStack.back(); nodes[lastMethod]->incrementSelfCount(); } @@ -238,7 +215,6 @@ void RBKit::CpuStorage::fillCallGraphModel(QStandardItemModel *callGraphModel) void RBKit::CpuStorage::fillFlatProfileModel(QStandardItemModel *flatGraphModel) { - qDebug() << "^^^^^^^^creating flat graph model^^^^^^^^^^^"; QStandardItem *fgRootNode = flatGraphModel->invisibleRootItem(); traverseFlatProfile(*fgRootNode); } diff --git a/rbkit-lib/model/cpustorage.h b/rbkit-lib/model/cpustorage.h index c55204d..3c88485 100644 --- a/rbkit-lib/model/cpustorage.h +++ b/rbkit-lib/model/cpustorage.h @@ -28,7 +28,6 @@ namespace RBKit void updateNewNodeLocation(QString methodName, RBKit::CpuNodePtr); bool exists(QVariant name); unsigned long long getSampleCount(); - void traverseNodes(); void clearFrameStack(); void updateExistingMethod(QMap); void updateSelfCount(); diff --git a/rbkit-lib/ui/actiontoolbar.cpp b/rbkit-lib/ui/actiontoolbar.cpp index 14d6b7a..e4a956a 100644 --- a/rbkit-lib/ui/actiontoolbar.cpp +++ b/rbkit-lib/ui/actiontoolbar.cpp @@ -26,8 +26,8 @@ static void toggleConnectButtonState(ConnectionStates state, QToolButton *btn) { } } -ActionToolbar::ActionToolbar(CentralWidget *widget) - : centralWidget(widget) +ActionToolbar::ActionToolbar(AppMainwindow &window, CentralWidget *widget) + : centralWidget(widget), window(window) { Q_INIT_RESOURCE(tool_icons); connectionState = DISCONNECTED; @@ -157,7 +157,7 @@ void ActionToolbar::setupToolBar() QIcon(":/icons/Compare-32.png"), "cpu_profiling"); connect(stopCPUButton, &QToolButton::clicked, this, &ActionToolbar::performStopCPUAction); - connect(this, SIGNAL(stopCPUProfiling()), centralWidget, SLOT(newCpuView())); + connect(this, SIGNAL(stopCPUProfiling()), &window, SLOT(newCpuView())); toolBar->loadStyleSheet(":/icons/style.css"); } @@ -222,3 +222,11 @@ void ActionToolbar::disconnectedFromSocket() centralWidget->appDisconnected(); disableProfileActions(); } + +void ActionToolbar::connectTabChangedSignal(AppMainwindow *window) +{ + connect(toolBar, + SIGNAL(changeTab(int)), + window, + SLOT(tabChanged(int))); +} diff --git a/rbkit-lib/ui/actiontoolbar.h b/rbkit-lib/ui/actiontoolbar.h index 47edbac..bed4669 100644 --- a/rbkit-lib/ui/actiontoolbar.h +++ b/rbkit-lib/ui/actiontoolbar.h @@ -12,10 +12,14 @@ #include "subscriber.h" #include "common.h" #include "memoryview.h" +#include "appmainwindow.h" +#include "stackedwidget.h" class QToolButton; class CentralWidget; class QTimer; +class AppMainwindow; +class StackedWidget; enum ConnectionStates { DISCONNECTED = 0, @@ -35,8 +39,9 @@ class ActionToolbar : public QObject Subscriber *subscriber; ConnectionStates connectionState; QThread subscriberThread; + AppMainwindow &window; public: - explicit ActionToolbar(CentralWidget *widget); + explicit ActionToolbar(AppMainwindow &window , CentralWidget *widget); void enableProfileActions(); void disableProfileActions(); void setupToolBar(); @@ -46,6 +51,7 @@ class ActionToolbar : public QObject RBKit::MemoryView *memoryView() const; void disconnectFromSocket(); void shutDownApp(); + void connectTabChangedSignal(AppMainwindow *window); private: QToolButton *gcButton; diff --git a/rbkit-lib/ui/appmainwindow.cpp b/rbkit-lib/ui/appmainwindow.cpp index bbe7d55..8d7882b 100644 --- a/rbkit-lib/ui/appmainwindow.cpp +++ b/rbkit-lib/ui/appmainwindow.cpp @@ -8,8 +8,36 @@ AppMainwindow::AppMainwindow(QWidget *parent) : QMainWindow(parent) { - centralWidget = new CentralWidget(this); - setCentralWidget(centralWidget); + QWidget *mainWidget = new QWidget(this); + + mainLayout = new QVBoxLayout(); + + stackedWidget = new StackedWidget(this); + setCentralWidget(mainWidget); + + centralMemoryWidget = new CentralWidget(stackedWidget, this); + int index = stackedWidget->addWidget(centralMemoryWidget); + + actionToolBar = QSharedPointer::create(*this, centralMemoryWidget); + + cpuTab = new QTabWidget(stackedWidget); + cpuTab->setTabsClosable(true); + connect(cpuTab, + SIGNAL(tabCloseRequested(int)), + this, + SLOT(closeCpuTab(int))); + + stackedWidget->addWidget(cpuTab); + + stackedWidget->setCurrentIndex(index); + + actionToolBar.data()->connectTabChangedSignal(this); + + mainLayout->addWidget(actionToolBar.data()->getToolBar(), 0, Qt::AlignTop); + mainLayout->addWidget(stackedWidget, 1); + + mainWidget->setLayout(mainLayout); + mainWidget->show(); appStatusBar = new QStatusBar(this); setStatusBar(appStatusBar); @@ -26,13 +54,38 @@ AppMainwindow::AppMainwindow(QWidget *parent) : QMainWindow(parent) qRegisterMetaType(); } -/*CpuViewPtr AppMainwindow::getCpuView() +void AppMainwindow::newCpuView() { - return centralWidget->getCpuViewPtr(); -}*/ + QSharedPointer cpuView(new CpuView()); + cpuTab->addTab(cpuView.data(), "Cpu Tree"); + cpuViewList.append(cpuView); + + connect(cpuView.data(), + SIGNAL(fillCallGraph(QStandardItemModel*)), + RBKit::CpuStorage::getStorage().data(), + SLOT(fillCallGraphModel(QStandardItemModel*))); + + connect(cpuView.data(), + SIGNAL(fillFlatProfile(QStandardItemModel*)), + RBKit::CpuStorage::getStorage().data(), + SLOT(fillFlatProfileModel(QStandardItemModel*))); + + emit cpuView.data()->fillCallGraph(cpuView->callGraphModel); + emit cpuView.data()->fillFlatProfile(cpuView->flatGraphModel); +} AppMainwindow::~AppMainwindow() { - delete centralWidget; + delete centralMemoryWidget; } +void AppMainwindow::tabChanged(int tab) +{ + stackedWidget->setCurrentIndex(tab); +} + +void AppMainwindow::closeCpuTab(int index) +{ + cpuTab->removeTab(index); + cpuViewList.removeAt(index); +} diff --git a/rbkit-lib/ui/appmainwindow.h b/rbkit-lib/ui/appmainwindow.h index e8377ae..a0c3423 100644 --- a/rbkit-lib/ui/appmainwindow.h +++ b/rbkit-lib/ui/appmainwindow.h @@ -2,18 +2,30 @@ #define APPMAINWINDOW_H #include +#include "stackedwidget.h" #include "centralwidget.h" +#include "actiontoolbar.h" +#include "cpuview.h" class QStatusBar; class QLabel; class QProgressBar; +class StackedWidget; +class ActionToolbar; class AppMainwindow : public QMainWindow { Q_OBJECT - CentralWidget *centralWidget; + StackedWidget *stackedWidget; + CentralWidget *centralMemoryWidget; + QTabWidget *cpuTab; QLabel *statusLabel; + QSharedPointer actionToolBar; + QVBoxLayout *mainLayout; + + QList> cpuViewList; + public: explicit AppMainwindow(QWidget *parent = 0); ~AppMainwindow(); @@ -23,6 +35,9 @@ class AppMainwindow : public QMainWindow signals: public slots: + void tabChanged(int); + void newCpuView(); + void closeCpuTab(int); }; #endif // APPMAINWINDOW_H diff --git a/rbkit-lib/ui/centralwidget.cpp b/rbkit-lib/ui/centralwidget.cpp index 367728c..e77f261 100644 --- a/rbkit-lib/ui/centralwidget.cpp +++ b/rbkit-lib/ui/centralwidget.cpp @@ -110,7 +110,6 @@ void CentralWidget::tabClosed(int index) return; chartingTab->removeTab(index); snapshotState->removeSnapshot(index); - cpuViewHash.remove(index); } void CentralWidget::onDiffSnapshotsSelected(QList selectedSnapshots) @@ -129,12 +128,10 @@ QList CentralWidget::diffableSnapshotVersions() return snapshotState->diffableSnapshotVersions(); } -CentralWidget::CentralWidget(AppMainwindow *window) : QWidget(window) +CentralWidget::CentralWidget(StackedWidget *mainWindow, AppMainwindow *window) : QWidget(mainWindow) , mainWindow(window) { mainLayout = new QVBoxLayout(); - actionToolBar = QSharedPointer::create(this); - mainLayout->addWidget(actionToolBar->getToolBar(), 0, Qt::AlignTop); snapshotProgressTimer = new QTimer(this); snapshotState = new RBKit::SnapshotState(); @@ -154,7 +151,7 @@ CentralWidget::CentralWidget(AppMainwindow *window) : QWidget(window) disableCloseButtonOnFirstTab(chartingTab.data()); makeMarginSpacingZero(mainLayout); setLayout(mainLayout); - actionToolBar->disableProfileActions(); + //actionToolBar->disableProfileActions(); } CentralWidget::~CentralWidget() @@ -169,26 +166,6 @@ void CentralWidget::setupCentralView() chartingTab->addTab(memoryView.data(), "Object Charts"); } -void CentralWidget::newCpuView() -{ - QSharedPointer cpuView(new CpuView(this)); - int index = chartingTab->addTab(cpuView.data(), "Cpu Tree"); - cpuViewHash[index] = cpuView; - - connect(cpuView.data(), - SIGNAL(fillCallGraph(QStandardItemModel*)), - RBKit::CpuStorage::getStorage().data(), - SLOT(fillCallGraphModel(QStandardItemModel*))); - - connect(cpuView.data(), - SIGNAL(fillFlatProfile(QStandardItemModel*)), - RBKit::CpuStorage::getStorage().data(), - SLOT(fillFlatProfileModel(QStandardItemModel*))); - - emit cpuView.data()->fillCallGraph(cpuView->callGraphModel); - emit cpuView.data()->fillFlatProfile(cpuView->flatGraphModel); -} - void CentralWidget::showStatusMessage(const QString &message) const { mainWindow->appStatusBar->showMessage(message); @@ -222,8 +199,3 @@ bool CentralWidget::attemptMemorySnapshot() return true; } } - -/*CpuViewPtr CentralWidget::getCpuViewPtr() -{ - return cpuView; -}*/ diff --git a/rbkit-lib/ui/centralwidget.h b/rbkit-lib/ui/centralwidget.h index 85e250a..53f7380 100644 --- a/rbkit-lib/ui/centralwidget.h +++ b/rbkit-lib/ui/centralwidget.h @@ -14,10 +14,12 @@ class QHBoxLayout; class QTabWidget; class AppMainwindow; class HeapDumpForm; +class ActionToolbar; #include "memoryview.h" #include "model/snapshotstate.h" #include "cpuview.h" +#include class CentralWidget : public QWidget @@ -27,14 +29,13 @@ class CentralWidget : public QWidget QVBoxLayout* mainLayout; QSharedPointer chartingTab; QSharedPointer memoryView; - QHash> cpuViewHash; AppMainwindow *mainWindow; RBKit::SnapshotState *snapshotState; QTimer *snapshotProgressTimer; QList diffableSnapshotVersions(); public: - explicit CentralWidget(AppMainwindow *mainWindow); + explicit CentralWidget(StackedWidget *mainWindow, AppMainwindow *window); ~CentralWidget(); void setupCentralView(); void showStatusMessage(const QString &message) const; @@ -55,7 +56,6 @@ public slots: void receiveOldGenStats(QVariantMap map); void objectDumpAvailable(int snapshotVersion); void updateProgressBar(); - void newCpuView(); private slots: void tabClosed(int index); void onDiffSnapshotsSelected(QList selectedSnapshots); diff --git a/rbkit-lib/ui/cpuview.h b/rbkit-lib/ui/cpuview.h index 1dc80d2..4ec11bb 100644 --- a/rbkit-lib/ui/cpuview.h +++ b/rbkit-lib/ui/cpuview.h @@ -3,6 +3,7 @@ #include #include +//#include "appmainwindow.h" namespace Ui { class CpuView; diff --git a/rbkit-lib/ui/rbkitmainwindow.ui b/rbkit-lib/ui/rbkitmainwindow.ui deleted file mode 100644 index c50d7f7..0000000 --- a/rbkit-lib/ui/rbkitmainwindow.ui +++ /dev/null @@ -1,171 +0,0 @@ - - - RbkitMainWindow - - - - 0 - 0 - 1100 - 840 - - - - - 850 - 840 - - - - Rbkit - A Ruby Profiler - - - - - - - QTabWidget::North - - - -1 - - - true - - - - - - - - - 0 - 0 - 1100 - 22 - - - - - &File - - - - - - - &Help - - - - - - &Memory Profiling - - - - - - - - - - - - - toolBar - - - true - - - false - - - - 16 - 16 - - - - Qt::ToolButtonTextBesideIcon - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - :/icons/connect-48.png:/icons/connect-48.png - - - &Connect - - - - - &Quit - - - Quit Rbkit - - - Ctrl+Q - - - - - &About Rbkit - - - - - - :/icons/startgc-48.png:/icons/startgc-48.png - - - &Start GC - - - - - - :/icons/snapshot-48.png:/icons/snapshot-48.png - - - Heap Snapshot - - - Record heapsnapshot - - - - - - :/icons/Compare-48.png:/icons/Compare-48.png - - - Compare Snapshots - - - Compare Heapsnpshot - - - - - - - - diff --git a/rbkit-lib/ui/ribbontoolbar.cpp b/rbkit-lib/ui/ribbontoolbar.cpp index 89bea8e..84d8cf3 100644 --- a/rbkit-lib/ui/ribbontoolbar.cpp +++ b/rbkit-lib/ui/ribbontoolbar.cpp @@ -125,5 +125,7 @@ void RibbonToolBar::tabSelectionChanged(int index) containerData->hideWidget(layout1); } } + + emit changeTab(index); //for triggring the change in stacked widget } diff --git a/rbkit-lib/ui/ribbontoolbar.h b/rbkit-lib/ui/ribbontoolbar.h index a714064..8522626 100644 --- a/rbkit-lib/ui/ribbontoolbar.h +++ b/rbkit-lib/ui/ribbontoolbar.h @@ -66,7 +66,7 @@ class RibbonToolBar : public QWidget QToolButton* addRibbonAction(const QString &actionName, const QString &actionIdentifier, const QIcon &icon, const QString &tabIdentifier); signals: - + void changeTab(int index); //for triggring the change in stacked widget public slots: void tabSelectionChanged(int index); }; diff --git a/rbkit-lib/ui/stackedwidget.cpp b/rbkit-lib/ui/stackedwidget.cpp new file mode 100644 index 0000000..5040b85 --- /dev/null +++ b/rbkit-lib/ui/stackedwidget.cpp @@ -0,0 +1,7 @@ +#include "stackedwidget.h" + +StackedWidget::StackedWidget(AppMainwindow *mainWindow) + : QStackedWidget(mainWindow) +{ + +} diff --git a/rbkit-lib/ui/stackedwidget.h b/rbkit-lib/ui/stackedwidget.h new file mode 100644 index 0000000..288ee27 --- /dev/null +++ b/rbkit-lib/ui/stackedwidget.h @@ -0,0 +1,14 @@ +#ifndef STACKEDWIDGET_H +#define STACKEDWIDGET_H +#include +#include "appmainwindow.h" + +class AppMainwindow; + +class StackedWidget : public QStackedWidget +{ +public: + explicit StackedWidget(AppMainwindow* mainWindow); +}; + +#endif // STACKEDWIDGET_H