2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-25 09:25:17 +01:00
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
#include "qmlprofilertool.h"
|
2012-02-24 10:47:17 +01:00
|
|
|
#include "qmlprofilerstatemanager.h"
|
2015-07-01 18:11:54 +02:00
|
|
|
#include "qmlprofilerruncontrol.h"
|
2011-04-04 15:03:31 +02:00
|
|
|
#include "qmlprofilerconstants.h"
|
|
|
|
#include "qmlprofilerattachdialog.h"
|
2012-02-24 10:47:17 +01:00
|
|
|
#include "qmlprofilerviewmanager.h"
|
|
|
|
#include "qmlprofilerclientmanager.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2012-02-24 10:47:17 +01:00
|
|
|
#include "qmlprofilerdetailsrewriter.h"
|
2014-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofilernotesmodel.h"
|
2015-08-28 12:50:46 +02:00
|
|
|
#include "qmlprofilerrunconfigurationaspect.h"
|
|
|
|
#include "qmlprofilersettings.h"
|
2015-09-11 16:55:46 +02:00
|
|
|
#include "qmlprofilerplugin.h"
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2016-02-24 14:42:52 +01:00
|
|
|
#include <debugger/analyzer/analyzermanager.h>
|
|
|
|
#include <debugger/analyzer/analyzerruncontrol.h>
|
|
|
|
#include <debugger/analyzer/analyzerstartparameters.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-05-20 12:43:29 +02:00
|
|
|
#include <utils/fancymainwindow.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
#include <utils/fileinprojectfinder.h>
|
2011-04-14 17:19:28 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-01-29 18:00:30 +01:00
|
|
|
#include <projectexplorer/environmentaspect.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/project.h>
|
2011-04-01 13:48:10 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2011-10-28 16:32:34 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2013-04-17 11:10:45 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2016-01-25 15:00:20 +01:00
|
|
|
#include <projectexplorer/runnables.h>
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2011-12-27 22:41:31 +01:00
|
|
|
|
2011-04-04 15:03:31 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2015-11-23 16:41:54 +01:00
|
|
|
#include <coreplugin/coreicons.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2015-05-08 14:30:30 +02:00
|
|
|
#include <coreplugin/find/findplugin.h>
|
2011-04-04 15:03:31 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2011-07-27 11:49:39 +02:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2011-09-14 13:26:19 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2011-11-16 17:06:00 +01:00
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
#include <coreplugin/imode.h>
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
2014-07-23 01:19:42 +02:00
|
|
|
#include <QFileDialog>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
2015-01-30 16:52:11 +01:00
|
|
|
#include <QLineEdit>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMenu>
|
2014-07-23 01:19:42 +02:00
|
|
|
#include <QMessageBox>
|
2013-04-17 17:58:27 +02:00
|
|
|
#include <QTcpServer>
|
2014-07-23 01:19:42 +02:00
|
|
|
#include <QTime>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QToolButton>
|
2011-04-08 13:05:39 +02:00
|
|
|
|
2011-11-16 17:06:00 +01:00
|
|
|
using namespace Core;
|
|
|
|
using namespace Core::Constants;
|
2011-03-11 12:22:57 +01:00
|
|
|
using namespace Analyzer;
|
2011-11-16 17:06:00 +01:00
|
|
|
using namespace Analyzer::Constants;
|
2012-02-24 10:47:17 +01:00
|
|
|
using namespace QmlProfiler::Constants;
|
2012-04-18 12:06:10 +02:00
|
|
|
using namespace QmlDebug;
|
2011-09-14 13:12:25 +02:00
|
|
|
using namespace ProjectExplorer;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2014-09-09 18:22:58 +02:00
|
|
|
namespace QmlProfiler {
|
|
|
|
namespace Internal {
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
class QmlProfilerTool::QmlProfilerToolPrivate
|
|
|
|
{
|
|
|
|
public:
|
2016-03-03 10:47:02 +01:00
|
|
|
QmlProfilerStateManager *m_profilerState = 0;
|
|
|
|
QmlProfilerClientManager *m_profilerConnections = 0;
|
|
|
|
QmlProfilerModelManager *m_profilerModelManager = 0;
|
2012-02-24 10:47:17 +01:00
|
|
|
|
2016-03-03 10:47:02 +01:00
|
|
|
QmlProfilerViewManager *m_viewContainer = 0;
|
2011-04-01 13:48:10 +02:00
|
|
|
Utils::FileInProjectFinder m_projectFinder;
|
2016-03-03 10:47:02 +01:00
|
|
|
QToolButton *m_recordButton = 0;
|
|
|
|
QMenu *m_recordFeaturesMenu = 0;
|
2014-09-09 18:22:58 +02:00
|
|
|
|
2016-03-03 10:47:02 +01:00
|
|
|
QToolButton *m_clearButton = 0;
|
2012-02-24 10:47:17 +01:00
|
|
|
|
|
|
|
// elapsed time display
|
|
|
|
QTimer m_recordingTimer;
|
|
|
|
QTime m_recordingElapsedTime;
|
2016-03-03 10:47:02 +01:00
|
|
|
QLabel *m_timeLabel = 0;
|
2012-02-24 10:47:17 +01:00
|
|
|
|
2015-05-08 14:30:30 +02:00
|
|
|
// open search
|
2016-03-03 10:47:02 +01:00
|
|
|
QToolButton *m_searchButton = 0;
|
2015-01-30 16:52:11 +01:00
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
// hide and show categories
|
2016-03-03 10:47:02 +01:00
|
|
|
QToolButton *m_displayFeaturesButton = 0;
|
|
|
|
QMenu *m_displayFeaturesMenu = 0;
|
2015-06-30 15:55:33 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
// save and load actions
|
2016-03-03 10:47:02 +01:00
|
|
|
QAction *m_saveQmlTrace = 0;
|
|
|
|
QAction *m_loadQmlTrace = 0;
|
2011-03-11 12:22:57 +01:00
|
|
|
};
|
|
|
|
|
2011-06-30 18:55:48 +02:00
|
|
|
QmlProfilerTool::QmlProfilerTool(QObject *parent)
|
2015-02-18 14:35:20 +01:00
|
|
|
: QObject(parent), d(new QmlProfilerToolPrivate)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2012-11-26 21:18:13 +02:00
|
|
|
setObjectName(QLatin1String("QmlProfilerTool"));
|
2011-05-20 13:36:16 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
d->m_profilerState = new QmlProfilerStateManager(this);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
|
|
|
|
this, &QmlProfilerTool::profilerStateChanged);
|
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::clientRecordingChanged,
|
|
|
|
this, &QmlProfilerTool::clientRecordingChanged);
|
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
|
|
|
|
this, &QmlProfilerTool::serverRecordingChanged);
|
2015-06-30 15:55:33 +02:00
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::recordedFeaturesChanged,
|
|
|
|
this, &QmlProfilerTool::setRecordedFeatures);
|
2012-02-24 10:47:17 +01:00
|
|
|
|
|
|
|
d->m_profilerConnections = new QmlProfilerClientManager(this);
|
|
|
|
d->m_profilerConnections->registerProfilerStateManager(d->m_profilerState);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionClosed,
|
|
|
|
this, &QmlProfilerTool::clientsDisconnected);
|
2012-02-24 10:47:17 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_profilerModelManager = new QmlProfilerModelManager(&d->m_projectFinder, this);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_profilerModelManager, &QmlProfilerModelManager::stateChanged,
|
|
|
|
this, &QmlProfilerTool::profilerDataModelStateChanged);
|
|
|
|
connect(d->m_profilerModelManager, &QmlProfilerModelManager::error,
|
|
|
|
this, &QmlProfilerTool::showErrorDialog);
|
2015-06-30 15:55:33 +02:00
|
|
|
connect(d->m_profilerModelManager, &QmlProfilerModelManager::availableFeaturesChanged,
|
|
|
|
this, &QmlProfilerTool::setAvailableFeatures);
|
2015-02-10 20:29:54 +01:00
|
|
|
connect(d->m_profilerModelManager, &QmlProfilerModelManager::saveFinished,
|
2015-02-17 14:25:24 +01:00
|
|
|
this, &QmlProfilerTool::onLoadSaveFinished);
|
|
|
|
connect(d->m_profilerModelManager, &QmlProfilerModelManager::loadFinished,
|
|
|
|
this, &QmlProfilerTool::onLoadSaveFinished);
|
2011-11-16 17:06:00 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_profilerConnections->setModelManager(d->m_profilerModelManager);
|
2011-11-16 17:06:00 +01:00
|
|
|
Command *command = 0;
|
|
|
|
|
2014-07-23 01:19:42 +02:00
|
|
|
ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER);
|
|
|
|
ActionContainer *options = ActionManager::createMenu(M_DEBUG_ANALYZER_QML_OPTIONS);
|
2011-11-16 17:06:00 +01:00
|
|
|
options->menu()->setTitle(tr("QML Profiler Options"));
|
|
|
|
menu->addMenu(options, G_ANALYZER_OPTIONS);
|
|
|
|
options->menu()->setEnabled(true);
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
QAction *act = d->m_loadQmlTrace = new QAction(tr("Load QML Trace"), options);
|
2016-01-04 17:20:13 +01:00
|
|
|
command = ActionManager::registerAction(act, Constants::QmlProfilerLoadActionId);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(act, &QAction::triggered, this, &QmlProfilerTool::showLoadDialog);
|
2011-11-16 17:06:00 +01:00
|
|
|
options->addAction(command);
|
|
|
|
|
|
|
|
act = d->m_saveQmlTrace = new QAction(tr("Save QML Trace"), options);
|
|
|
|
d->m_saveQmlTrace->setEnabled(false);
|
2016-01-04 17:20:13 +01:00
|
|
|
command = ActionManager::registerAction(act, Constants::QmlProfilerSaveActionId);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(act, &QAction::triggered, this, &QmlProfilerTool::showSaveDialog);
|
2011-11-16 17:06:00 +01:00
|
|
|
options->addAction(command);
|
2012-02-24 10:47:17 +01:00
|
|
|
|
|
|
|
d->m_recordingTimer.setInterval(100);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(&d->m_recordingTimer, &QTimer::timeout, this, &QmlProfilerTool::updateTimeDisplay);
|
2011-04-08 13:05:39 +02:00
|
|
|
|
2011-09-27 14:38:22 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
d->m_viewContainer = new QmlProfilerViewManager(this,
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_profilerModelManager,
|
2012-02-24 10:47:17 +01:00
|
|
|
d->m_profilerState);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_viewContainer, &QmlProfilerViewManager::gotoSourceLocation,
|
|
|
|
this, &QmlProfilerTool::gotoSourceLocation);
|
2011-07-06 14:13:04 +02:00
|
|
|
|
2011-07-06 16:52:14 +02:00
|
|
|
//
|
|
|
|
// Toolbar
|
|
|
|
//
|
2011-03-24 12:42:15 +01:00
|
|
|
QWidget *toolbarWidget = new QWidget;
|
|
|
|
toolbarWidget->setObjectName(QLatin1String("QmlProfilerToolBarWidget"));
|
|
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout;
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
2011-04-06 12:26:19 +02:00
|
|
|
d->m_recordButton = new QToolButton(toolbarWidget);
|
|
|
|
d->m_recordButton->setCheckable(true);
|
|
|
|
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_recordButton,&QAbstractButton::clicked,
|
|
|
|
this, &QmlProfilerTool::recordingButtonChanged);
|
2011-04-06 12:26:19 +02:00
|
|
|
d->m_recordButton->setChecked(true);
|
2015-06-30 15:55:33 +02:00
|
|
|
d->m_recordFeaturesMenu = new QMenu(d->m_recordButton);
|
|
|
|
d->m_recordButton->setMenu(d->m_recordFeaturesMenu);
|
2014-09-09 18:22:58 +02:00
|
|
|
d->m_recordButton->setPopupMode(QToolButton::MenuButtonPopup);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_recordFeaturesMenu, &QMenu::triggered,
|
|
|
|
this, &QmlProfilerTool::toggleRequestedFeature);
|
2014-09-09 18:22:58 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
setRecording(d->m_profilerState->clientRecording());
|
2011-04-06 12:26:19 +02:00
|
|
|
layout->addWidget(d->m_recordButton);
|
|
|
|
|
2011-06-24 18:19:08 +02:00
|
|
|
d->m_clearButton = new QToolButton(toolbarWidget);
|
2015-11-23 16:41:54 +01:00
|
|
|
d->m_clearButton->setIcon(Icons::CLEAN_PANE.icon());
|
2011-07-05 16:40:26 +02:00
|
|
|
d->m_clearButton->setToolTip(tr("Discard data"));
|
2012-02-24 10:47:17 +01:00
|
|
|
|
2014-11-03 14:19:26 +01:00
|
|
|
connect(d->m_clearButton, &QAbstractButton::clicked, [this](){
|
|
|
|
if (checkForUnsavedNotes())
|
|
|
|
clearData();
|
|
|
|
});
|
2012-02-24 10:47:17 +01:00
|
|
|
|
2011-06-24 18:19:08 +02:00
|
|
|
layout->addWidget(d->m_clearButton);
|
|
|
|
|
2015-01-30 16:52:11 +01:00
|
|
|
d->m_searchButton = new QToolButton;
|
2015-11-23 16:41:54 +01:00
|
|
|
d->m_searchButton->setIcon(Icons::ZOOM.icon());
|
2015-05-08 14:30:30 +02:00
|
|
|
d->m_searchButton->setToolTip(tr("Search timeline event notes."));
|
2015-01-30 16:52:11 +01:00
|
|
|
layout->addWidget(d->m_searchButton);
|
|
|
|
|
2015-05-08 14:30:30 +02:00
|
|
|
connect(d->m_searchButton, &QToolButton::clicked, this, &QmlProfilerTool::showTimeLineSearch);
|
2015-01-30 16:52:11 +01:00
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
d->m_displayFeaturesButton = new QToolButton;
|
2015-11-23 16:41:54 +01:00
|
|
|
d->m_displayFeaturesButton->setIcon(Icons::FILTER.icon());
|
2015-06-30 15:55:33 +02:00
|
|
|
d->m_displayFeaturesButton->setToolTip(tr("Hide or show event categories."));
|
|
|
|
d->m_displayFeaturesButton->setPopupMode(QToolButton::InstantPopup);
|
2015-09-28 19:14:46 +02:00
|
|
|
d->m_displayFeaturesButton->setProperty("noArrow", true);
|
2015-06-30 15:55:33 +02:00
|
|
|
d->m_displayFeaturesMenu = new QMenu(d->m_displayFeaturesButton);
|
|
|
|
d->m_displayFeaturesButton->setMenu(d->m_displayFeaturesMenu);
|
|
|
|
connect(d->m_displayFeaturesMenu, &QMenu::triggered,
|
|
|
|
this, &QmlProfilerTool::toggleVisibleFeature);
|
|
|
|
layout->addWidget(d->m_displayFeaturesButton);
|
|
|
|
|
2015-06-30 18:05:03 +02:00
|
|
|
d->m_timeLabel = new QLabel();
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
d->m_timeLabel->setPalette(palette);
|
|
|
|
d->m_timeLabel->setIndent(10);
|
|
|
|
updateTimeDisplay();
|
|
|
|
layout->addWidget(d->m_timeLabel);
|
|
|
|
|
2015-01-30 16:52:11 +01:00
|
|
|
layout->addStretch();
|
2015-06-30 15:55:33 +02:00
|
|
|
|
2011-03-24 12:42:15 +01:00
|
|
|
toolbarWidget->setLayout(layout);
|
2015-06-30 15:55:33 +02:00
|
|
|
setAvailableFeatures(d->m_profilerModelManager->availableFeatures());
|
|
|
|
setRecordedFeatures(0);
|
2011-03-24 12:42:15 +01:00
|
|
|
|
2012-05-10 11:46:59 +02:00
|
|
|
// When the widgets are requested we assume that the session data
|
|
|
|
// is available, then we can populate the file finder
|
|
|
|
populateFileFinder();
|
|
|
|
|
2016-03-03 10:47:02 +01:00
|
|
|
auto runControlCreator = [this](RunConfiguration *runConfiguration, Core::Id) {
|
|
|
|
return createRunControl(runConfiguration);
|
|
|
|
};
|
|
|
|
|
|
|
|
QString description = tr("The QML Profiler can be used to find performance "
|
|
|
|
"bottlenecks in applications using QML.");
|
|
|
|
|
|
|
|
ActionDescription desc;
|
|
|
|
desc.setText(tr("QML Profiler"));
|
|
|
|
desc.setToolTip(description);
|
|
|
|
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId);
|
|
|
|
desc.setRunControlCreator(runControlCreator);
|
|
|
|
desc.setToolPreparer([this] { return prepareTool(); });
|
|
|
|
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
|
|
|
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
|
|
|
|
AnalyzerManager::registerAction(Constants::QmlProfilerLocalActionId, desc);
|
|
|
|
|
|
|
|
desc.setText(tr("QML Profiler (External)"));
|
|
|
|
desc.setToolTip(description);
|
|
|
|
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId);
|
|
|
|
desc.setRunControlCreator(runControlCreator);
|
|
|
|
desc.setCustomToolStarter([this](RunConfiguration *rc) { startRemoteTool(rc); });
|
|
|
|
desc.setToolPreparer([this] { return prepareTool(); });
|
|
|
|
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
|
|
|
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
|
|
|
|
AnalyzerManager::registerAction(Constants::QmlProfilerRemoteActionId, desc);
|
|
|
|
|
|
|
|
AnalyzerManager::registerToolbar(Constants::QmlProfilerPerspectiveId, toolbarWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerTool::~QmlProfilerTool()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString sysroot(RunConfiguration *runConfig)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(runConfig, return QString());
|
|
|
|
Kit *k = runConfig->target()->kit();
|
|
|
|
if (k && SysRootKitInformation::hasSysRoot(k))
|
|
|
|
return SysRootKitInformation::sysRoot(runConfig->target()->kit()).toString();
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
AnalyzerRunControl *QmlProfilerTool::createRunControl(RunConfiguration *runConfiguration)
|
|
|
|
{
|
|
|
|
QmlProfilerRunConfigurationAspect *aspect = static_cast<QmlProfilerRunConfigurationAspect *>(
|
|
|
|
runConfiguration->extraAspect(Constants::SETTINGS));
|
|
|
|
QTC_ASSERT(aspect, return 0);
|
|
|
|
|
|
|
|
QmlProfilerSettings *settings = static_cast<QmlProfilerSettings *>(aspect->currentSettings());
|
|
|
|
QTC_ASSERT(settings, return 0);
|
|
|
|
|
|
|
|
d->m_profilerConnections->setFlushInterval(settings->flushEnabled() ?
|
|
|
|
settings->flushInterval() : 0);
|
|
|
|
d->m_profilerConnections->setAggregateTraces(settings->aggregateTraces());
|
|
|
|
|
|
|
|
return new QmlProfilerRunControl(runConfiguration, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::finalizeRunControl(QmlProfilerRunControl *runControl)
|
|
|
|
{
|
|
|
|
runControl->registerProfilerStateManager(d->m_profilerState);
|
|
|
|
|
|
|
|
// FIXME: Check that there's something sensible in sp.connParams
|
|
|
|
auto connection = runControl->connection().as<AnalyzerConnection>();
|
|
|
|
if (!connection.analyzerSocket.isEmpty())
|
|
|
|
d->m_profilerConnections->setLocalSocket(connection.analyzerSocket);
|
|
|
|
else
|
|
|
|
d->m_profilerConnections->setTcpConnection(connection.analyzerHost, connection.analyzerPort);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize m_projectFinder
|
|
|
|
//
|
|
|
|
|
|
|
|
RunConfiguration *runConfiguration = runControl->runConfiguration();
|
|
|
|
QString projectDirectory;
|
|
|
|
if (runConfiguration) {
|
|
|
|
Project *project = runConfiguration->target()->project();
|
|
|
|
projectDirectory = project->projectDirectory().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
populateFileFinder(projectDirectory, sysroot(runConfiguration));
|
|
|
|
|
|
|
|
if (connection.analyzerSocket.isEmpty())
|
|
|
|
connect(runControl, &QmlProfilerRunControl::processRunning,
|
|
|
|
d->m_profilerConnections, &QmlProfilerClientManager::connectTcpClient);
|
|
|
|
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed,
|
|
|
|
runControl, &QmlProfilerRunControl::cancelProcess);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
2012-05-10 11:46:59 +02:00
|
|
|
void QmlProfilerTool::populateFileFinder(QString projectDirectory, QString activeSysroot)
|
|
|
|
{
|
|
|
|
// Initialize filefinder with some sensible default
|
|
|
|
QStringList sourceFiles;
|
2013-09-05 11:46:07 +02:00
|
|
|
QList<Project *> projects = SessionManager::projects();
|
|
|
|
if (Project *startupProject = SessionManager::startupProject()) {
|
2012-05-10 11:46:59 +02:00
|
|
|
// startup project first
|
2013-09-05 11:46:07 +02:00
|
|
|
projects.removeOne(startupProject);
|
2012-05-10 11:46:59 +02:00
|
|
|
projects.insert(0, startupProject);
|
|
|
|
}
|
|
|
|
foreach (Project *project, projects)
|
2016-01-08 16:56:35 +01:00
|
|
|
sourceFiles << project->files(Project::SourceFiles);
|
2012-05-10 11:46:59 +02:00
|
|
|
|
|
|
|
if (!projects.isEmpty()) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (projectDirectory.isEmpty())
|
2014-05-02 12:53:36 +02:00
|
|
|
projectDirectory = projects.first()->projectDirectory().toString();
|
2012-05-10 11:46:59 +02:00
|
|
|
|
|
|
|
if (activeSysroot.isEmpty()) {
|
|
|
|
if (Target *target = projects.first()->activeTarget())
|
|
|
|
if (RunConfiguration *rc = target->activeRunConfiguration())
|
|
|
|
activeSysroot = sysroot(rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->m_projectFinder.setProjectDirectory(projectDirectory);
|
|
|
|
d->m_projectFinder.setProjectFiles(sourceFiles);
|
|
|
|
d->m_projectFinder.setSysroot(activeSysroot);
|
|
|
|
}
|
|
|
|
|
2012-02-13 15:26:57 +01:00
|
|
|
void QmlProfilerTool::recordingButtonChanged(bool recording)
|
2011-04-06 12:26:19 +02:00
|
|
|
{
|
2014-11-17 17:32:52 +01:00
|
|
|
// clientRecording is our intention for new sessions. That may differ from the state of the
|
|
|
|
// current session, as indicated by the button. To synchronize it, toggle once.
|
|
|
|
|
2014-11-03 14:19:26 +01:00
|
|
|
if (recording && d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
|
|
|
|
if (checkForUnsavedNotes()) {
|
2015-11-18 12:34:52 +01:00
|
|
|
if (!d->m_profilerConnections->aggregateTraces() ||
|
|
|
|
d->m_profilerModelManager->state() == QmlProfilerModelManager::Done)
|
|
|
|
clearData(); // clear before the recording starts, unless we aggregate recordings
|
2014-11-17 17:32:52 +01:00
|
|
|
if (d->m_profilerState->clientRecording())
|
|
|
|
d->m_profilerState->setClientRecording(false);
|
2014-11-03 14:19:26 +01:00
|
|
|
d->m_profilerState->setClientRecording(true);
|
|
|
|
} else {
|
|
|
|
d->m_recordButton->setChecked(false);
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-17 17:32:52 +01:00
|
|
|
if (d->m_profilerState->clientRecording() == recording)
|
|
|
|
d->m_profilerState->setClientRecording(!recording);
|
2014-11-03 14:19:26 +01:00
|
|
|
d->m_profilerState->setClientRecording(recording);
|
|
|
|
}
|
2012-02-13 15:26:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::setRecording(bool recording)
|
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
// update display
|
2012-02-13 15:26:57 +01:00
|
|
|
d->m_recordButton->setToolTip( recording ? tr("Disable profiling") : tr("Enable profiling"));
|
|
|
|
d->m_recordButton->setIcon(QIcon(recording ? QLatin1String(":/qmlprofiler/recordOn.png") :
|
|
|
|
QLatin1String(":/qmlprofiler/recordOff.png")));
|
|
|
|
|
|
|
|
d->m_recordButton->setChecked(recording);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
// manage timer
|
|
|
|
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
|
|
|
|
if (recording) {
|
|
|
|
d->m_recordingTimer.start();
|
|
|
|
d->m_recordingElapsedTime.start();
|
|
|
|
} else {
|
|
|
|
d->m_recordingTimer.stop();
|
|
|
|
}
|
|
|
|
}
|
2011-08-25 16:30:36 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 16:36:40 +01:00
|
|
|
void QmlProfilerTool::gotoSourceLocation(const QString &fileUrl, int lineNumber, int columnNumber)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-01 13:57:49 +02:00
|
|
|
if (lineNumber < 0 || fileUrl.isEmpty())
|
2011-03-11 12:22:57 +01:00
|
|
|
return;
|
|
|
|
|
2014-02-21 12:15:31 +01:00
|
|
|
const QString projectFileName = d->m_projectFinder.findFile(fileUrl);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-11-09 11:01:03 +01:00
|
|
|
QFileInfo fileInfo(projectFileName);
|
|
|
|
if (!fileInfo.exists() || !fileInfo.isReadable())
|
|
|
|
return;
|
|
|
|
|
2014-11-17 19:12:44 +01:00
|
|
|
// The text editors count columns starting with 0, but the ASTs store the
|
|
|
|
// location starting with 1, therefore the -1.
|
|
|
|
EditorManager::openEditorAt(projectFileName, lineNumber, columnNumber - 1, Id(),
|
|
|
|
EditorManager::DoNotSwitchToDesignMode);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
2011-03-24 12:42:15 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void QmlProfilerTool::updateTimeDisplay()
|
2011-11-28 16:30:30 +01:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
double seconds = 0;
|
2015-10-20 13:04:44 +02:00
|
|
|
switch (d->m_profilerState->currentState()) {
|
|
|
|
case QmlProfilerStateManager::AppStopRequested:
|
|
|
|
case QmlProfilerStateManager::AppDying:
|
|
|
|
return; // Transitional state: don't update the display.
|
|
|
|
case QmlProfilerStateManager::AppRunning:
|
|
|
|
if (d->m_profilerState->serverRecording()) {
|
2012-02-24 10:47:17 +01:00
|
|
|
seconds = d->m_recordingElapsedTime.elapsed() / 1000.0;
|
2015-10-20 13:04:44 +02:00
|
|
|
break;
|
|
|
|
} // else fall through
|
|
|
|
case QmlProfilerStateManager::Idle:
|
|
|
|
if (d->m_profilerModelManager->state() != QmlProfilerModelManager::Empty &&
|
|
|
|
d->m_profilerModelManager->state() != QmlProfilerModelManager::ClearingData)
|
|
|
|
seconds = d->m_profilerModelManager->traceTime()->duration() / 1.0e9;
|
|
|
|
break;
|
2012-02-24 10:47:17 +01:00
|
|
|
}
|
2011-11-28 16:30:30 +01:00
|
|
|
QString timeString = QString::number(seconds,'f',1);
|
2012-02-24 10:47:17 +01:00
|
|
|
QString profilerTimeStr = QmlProfilerTool::tr("%1 s").arg(timeString, 6);
|
|
|
|
d->m_timeLabel->setText(tr("Elapsed: %1").arg(profilerTimeStr));
|
2011-11-28 16:30:30 +01:00
|
|
|
}
|
|
|
|
|
2015-05-08 14:30:30 +02:00
|
|
|
void QmlProfilerTool::showTimeLineSearch()
|
2015-01-30 16:52:11 +01:00
|
|
|
{
|
2015-05-08 14:30:30 +02:00
|
|
|
d->m_viewContainer->raiseTimeline();
|
|
|
|
Core::FindPlugin::instance()->openFindToolBar(Core::FindPlugin::FindForwardDirection);
|
2015-01-30 16:52:11 +01:00
|
|
|
}
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void QmlProfilerTool::clearData()
|
2011-11-28 16:30:30 +01:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_profilerModelManager->clear();
|
2012-03-26 16:20:09 +02:00
|
|
|
d->m_profilerConnections->discardPendingData();
|
2015-06-30 15:55:33 +02:00
|
|
|
setRecordedFeatures(0);
|
2011-03-24 12:42:15 +01:00
|
|
|
}
|
2011-04-01 13:48:10 +02:00
|
|
|
|
2011-04-06 16:04:18 +02:00
|
|
|
void QmlProfilerTool::clearDisplay()
|
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
d->m_profilerConnections->clearBufferedData();
|
|
|
|
d->m_viewContainer->clear();
|
|
|
|
updateTimeDisplay();
|
2011-04-06 16:04:18 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 12:48:26 +02:00
|
|
|
void QmlProfilerTool::setButtonsEnabled(bool enable)
|
|
|
|
{
|
|
|
|
d->m_clearButton->setEnabled(enable);
|
|
|
|
d->m_displayFeaturesButton->setEnabled(enable);
|
|
|
|
d->m_searchButton->setEnabled(enable);
|
|
|
|
d->m_recordFeaturesMenu->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2015-06-18 16:26:58 +02:00
|
|
|
bool QmlProfilerTool::prepareTool()
|
2011-04-04 15:03:31 +02:00
|
|
|
{
|
2015-02-18 18:51:29 +01:00
|
|
|
if (d->m_recordButton->isChecked()) {
|
2015-06-18 16:26:58 +02:00
|
|
|
if (checkForUnsavedNotes()) {
|
|
|
|
clearData(); // clear right away to suppress second warning on server recording change
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-18 18:51:29 +01:00
|
|
|
}
|
2015-06-18 16:26:58 +02:00
|
|
|
return true;
|
2015-02-18 18:51:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 17:08:50 +01:00
|
|
|
void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc)
|
2015-02-18 18:51:29 +01:00
|
|
|
{
|
|
|
|
AnalyzerManager::showMode();
|
|
|
|
|
2013-04-26 10:23:14 +02:00
|
|
|
Id kitId;
|
2011-10-15 11:52:03 +02:00
|
|
|
quint16 port;
|
2013-04-26 10:23:14 +02:00
|
|
|
Kit *kit = 0;
|
2011-10-15 11:52:03 +02:00
|
|
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2011-10-15 11:52:03 +02:00
|
|
|
|
2013-04-26 10:23:14 +02:00
|
|
|
kitId = Id::fromSetting(settings->value(QLatin1String("AnalyzerQmlAttachDialog/kitId")));
|
|
|
|
port = settings->value(QLatin1String("AnalyzerQmlAttachDialog/port"), 3768).toUInt();
|
2011-10-15 11:52:03 +02:00
|
|
|
|
|
|
|
QmlProfilerAttachDialog dialog;
|
|
|
|
|
2013-04-26 10:23:14 +02:00
|
|
|
dialog.setKitId(kitId);
|
2011-10-15 11:52:03 +02:00
|
|
|
dialog.setPort(port);
|
|
|
|
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
|
|
|
|
2013-04-26 10:23:14 +02:00
|
|
|
kit = dialog.kit();
|
2011-10-15 11:52:03 +02:00
|
|
|
port = dialog.port();
|
|
|
|
|
2013-04-26 10:23:14 +02:00
|
|
|
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/kitId"), kit->id().toSetting());
|
2011-10-15 11:52:03 +02:00
|
|
|
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/port"), port);
|
|
|
|
}
|
2011-04-04 15:03:31 +02:00
|
|
|
|
2016-01-19 17:25:18 +01:00
|
|
|
AnalyzerConnection connection;
|
2013-04-26 10:23:14 +02:00
|
|
|
|
|
|
|
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
|
|
|
|
if (device) {
|
2016-01-19 17:25:18 +01:00
|
|
|
connection.connParams = device->sshParameters();
|
|
|
|
connection.analyzerHost = device->qmlProfilerHost();
|
2013-04-26 10:23:14 +02:00
|
|
|
}
|
2016-01-19 17:25:18 +01:00
|
|
|
connection.analyzerPort = port;
|
|
|
|
|
2016-01-22 17:08:50 +01:00
|
|
|
auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc));
|
2016-01-19 17:25:18 +01:00
|
|
|
runControl->setConnection(connection);
|
2011-04-04 15:03:31 +02:00
|
|
|
|
2016-01-19 17:25:18 +01:00
|
|
|
ProjectExplorerPlugin::startRunControl(runControl, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
2011-04-04 15:03:31 +02:00
|
|
|
}
|
2011-04-04 15:56:34 +02:00
|
|
|
|
2014-05-06 15:44:34 +02:00
|
|
|
void QmlProfilerTool::logState(const QString &msg)
|
2011-07-27 11:49:39 +02:00
|
|
|
{
|
2014-07-23 01:19:42 +02:00
|
|
|
MessageManager::write(msg, MessageManager::Flash);
|
2011-07-27 11:49:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::logError(const QString &msg)
|
|
|
|
{
|
2013-09-05 01:52:17 +02:00
|
|
|
MessageManager::write(msg);
|
2011-07-27 11:49:39 +02:00
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void QmlProfilerTool::showErrorDialog(const QString &error)
|
|
|
|
{
|
2014-07-23 01:19:42 +02:00
|
|
|
QMessageBox *errorDialog = new QMessageBox(ICore::mainWindow());
|
2012-02-24 10:47:17 +01:00
|
|
|
errorDialog->setIcon(QMessageBox::Warning);
|
|
|
|
errorDialog->setWindowTitle(tr("QML Profiler"));
|
|
|
|
errorDialog->setText(error);
|
|
|
|
errorDialog->setStandardButtons(QMessageBox::Ok);
|
|
|
|
errorDialog->setDefaultButton(QMessageBox::Ok);
|
|
|
|
errorDialog->setModal(false);
|
|
|
|
errorDialog->show();
|
|
|
|
}
|
|
|
|
|
2014-11-03 14:34:34 +01:00
|
|
|
void QmlProfilerTool::showLoadOption()
|
|
|
|
{
|
|
|
|
d->m_loadQmlTrace->setEnabled(!d->m_profilerState->serverRecording());
|
|
|
|
}
|
|
|
|
|
2011-11-16 17:06:00 +01:00
|
|
|
void QmlProfilerTool::showSaveOption()
|
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_saveQmlTrace->setEnabled(!d->m_profilerModelManager->isEmpty());
|
2011-11-16 17:06:00 +01:00
|
|
|
}
|
|
|
|
|
2015-09-11 16:55:46 +02:00
|
|
|
void saveLastTraceFile(const QString &filename)
|
|
|
|
{
|
|
|
|
QmlProfilerSettings *settings = QmlProfilerPlugin::globalSettings();
|
|
|
|
if (filename != settings->lastTraceFile()) {
|
|
|
|
settings->setLastTraceFile(filename);
|
|
|
|
settings->writeGlobalSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:14 +02:00
|
|
|
void QmlProfilerTool::showSaveDialog()
|
|
|
|
{
|
2015-09-11 16:55:46 +02:00
|
|
|
QString filename = QFileDialog::getSaveFileName(
|
|
|
|
ICore::mainWindow(), tr("Save QML Trace"),
|
|
|
|
QmlProfilerPlugin::globalSettings()->lastTraceFile(),
|
|
|
|
tr("QML traces (*%1)").arg(QLatin1String(TraceFileExtension)));
|
2011-07-26 13:56:14 +02:00
|
|
|
if (!filename.isEmpty()) {
|
2011-08-22 16:01:50 +02:00
|
|
|
if (!filename.endsWith(QLatin1String(TraceFileExtension)))
|
|
|
|
filename += QLatin1String(TraceFileExtension);
|
2015-09-11 16:55:46 +02:00
|
|
|
saveLastTraceFile(filename);
|
2016-02-26 14:14:49 +01:00
|
|
|
AnalyzerManager::enableMainWindow(false);
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_profilerModelManager->save(filename);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::showLoadDialog()
|
|
|
|
{
|
2014-11-03 14:19:26 +01:00
|
|
|
if (!checkForUnsavedNotes())
|
|
|
|
return;
|
|
|
|
|
2012-05-07 18:28:03 +02:00
|
|
|
if (ModeManager::currentMode()->id() != MODE_ANALYZE)
|
2011-11-16 17:06:00 +01:00
|
|
|
AnalyzerManager::showMode();
|
|
|
|
|
2015-06-22 18:08:44 +02:00
|
|
|
AnalyzerManager::selectAction(QmlProfilerRemoteActionId);
|
2011-11-16 17:06:00 +01:00
|
|
|
|
2015-09-11 16:55:46 +02:00
|
|
|
QString filename = QFileDialog::getOpenFileName(
|
|
|
|
ICore::mainWindow(), tr("Load QML Trace"),
|
|
|
|
QmlProfilerPlugin::globalSettings()->lastTraceFile(),
|
|
|
|
tr("QML traces (*%1)").arg(QLatin1String(TraceFileExtension)));
|
2011-07-26 13:56:14 +02:00
|
|
|
|
|
|
|
if (!filename.isEmpty()) {
|
2015-09-11 16:55:46 +02:00
|
|
|
saveLastTraceFile(filename);
|
2016-02-26 14:14:49 +01:00
|
|
|
AnalyzerManager::enableMainWindow(false);
|
2015-06-30 15:55:33 +02:00
|
|
|
connect(d->m_profilerModelManager, &QmlProfilerModelManager::recordedFeaturesChanged,
|
|
|
|
this, &QmlProfilerTool::setRecordedFeatures);
|
2015-02-17 14:25:24 +01:00
|
|
|
d->m_profilerModelManager->load(filename);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-18 16:10:33 +02:00
|
|
|
|
2015-02-17 14:25:24 +01:00
|
|
|
void QmlProfilerTool::onLoadSaveFinished()
|
|
|
|
{
|
2015-06-30 15:55:33 +02:00
|
|
|
disconnect(d->m_profilerModelManager, &QmlProfilerModelManager::recordedFeaturesChanged,
|
|
|
|
this, &QmlProfilerTool::setRecordedFeatures);
|
2016-02-26 14:14:49 +01:00
|
|
|
AnalyzerManager::enableMainWindow(true);
|
2015-02-17 14:25:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-03 14:19:26 +01:00
|
|
|
/*!
|
|
|
|
Checks if we have unsaved notes. If so, shows a warning dialog. Returns true if we can continue
|
|
|
|
with a potentially destructive operation and discard the warnings, or false if not. We don't
|
|
|
|
want to show a save/discard dialog here because that will often result in a confusing series of
|
|
|
|
different dialogs: first "save" and then immediately "load" or "connect".
|
|
|
|
*/
|
|
|
|
bool QmlProfilerTool::checkForUnsavedNotes()
|
|
|
|
{
|
|
|
|
if (!d->m_profilerModelManager->notesModel()->isModified())
|
|
|
|
return true;
|
|
|
|
return QMessageBox::warning(QApplication::activeWindow(), tr("QML Profiler"),
|
|
|
|
tr("You are about to discard the profiling data, including unsaved "
|
|
|
|
"notes. Do you want to continue?"),
|
|
|
|
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes;
|
|
|
|
}
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
void QmlProfilerTool::restoreFeatureVisibility()
|
|
|
|
{
|
|
|
|
// Restore the shown/hidden state of features to what the user selected. When clearing data the
|
|
|
|
// the model manager sets its features to 0, and models get automatically shown, for the mockup.
|
|
|
|
quint64 features = 0;
|
|
|
|
foreach (const QAction *action, d->m_displayFeaturesMenu->actions()) {
|
|
|
|
if (action->isChecked())
|
|
|
|
features |= (1ULL << action->data().toUInt());
|
|
|
|
}
|
|
|
|
d->m_profilerModelManager->setVisibleFeatures(features);
|
|
|
|
}
|
|
|
|
|
2012-05-08 15:14:11 +02:00
|
|
|
void QmlProfilerTool::clientsDisconnected()
|
|
|
|
{
|
2016-01-22 17:43:09 +01:00
|
|
|
if (d->m_profilerModelManager->state() == QmlProfilerModelManager::AcquiringData) {
|
|
|
|
if (d->m_profilerConnections->aggregateTraces()) {
|
|
|
|
d->m_profilerModelManager->acquiringDone();
|
|
|
|
} else {
|
|
|
|
// If the application stopped by itself, check if we have all the data
|
|
|
|
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppDying ||
|
|
|
|
d->m_profilerState->currentState() == QmlProfilerStateManager::Idle) {
|
2015-11-18 12:34:52 +01:00
|
|
|
showNonmodalWarning(tr("Application finished before loading profiled data.\n"
|
|
|
|
"Please use the stop button instead."));
|
|
|
|
d->m_profilerModelManager->clear();
|
|
|
|
}
|
2015-09-11 16:10:58 +02:00
|
|
|
}
|
2012-05-08 15:14:11 +02:00
|
|
|
}
|
2016-01-22 17:43:09 +01:00
|
|
|
|
|
|
|
// ... and return to the "base" state
|
|
|
|
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppDying)
|
|
|
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::Idle);
|
2012-05-08 15:14:11 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
void addFeatureToMenu(QMenu *menu, ProfileFeature feature, quint64 enabledFeatures)
|
|
|
|
{
|
|
|
|
QAction *action =
|
|
|
|
menu->addAction(QmlProfilerTool::tr(QmlProfilerModelManager::featureName(feature)));
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setData(static_cast<uint>(feature));
|
|
|
|
action->setChecked(enabledFeatures & (1ULL << (feature)));
|
|
|
|
}
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
template<ProfileFeature feature>
|
2015-06-30 15:55:33 +02:00
|
|
|
void QmlProfilerTool::updateFeatures(quint64 features)
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
2014-09-24 07:59:13 +03:00
|
|
|
if (features & (1ULL << (feature))) {
|
2015-06-30 15:55:33 +02:00
|
|
|
addFeatureToMenu(d->m_recordFeaturesMenu, feature,
|
|
|
|
d->m_profilerState->requestedFeatures());
|
|
|
|
addFeatureToMenu(d->m_displayFeaturesMenu, feature,
|
|
|
|
d->m_profilerModelManager->visibleFeatures());
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
2015-06-30 15:55:33 +02:00
|
|
|
updateFeatures<static_cast<ProfileFeature>(feature + 1)>(features);
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2015-06-30 15:55:33 +02:00
|
|
|
void QmlProfilerTool::updateFeatures<MaximumProfileFeature>(quint64 features)
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(features);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::setAvailableFeatures(quint64 features)
|
|
|
|
{
|
2015-06-30 15:55:33 +02:00
|
|
|
if (features != d->m_profilerState->requestedFeatures())
|
|
|
|
d->m_profilerState->setRequestedFeatures(features); // by default, enable them all.
|
|
|
|
if (d->m_recordFeaturesMenu && d->m_displayFeaturesMenu) {
|
|
|
|
d->m_recordFeaturesMenu->clear();
|
|
|
|
d->m_displayFeaturesMenu->clear();
|
|
|
|
updateFeatures<static_cast<ProfileFeature>(0)>(features);
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
void QmlProfilerTool::setRecordedFeatures(quint64 features)
|
|
|
|
{
|
|
|
|
foreach (QAction *action, d->m_displayFeaturesMenu->actions())
|
|
|
|
action->setEnabled(features & (1ULL << action->data().toUInt()));
|
|
|
|
}
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void QmlProfilerTool::profilerDataModelStateChanged()
|
2011-08-18 16:10:33 +02:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
switch (d->m_profilerModelManager->state()) {
|
2015-09-10 13:51:54 +02:00
|
|
|
case QmlProfilerModelManager::Empty :
|
2015-10-20 12:48:26 +02:00
|
|
|
d->m_recordButton->setEnabled(true);
|
|
|
|
setButtonsEnabled(true);
|
2013-12-09 12:11:48 +01:00
|
|
|
break;
|
2015-09-10 13:51:54 +02:00
|
|
|
case QmlProfilerModelManager::ClearingData :
|
2015-10-20 12:48:26 +02:00
|
|
|
d->m_recordButton->setEnabled(false);
|
|
|
|
setButtonsEnabled(false);
|
2012-02-24 10:47:17 +01:00
|
|
|
clearDisplay();
|
|
|
|
break;
|
2015-09-10 13:51:54 +02:00
|
|
|
case QmlProfilerModelManager::AcquiringData :
|
2015-10-20 12:48:26 +02:00
|
|
|
d->m_recordButton->setEnabled(true); // Press recording button to stop recording
|
|
|
|
setButtonsEnabled(false); // Other buttons disabled
|
|
|
|
break;
|
2015-09-10 13:51:54 +02:00
|
|
|
case QmlProfilerModelManager::ProcessingData :
|
2015-10-20 12:48:26 +02:00
|
|
|
d->m_recordButton->setEnabled(false);
|
|
|
|
setButtonsEnabled(false);
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
2015-09-10 13:51:54 +02:00
|
|
|
case QmlProfilerModelManager::Done :
|
2012-02-24 10:47:17 +01:00
|
|
|
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppStopRequested)
|
2015-09-11 16:10:58 +02:00
|
|
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::Idle);
|
2012-02-24 10:47:17 +01:00
|
|
|
showSaveOption();
|
|
|
|
updateTimeDisplay();
|
2015-06-30 15:55:33 +02:00
|
|
|
restoreFeatureVisibility();
|
2015-10-20 12:48:26 +02:00
|
|
|
d->m_recordButton->setEnabled(true);
|
|
|
|
setButtonsEnabled(true);
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 17:20:13 +01:00
|
|
|
QList <QAction *> QmlProfilerTool::profilerContextMenuActions()
|
2012-02-24 10:47:17 +01:00
|
|
|
{
|
|
|
|
QList <QAction *> commonActions;
|
2016-01-04 17:20:13 +01:00
|
|
|
ActionManager *manager = ActionManager::instance();
|
|
|
|
if (manager) {
|
|
|
|
Command *command = manager->command(Constants::QmlProfilerLoadActionId);
|
|
|
|
if (command)
|
|
|
|
commonActions << command->action();
|
|
|
|
command = manager->command(Constants::QmlProfilerSaveActionId);
|
|
|
|
if (command)
|
|
|
|
commonActions << command->action();
|
|
|
|
}
|
2012-02-24 10:47:17 +01:00
|
|
|
return commonActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::showNonmodalWarning(const QString &warningMsg)
|
|
|
|
{
|
2014-07-23 01:19:42 +02:00
|
|
|
QMessageBox *noExecWarning = new QMessageBox(ICore::mainWindow());
|
2012-02-24 10:47:17 +01:00
|
|
|
noExecWarning->setIcon(QMessageBox::Warning);
|
|
|
|
noExecWarning->setWindowTitle(tr("QML Profiler"));
|
|
|
|
noExecWarning->setText(warningMsg);
|
|
|
|
noExecWarning->setStandardButtons(QMessageBox::Ok);
|
|
|
|
noExecWarning->setDefaultButton(QMessageBox::Ok);
|
|
|
|
noExecWarning->setModal(false);
|
|
|
|
noExecWarning->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
QMessageBox *QmlProfilerTool::requestMessageBox()
|
|
|
|
{
|
2014-07-23 01:19:42 +02:00
|
|
|
return new QMessageBox(ICore::mainWindow());
|
2012-02-24 10:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::handleHelpRequest(const QString &link)
|
|
|
|
{
|
2013-08-29 19:00:34 +02:00
|
|
|
HelpManager::handleHelpRequest(link);
|
2011-08-18 16:10:33 +02:00
|
|
|
}
|
2011-09-14 13:26:19 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void QmlProfilerTool::profilerStateChanged()
|
2011-09-14 13:26:19 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
switch (d->m_profilerState->currentState()) {
|
2012-05-11 17:19:15 +02:00
|
|
|
case QmlProfilerStateManager::AppDying : {
|
|
|
|
// If already disconnected when dying, check again that all data was read
|
|
|
|
if (!d->m_profilerConnections->isConnected())
|
2015-10-30 12:35:17 +01:00
|
|
|
QTimer::singleShot(0, this, &QmlProfilerTool::clientsDisconnected);
|
2012-05-11 17:19:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-02-24 10:47:17 +01:00
|
|
|
case QmlProfilerStateManager::Idle :
|
|
|
|
// when the app finishes, set recording display to client status
|
|
|
|
setRecording(d->m_profilerState->clientRecording());
|
|
|
|
break;
|
2015-10-20 12:48:26 +02:00
|
|
|
case QmlProfilerStateManager::AppStopRequested:
|
|
|
|
// Don't allow toggling the recording while data is loaded when application quits
|
|
|
|
if (d->m_profilerState->serverRecording())
|
|
|
|
d->m_recordButton->setEnabled(false);
|
|
|
|
break;
|
2012-02-24 10:47:17 +01:00
|
|
|
default:
|
|
|
|
// no special action needed for other states
|
2011-09-14 13:26:19 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-02-24 10:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTool::clientRecordingChanged()
|
|
|
|
{
|
|
|
|
// if application is running, display server record changes
|
|
|
|
// if application is stopped, display client record changes
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (d->m_profilerState->currentState() != QmlProfilerStateManager::AppRunning)
|
2012-02-24 10:47:17 +01:00
|
|
|
setRecording(d->m_profilerState->clientRecording());
|
2011-09-14 13:26:19 +02:00
|
|
|
}
|
2012-02-13 15:26:57 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void QmlProfilerTool::serverRecordingChanged()
|
2012-02-13 15:26:57 +01:00
|
|
|
{
|
2014-11-03 14:34:34 +01:00
|
|
|
showLoadOption();
|
2012-02-24 10:47:17 +01:00
|
|
|
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
|
|
|
|
// clear the old data each time we start a new profiling session
|
|
|
|
if (d->m_profilerState->serverRecording()) {
|
2014-11-03 14:19:26 +01:00
|
|
|
// We cannot stop it here, so we cannot give the usual yes/no dialog. Show a dialog
|
|
|
|
// offering to immediately save the data instead.
|
|
|
|
if (d->m_profilerModelManager->notesModel()->isModified() &&
|
|
|
|
QMessageBox::warning(QApplication::activeWindow(), tr("QML Profiler"),
|
|
|
|
tr("Starting a new profiling session will discard the "
|
|
|
|
"previous data, including unsaved notes.\nDo you want "
|
|
|
|
"to save the data first?"),
|
|
|
|
QMessageBox::Save, QMessageBox::Discard) ==
|
|
|
|
QMessageBox::Save)
|
|
|
|
showSaveDialog();
|
|
|
|
|
|
|
|
setRecording(true);
|
2015-11-18 12:34:52 +01:00
|
|
|
if (!d->m_profilerConnections->aggregateTraces() ||
|
|
|
|
d->m_profilerModelManager->state() == QmlProfilerModelManager::Done)
|
|
|
|
clearData();
|
2013-08-08 13:28:08 +02:00
|
|
|
d->m_profilerModelManager->prepareForWriting();
|
|
|
|
} else {
|
2014-11-03 14:19:26 +01:00
|
|
|
setRecording(false);
|
2015-10-20 12:48:26 +02:00
|
|
|
|
|
|
|
// changes back once loading is finished, see profilerDataModelStateChanged()
|
2015-11-18 12:34:52 +01:00
|
|
|
if (!d->m_profilerConnections->aggregateTraces())
|
|
|
|
d->m_recordButton->setEnabled(false);
|
2012-02-24 10:47:17 +01:00
|
|
|
}
|
2012-02-13 15:26:57 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-09 18:22:58 +02:00
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
void QmlProfilerTool::toggleRequestedFeature(QAction *action)
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
|
|
|
uint feature = action->data().toUInt();
|
|
|
|
if (action->isChecked())
|
2015-06-30 15:55:33 +02:00
|
|
|
d->m_profilerState->setRequestedFeatures(
|
|
|
|
d->m_profilerState->requestedFeatures() | (1ULL << feature));
|
2014-09-09 18:22:58 +02:00
|
|
|
else
|
2015-06-30 15:55:33 +02:00
|
|
|
d->m_profilerState->setRequestedFeatures(
|
|
|
|
d->m_profilerState->requestedFeatures() & (~(1ULL << feature)));
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
void QmlProfilerTool::toggleVisibleFeature(QAction *action)
|
|
|
|
{
|
|
|
|
uint feature = action->data().toUInt();
|
|
|
|
if (action->isChecked())
|
|
|
|
d->m_profilerModelManager->setVisibleFeatures(
|
|
|
|
d->m_profilerModelManager->visibleFeatures() | (1ULL << feature));
|
|
|
|
else
|
|
|
|
d->m_profilerModelManager->setVisibleFeatures(
|
|
|
|
d->m_profilerModelManager->visibleFeatures() & (~(1ULL << feature)));
|
|
|
|
}
|
|
|
|
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
}
|