Skip to content
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

Cpu stacked widget #197

Open
wants to merge 9 commits into
base: cpu-profiling
Choose a base branch
from
2 changes: 2 additions & 0 deletions rbkit-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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
Expand Down Expand Up @@ -104,6 +105,7 @@ add_library(rbkit
ui/centralwidget.h
ui/ribbontoolbar.h
ui/cpuview.h
ui/stackedwidget.h
layoututil.hpp
common.h

Expand Down
15 changes: 0 additions & 15 deletions rbkit-lib/model/cpuprof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,10 @@ void RBKit::CpuProf::parseFrames(QMap<int, QVariant> frames)
void RBKit::CpuProf::decodeMap(QList<QMap<int, QVariant> > data)
{
for(int i = 0; i < data.size() ; i++) {
//qDebug() << data[i];
//detect starting of new frame
parseFrames(data[i]);
store()->incrementSampleCount();
}
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();
}
3 changes: 0 additions & 3 deletions rbkit-lib/model/cpuprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace RBKit
void decodeMap(QList<QMap<int, QVariant>> data);
void parseFrames(QMap<int, QVariant> frames);

//handeling traversals
void startTraversals();

private:
inline CpuStoragePtr store() {
return CpuStorage::getStorage();
Expand Down
24 changes: 0 additions & 24 deletions rbkit-lib/model/cpustorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RBKit::CpuStorage::CpuStorage()

void RBKit::CpuStorage::addNewNode(QMap<int, QVariant> data)
{
//qDebug() << data;
auto methodName = data[RBKit::ECeMethodName].toString();

RBKit::CpuNodePtr newNode( new RBKit::CpuNode(methodName,
Expand All @@ -27,7 +26,6 @@ void RBKit::CpuStorage::addNewNode(QMap<int, QVariant> data)

// increment total count
newNode->incrementTotalCount();
qDebug() << "----------incrementing total count------------";

//add to current frame stack
if(currentStack.empty()) {
Expand All @@ -53,10 +51,8 @@ bool RBKit::CpuStorage::exists(QVariant name)
QString methodName = name.toString();
QHash<QString, RBKit::CpuNodePtr>::iterator iter = nodes.find(methodName);
if(iter == nodes.end()) {
qDebug() << methodName << " does not exists";
return false;
} else {
qDebug() << methodName << " exists";
return true;
}
}
Expand All @@ -66,16 +62,8 @@ unsigned long long RBKit::CpuStorage::getSampleCount()
return sample_count;
}

void RBKit::CpuStorage::traverseNodes()
{
for(QHash<QString, RBKit::CpuNodePtr>::iterator i = nodes.begin(); i != nodes.end(); i++) {
qDebug() << "" << *i.value();
}
}

void RBKit::CpuStorage::clearFrameStack()
{
qDebug() << "Reset Frame Stack";
currentStack.clear();
}

Expand All @@ -84,8 +72,6 @@ void RBKit::CpuStorage::traverseFlatProfile(QStandardItem &fgRootNode)
int indent;
char space = ' ';
for(QHash<QString, RBKit::CpuNodePtr>::iterator node = nodes.begin(); node != nodes.end(); node++) {
//qDebug() << "\n=====================\n";
//qDebug() << "\n" + node.value()->getMethodName();

QList<QStandardItem*> topLevelMethod = prepareRow(node.value()->getMethodName(),
node.value()->getSelfCount(),
Expand All @@ -95,15 +81,12 @@ void RBKit::CpuStorage::traverseFlatProfile(QStandardItem &fgRootNode)
QList<RBKit::CpuNodePtr> calledBy = node.value()->getCalledBy();
indent=4;
foreach(RBKit::CpuNodePtr node, calledBy) {
//qDebug() << QString(indent, space) + node->getMethodName();

QList<QStandardItem*> innerMethod = prepareRow(node->getMethodName(),
node->getSelfCount(),
node->getTotalCount());
topLevelMethod.first()->appendRow(innerMethod);
}
//qDebug() << "\n=====================\n";
//qDebug() << calledBy.size();
}
}

Expand Down Expand Up @@ -135,7 +118,6 @@ void RBKit::CpuStorage::updateExistingMethod(QMap<int, QVariant> data)

//increment the method's total count
nodes[methodName]->incrementTotalCount();
qDebug() << "--------updating total count---------";
}

void RBKit::CpuStorage::traverseCallGraph(RBKit::CpuNodePtr startingNode,
Expand All @@ -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<QStandardItem*> currentMethod = prepareRow(methodName,
startingNode.data()->getSelfCount(),
Expand All @@ -159,7 +140,6 @@ void RBKit::CpuStorage::traverseCallGraph(RBKit::CpuNodePtr startingNode,
return;

} else {
//qDebug() << QString(indent, space) + methodName;

QList<QStandardItem*> currentMethod = prepareRow(methodName,
startingNode.data()->getSelfCount(),
Expand All @@ -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());
}
}
Expand All @@ -189,7 +168,6 @@ QHash<QString, RBKit::CpuNodePtr> RBKit::CpuStorage::getNodes()
void RBKit::CpuStorage::handleCallGraph(QStandardItem &cgRootNode)
{
notReached = nodes.keys();
//qDebug() << notReached;
while(!notReached.empty()) {
CpuStorage::traverseCallGraph(nodes[notReached.front()], cgRootNode);
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion rbkit-lib/model/cpustorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, QVariant>);
void updateSelfCount();
Expand Down
14 changes: 11 additions & 3 deletions rbkit-lib/ui/actiontoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -222,3 +222,11 @@ void ActionToolbar::disconnectedFromSocket()
centralWidget->appDisconnected();
disableProfileActions();
}

void ActionToolbar::connectTabChangedSignal(AppMainwindow *window)
{
connect(toolBar,
SIGNAL(changeTab(int)),
window,
SLOT(tabChanged(int)));
}
8 changes: 7 additions & 1 deletion rbkit-lib/ui/actiontoolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,8 +39,9 @@ class ActionToolbar : public QObject
Subscriber *subscriber;
ConnectionStates connectionState;
QThread subscriberThread;
AppMainwindow *window;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use sharedpointer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not instantiating AppMainwindow here
this variable will just hold a reference to mainwindow so that some of the function which need to call methods on mainwindow can call them

public:
explicit ActionToolbar(CentralWidget *widget);
explicit ActionToolbar(AppMainwindow *window , CentralWidget *widget);
void enableProfileActions();
void disableProfileActions();
void setupToolBar();
Expand All @@ -46,6 +51,7 @@ class ActionToolbar : public QObject
RBKit::MemoryView *memoryView() const;
void disconnectFromSocket();
void shutDownApp();
void connectTabChangedSignal(AppMainwindow *window);

private:
QToolButton *gcButton;
Expand Down
65 changes: 59 additions & 6 deletions rbkit-lib/ui/appmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,36 @@

AppMainwindow::AppMainwindow(QWidget *parent) : QMainWindow(parent)
{
centralWidget = new CentralWidget(this);
setCentralWidget(centralWidget);
QWidget *mainWidget = new QWidget(this);

mainLayout = new QVBoxLayout();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared pointers! these news are never deleted. im not sure if Qt automatically handles deletes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

centralwidget is only deleted once the rbkit-client itself closes
rest its there all the time in the ui
and we have only one instantiation of centralwidget per app instance

this is also true for mainWidget and mainLayout


stackedWidget = new StackedWidget(this);
setCentralWidget(mainWidget);

centralMemoryWidget = new CentralWidget(stackedWidget, this);
int index = stackedWidget->addWidget(centralMemoryWidget);

actionToolBar = QSharedPointer<ActionToolbar>::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);
Expand All @@ -26,13 +54,38 @@ AppMainwindow::AppMainwindow(QWidget *parent) : QMainWindow(parent)
qRegisterMetaType<RBKit::ObjectDetail>();
}

/*CpuViewPtr AppMainwindow::getCpuView()
void AppMainwindow::newCpuView()
{
return centralWidget->getCpuViewPtr();
}*/
QSharedPointer<CpuView> 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);
}
17 changes: 16 additions & 1 deletion rbkit-lib/ui/appmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
#define APPMAINWINDOW_H

#include <QMainWindow>
#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> actionToolBar;
QVBoxLayout *mainLayout;

QList<QSharedPointer<CpuView>> cpuViewList;

public:
explicit AppMainwindow(QWidget *parent = 0);
~AppMainwindow();
Expand All @@ -23,6 +35,9 @@ class AppMainwindow : public QMainWindow
signals:

public slots:
void tabChanged(int);
void newCpuView();
void closeCpuTab(int);
};

#endif // APPMAINWINDOW_H
Loading