2016-06-26 20:54:16 +03:00
|
|
|
/************************************************************************
|
|
|
|
* file name : main_window.cpp
|
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/06/26
|
|
|
|
* copyright : (c) 2016 Victor Zarubkin
|
|
|
|
* author : Victor Zarubkin
|
|
|
|
* email : v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
|
|
|
* description : The file contains implementation of MainWindow for easy_profiler GUI.
|
|
|
|
* ----------------- :
|
2016-06-27 22:11:26 +03:00
|
|
|
* change log : * 2016/06/26 Victor Zarubkin: Initial commit.
|
2016-06-30 02:57:57 +03:00
|
|
|
* :
|
2016-06-27 22:11:26 +03:00
|
|
|
* : * 2016/06/27 Victor Zarubkin: Passing blocks number to ProfTreeWidget::setTree().
|
2016-06-30 02:57:57 +03:00
|
|
|
* :
|
|
|
|
* : * 2016/06/29 Victor Zarubkin: Added menu with tests.
|
|
|
|
* :
|
2016-07-10 01:36:02 +03:00
|
|
|
* : * 2016/06/30 Sergey Yagovtsev: Open file by command line argument
|
|
|
|
* :
|
2016-06-26 20:54:16 +03:00
|
|
|
* : *
|
|
|
|
* ----------------- :
|
|
|
|
* license : TODO: add license text
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
#include <QDockWidget>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMenuBar>
|
2016-07-10 01:36:02 +03:00
|
|
|
#include <QCoreApplication>
|
2016-08-04 23:46:04 +03:00
|
|
|
#include <QCloseEvent>
|
2016-08-04 23:12:41 +03:00
|
|
|
#include <QSettings>
|
2016-06-26 20:54:16 +03:00
|
|
|
#include "main_window.h"
|
|
|
|
#include "blocks_tree_widget.h"
|
|
|
|
#include "blocks_graphics_view.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graphicsView(nullptr)
|
|
|
|
{
|
|
|
|
setObjectName("ProfilerGUI_MainWindow");
|
|
|
|
setWindowTitle("easy_profiler reader");
|
|
|
|
setDockNestingEnabled(true);
|
|
|
|
resize(800, 600);
|
|
|
|
|
|
|
|
setStatusBar(new QStatusBar());
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
auto graphicsView = new ProfGraphicsViewWidget(false);
|
2016-06-26 20:54:16 +03:00
|
|
|
m_graphicsView = new QDockWidget("Blocks diagram");
|
|
|
|
m_graphicsView->setMinimumHeight(50);
|
|
|
|
m_graphicsView->setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
m_graphicsView->setWidget(graphicsView);
|
|
|
|
|
|
|
|
auto treeWidget = new ProfTreeWidget();
|
|
|
|
m_treeWidget = new QDockWidget("Blocks hierarchy");
|
|
|
|
m_treeWidget->setMinimumHeight(50);
|
|
|
|
m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
m_treeWidget->setWidget(treeWidget);
|
|
|
|
|
|
|
|
addDockWidget(Qt::TopDockWidgetArea, m_graphicsView);
|
|
|
|
addDockWidget(Qt::BottomDockWidgetArea, m_treeWidget);
|
|
|
|
|
|
|
|
auto actionOpen = new QAction("Open", nullptr);
|
2016-06-30 02:57:57 +03:00
|
|
|
connect(actionOpen, &QAction::triggered, this, &This::onOpenFileClicked);
|
2016-06-26 20:54:16 +03:00
|
|
|
|
|
|
|
auto actionReload = new QAction("Reload", nullptr);
|
2016-06-30 02:57:57 +03:00
|
|
|
connect(actionReload, &QAction::triggered, this, &This::onReloadFileClicked);
|
2016-06-26 20:54:16 +03:00
|
|
|
|
|
|
|
auto actionExit = new QAction("Exit", nullptr);
|
2016-06-30 02:57:57 +03:00
|
|
|
connect(actionExit, &QAction::triggered, this, &This::onExitClicked);
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
auto actionTestView = new QAction("Test viewport", nullptr);
|
|
|
|
connect(actionTestView, &QAction::triggered, this, &This::onTestViewportClicked);
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
auto menu = new QMenu("File");
|
|
|
|
menu->addAction(actionOpen);
|
|
|
|
menu->addAction(actionReload);
|
|
|
|
menu->addSeparator();
|
|
|
|
menu->addAction(actionExit);
|
|
|
|
menuBar()->addMenu(menu);
|
|
|
|
|
|
|
|
menu = new QMenu("Tests");
|
|
|
|
menu->addAction(actionTestView);
|
|
|
|
menuBar()->addMenu(menu);
|
2016-07-10 01:36:02 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
connect(graphicsView->view(), &ProfGraphicsView::intervalChanged, treeWidget, &ProfTreeWidget::setTreeBlocks);
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-07 19:35:58 +03:00
|
|
|
loadSettings();
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-07-10 01:36:02 +03:00
|
|
|
if(QCoreApplication::arguments().size() > 1)
|
|
|
|
{
|
|
|
|
auto opened_filename = QCoreApplication::arguments().at(1).toStdString();
|
|
|
|
loadFile(opened_filename);
|
2016-06-30 21:39:04 +03:00
|
|
|
}
|
2016-07-10 01:36:02 +03:00
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
|
|
|
|
ProfMainWindow::~ProfMainWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ProfMainWindow::onOpenFileClicked(bool)
|
|
|
|
{
|
|
|
|
auto filename = QFileDialog::getOpenFileName(this, "Open profiler log", m_lastFile.c_str(), "Profiler Log File (*.prof);;All Files (*.*)");
|
2016-07-10 01:36:02 +03:00
|
|
|
loadFile(filename.toStdString());
|
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-07-10 01:36:02 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ProfMainWindow::loadFile(const std::string& stdfilename)
|
|
|
|
{
|
2016-08-03 23:00:04 +03:00
|
|
|
::profiler::thread_blocks_tree_t prof_blocks;
|
2016-06-26 20:54:16 +03:00
|
|
|
auto nblocks = fillTreesFromFile(stdfilename.c_str(), prof_blocks, true);
|
|
|
|
|
2016-06-27 23:22:12 +03:00
|
|
|
if (nblocks != 0)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->clearSilent(true);
|
|
|
|
|
2016-07-10 01:36:02 +03:00
|
|
|
m_lastFile = stdfilename;
|
2016-08-04 22:38:45 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.selected_thread = 0;
|
2016-08-03 23:00:04 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.profiler_blocks.swap(prof_blocks);
|
2016-08-04 22:38:45 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.gui_blocks.resize(nblocks);
|
|
|
|
memset(::profiler_gui::EASY_GLOBALS.gui_blocks.data(), 0, sizeof(::profiler_gui::ProfBlock) * nblocks);
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
static_cast<ProfGraphicsViewWidget*>(m_graphicsView->widget())->view()->setTree(::profiler_gui::EASY_GLOBALS.profiler_blocks);
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ProfMainWindow::onReloadFileClicked(bool)
|
|
|
|
{
|
|
|
|
if (m_lastFile.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
::profiler::thread_blocks_tree_t prof_blocks;
|
2016-06-26 20:54:16 +03:00
|
|
|
auto nblocks = fillTreesFromFile(m_lastFile.c_str(), prof_blocks, true);
|
|
|
|
|
2016-06-27 23:22:12 +03:00
|
|
|
if (nblocks != 0)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->clearSilent(true);
|
|
|
|
|
|
|
|
::profiler_gui::EASY_GLOBALS.selected_thread = 0;
|
2016-08-08 22:17:56 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.selected_block = -1;
|
2016-08-03 23:00:04 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.profiler_blocks.swap(prof_blocks);
|
2016-08-04 22:38:45 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.gui_blocks.resize(nblocks);
|
|
|
|
memset(::profiler_gui::EASY_GLOBALS.gui_blocks.data(), 0, sizeof(::profiler_gui::ProfBlock) * nblocks);
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
static_cast<ProfGraphicsViewWidget*>(m_graphicsView->widget())->view()->setTree(::profiler_gui::EASY_GLOBALS.profiler_blocks);
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ProfMainWindow::onExitClicked(bool)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
void ProfMainWindow::onTestViewportClicked(bool)
|
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->clearSilent(true);
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
auto view = static_cast<ProfGraphicsViewWidget*>(m_graphicsView->widget())->view();
|
2016-06-30 02:57:57 +03:00
|
|
|
view->clearSilent();
|
2016-08-04 22:38:45 +03:00
|
|
|
|
|
|
|
::profiler_gui::EASY_GLOBALS.gui_blocks.clear();
|
2016-08-03 23:00:04 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.profiler_blocks.clear();
|
2016-08-04 22:38:45 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.selected_thread = 0;
|
2016-08-08 22:17:56 +03:00
|
|
|
::profiler_gui::EASY_GLOBALS.selected_block = -1;
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
view->test(18000, 40000000, 2);
|
|
|
|
//view->test(3, 300, 1);
|
2016-06-30 02:57:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-04 23:46:04 +03:00
|
|
|
void ProfMainWindow::closeEvent(QCloseEvent* close_event)
|
2016-08-04 23:12:41 +03:00
|
|
|
{
|
2016-08-04 23:46:04 +03:00
|
|
|
saveSettings();
|
|
|
|
QMainWindow::closeEvent(close_event);
|
2016-08-04 23:12:41 +03:00
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-08-04 23:12:41 +03:00
|
|
|
|
2016-08-07 19:35:58 +03:00
|
|
|
void ProfMainWindow::loadSettings()
|
|
|
|
{
|
|
|
|
QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
|
|
|
|
settings.beginGroup("main");
|
|
|
|
|
|
|
|
auto geometry = settings.value("geometry").toByteArray();
|
|
|
|
if (!geometry.isEmpty())
|
|
|
|
{
|
|
|
|
restoreGeometry(geometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto last_file = settings.value("last_file");
|
|
|
|
if (!last_file.isNull())
|
|
|
|
{
|
|
|
|
m_lastFile = last_file.toString().toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:12:41 +03:00
|
|
|
void ProfMainWindow::saveSettings()
|
|
|
|
{
|
2016-08-07 19:35:58 +03:00
|
|
|
QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
|
2016-08-04 23:12:41 +03:00
|
|
|
settings.beginGroup("main");
|
|
|
|
|
|
|
|
settings.setValue("geometry", this->saveGeometry());
|
2016-08-06 14:48:38 +03:00
|
|
|
settings.setValue("last_file", m_lastFile.c_str());
|
2016-08-04 23:12:41 +03:00
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2016-08-07 19:35:58 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|