forked from qt-creator/qt-creator
QmlProfiler: Move action registration out of QmlProfilerTool
This enables us to have multiple QmlProfilerTool instances without conflicting action registrations. Ultimately there should be a way to unregister actions, or to add some extra description on which tool instance they refer to, but this is a minimal first step. The main problem this fixes for now is the warnings generated by the tests. Change-Id: I2193fc48a5a68c52f46e5567919f3035bc93df36 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -15,6 +15,7 @@ SOURCES += \
|
||||
qmleventlocation.cpp \
|
||||
qmleventtype.cpp \
|
||||
qmlnote.cpp \
|
||||
qmlprofileractions.cpp \
|
||||
qmlprofileranimationsmodel.cpp \
|
||||
qmlprofilerattachdialog.cpp \
|
||||
qmlprofilerbindingloopsrenderpass.cpp \
|
||||
@@ -55,6 +56,7 @@ HEADERS += \
|
||||
qmleventtype.h \
|
||||
qmlnote.h \
|
||||
qmlprofiler_global.h \
|
||||
qmlprofileractions.h \
|
||||
qmlprofileranimationsmodel.h \
|
||||
qmlprofilerattachdialog.h \
|
||||
qmlprofilerbindingloopsrenderpass.h \
|
||||
|
||||
@@ -31,6 +31,7 @@ QtcPlugin {
|
||||
"qmleventtype.cpp", "qmleventtype.h",
|
||||
"qmlnote.cpp", "qmlnote.h",
|
||||
"qmlprofiler_global.h",
|
||||
"qmlprofileractions.h", "qmlprofileractions.cpp"
|
||||
"qmlprofileranimationsmodel.h", "qmlprofileranimationsmodel.cpp",
|
||||
"qmlprofilerattachdialog.cpp", "qmlprofilerattachdialog.h",
|
||||
"qmlprofilerbindingloopsrenderpass.cpp","qmlprofilerbindingloopsrenderpass.h",
|
||||
|
||||
113
src/plugins/qmlprofiler/qmlprofileractions.cpp
Normal file
113
src/plugins/qmlprofiler/qmlprofileractions.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmlprofileractions.h"
|
||||
#include "qmlprofilerconstants.h"
|
||||
#include "qmlprofilertool.h"
|
||||
#include "qmlprofilerstatemanager.h"
|
||||
#include "qmlprofilermodelmanager.h"
|
||||
|
||||
#include <debugger/analyzer/analyzerconstants.h>
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
|
||||
using namespace Core;
|
||||
using namespace Debugger::Constants;
|
||||
|
||||
QmlProfilerActions::QmlProfilerActions(QObject *parent) : QObject(parent)
|
||||
{}
|
||||
|
||||
void QmlProfilerActions::attachToTool(QmlProfilerTool *tool)
|
||||
{
|
||||
const QString description = tr("The QML Profiler can be used to find performance "
|
||||
"bottlenecks in applications using QML.");
|
||||
|
||||
m_runAction = std::make_unique<QAction>(tr("QML Profiler"));
|
||||
m_runAction->setToolTip(description);
|
||||
QObject::connect(m_runAction.get(), &QAction::triggered,
|
||||
tool, &QmlProfilerTool::profileStartupProject);
|
||||
|
||||
QAction *toolStartAction = tool->startAction();
|
||||
QObject::connect(toolStartAction, &QAction::changed, this, [this, toolStartAction] {
|
||||
m_runAction->setEnabled(toolStartAction->isEnabled());
|
||||
});
|
||||
|
||||
m_attachAction = std::make_unique<QAction>(tr("QML Profiler (Attach to Waiting Application)"));
|
||||
m_attachAction->setToolTip(description);
|
||||
QObject::connect(m_attachAction.get(), &QAction::triggered,
|
||||
tool, &QmlProfilerTool::attachToWaitingApplication);
|
||||
|
||||
m_loadQmlTrace = std::make_unique<QAction>(tr("Load QML Trace"));
|
||||
connect(m_loadQmlTrace.get(), &QAction::triggered,
|
||||
tool, &QmlProfilerTool::showLoadDialog, Qt::QueuedConnection);
|
||||
|
||||
m_saveQmlTrace = std::make_unique<QAction>(tr("Save QML Trace"));
|
||||
connect(m_saveQmlTrace.get(), &QAction::triggered,
|
||||
tool, &QmlProfilerTool::showSaveDialog, Qt::QueuedConnection);
|
||||
|
||||
QmlProfilerStateManager *stateManager = tool->stateManager();
|
||||
connect(stateManager, &QmlProfilerStateManager::serverRecordingChanged,
|
||||
this, [this, stateManager](bool recording) {
|
||||
m_loadQmlTrace->setEnabled(!recording);
|
||||
});
|
||||
m_loadQmlTrace->setEnabled(!stateManager->serverRecording());
|
||||
|
||||
QmlProfilerModelManager *modelManager = tool->modelManager();
|
||||
connect(modelManager, &QmlProfilerModelManager::traceChanged,
|
||||
this, [this, modelManager] {
|
||||
m_saveQmlTrace->setEnabled(!modelManager->isEmpty());
|
||||
});
|
||||
m_saveQmlTrace->setEnabled(!modelManager->isEmpty());
|
||||
}
|
||||
|
||||
void QmlProfilerActions::registerActions()
|
||||
{
|
||||
m_options.reset(ActionManager::createMenu("Analyzer.Menu.QMLOptions"));
|
||||
m_options->menu()->setTitle(tr("QML Profiler Options"));
|
||||
m_options->menu()->setEnabled(true);
|
||||
ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER);
|
||||
|
||||
menu->addAction(ActionManager::registerAction(m_runAction.get(),
|
||||
"QmlProfiler.Internal"),
|
||||
Debugger::Constants::G_ANALYZER_TOOLS);
|
||||
menu->addAction(ActionManager::registerAction(m_attachAction.get(),
|
||||
"QmlProfiler.AttachToWaitingApplication"),
|
||||
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
|
||||
|
||||
menu->addMenu(m_options.get(), G_ANALYZER_OPTIONS);
|
||||
m_options->addAction(ActionManager::registerAction(m_loadQmlTrace.get(),
|
||||
Constants::QmlProfilerLoadActionId));
|
||||
m_options->addAction(ActionManager::registerAction(m_saveQmlTrace.get(),
|
||||
Constants::QmlProfilerSaveActionId));
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProfiler
|
||||
57
src/plugins/qmlprofiler/qmlprofileractions.h
Normal file
57
src/plugins/qmlprofiler/qmlprofileractions.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QAction>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
|
||||
class QmlProfilerTool;
|
||||
class QmlProfilerActions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QmlProfilerActions(QObject *parent = nullptr);
|
||||
|
||||
void attachToTool(QmlProfilerTool *tool);
|
||||
void registerActions();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Core::ActionContainer> m_options;
|
||||
std::unique_ptr<QAction> m_loadQmlTrace;
|
||||
std::unique_ptr<QAction> m_saveQmlTrace;
|
||||
std::unique_ptr<QAction> m_runAction;
|
||||
std::unique_ptr<QAction> m_attachAction;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProfiler
|
||||
@@ -202,6 +202,12 @@ void QmlProfilerModelManager::replayQmlEvents(QmlEventLoader loader,
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerModelManager::clearEventStorage()
|
||||
{
|
||||
TimelineTraceManager::clearEventStorage();
|
||||
emit traceChanged();
|
||||
}
|
||||
|
||||
static QString getDisplayName(const QmlEventType &event)
|
||||
{
|
||||
if (event.location().filename().isEmpty()) {
|
||||
@@ -255,6 +261,7 @@ void QmlProfilerModelManager::finalize()
|
||||
// which happens on stateChanged(Done).
|
||||
|
||||
TimelineTraceManager::finalize();
|
||||
emit traceChanged();
|
||||
}
|
||||
|
||||
void QmlProfilerModelManager::populateFileFinder(const ProjectExplorer::Target *target)
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
QmlEventFilter rangeFilter(qint64 start, qint64 end) const;
|
||||
|
||||
signals:
|
||||
void traceChanged();
|
||||
void typeDetailsChanged(int typeId);
|
||||
void typeDetailsFinished();
|
||||
|
||||
@@ -90,6 +91,8 @@ private:
|
||||
void detailsChanged(int typeId, const QString &newString);
|
||||
void restrictByFilter(QmlEventFilter filter);
|
||||
|
||||
void clearEventStorage() final;
|
||||
|
||||
Timeline::TimelineTraceFile *createTraceFile() override;
|
||||
void replayEvents(TraceEventLoader loader, Initializer initializer, Finalizer finalizer,
|
||||
ErrorHandler errorHandler, QFutureInterface<void> &future) const override;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "qmlprofilersettings.h"
|
||||
#include "qmlprofilertool.h"
|
||||
#include "qmlprofilertimelinemodel.h"
|
||||
#include "qmlprofileractions.h"
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
@@ -84,6 +85,7 @@ class QmlProfilerPluginPrivate
|
||||
public:
|
||||
QmlProfilerTool m_profilerTool;
|
||||
QmlProfilerOptionsPage m_profilerOptionsPage;
|
||||
QmlProfilerActions m_actions;
|
||||
};
|
||||
|
||||
bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
@@ -99,6 +101,8 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
|
||||
void QmlProfilerPlugin::extensionsInitialized()
|
||||
{
|
||||
d = new QmlProfilerPluginPrivate;
|
||||
d->m_actions.attachToTool(&d->m_profilerTool);
|
||||
d->m_actions.registerActions();
|
||||
|
||||
RunConfiguration::registerAspect<QmlProfilerRunConfigurationAspect>();
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
#include <projectexplorer/taskhub.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/find/findplugin.h>
|
||||
@@ -66,9 +68,6 @@
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <coreplugin/imode.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
@@ -117,10 +116,6 @@ public:
|
||||
QToolButton *m_displayFeaturesButton = nullptr;
|
||||
QMenu *m_displayFeaturesMenu = nullptr;
|
||||
|
||||
// save and load actions
|
||||
QAction *m_saveQmlTrace = nullptr;
|
||||
QAction *m_loadQmlTrace = nullptr;
|
||||
|
||||
// elapsed time display
|
||||
QLabel *m_timeLabel = nullptr;
|
||||
QTimer m_recordingTimer;
|
||||
@@ -163,24 +158,6 @@ QmlProfilerTool::QmlProfilerTool()
|
||||
this, &QmlProfilerTool::onLoadSaveFinished);
|
||||
|
||||
d->m_profilerConnections->setModelManager(d->m_profilerModelManager);
|
||||
Command *command = nullptr;
|
||||
|
||||
ActionContainer *menu = ActionManager::actionContainer(M_DEBUG_ANALYZER);
|
||||
ActionContainer *options = ActionManager::createMenu("Analyzer.Menu.QMLOptions");
|
||||
options->menu()->setTitle(tr("QML Profiler Options"));
|
||||
menu->addMenu(options, G_ANALYZER_OPTIONS);
|
||||
options->menu()->setEnabled(true);
|
||||
|
||||
QAction *act = d->m_loadQmlTrace = new QAction(tr("Load QML Trace"), options);
|
||||
command = ActionManager::registerAction(act, Constants::QmlProfilerLoadActionId);
|
||||
connect(act, &QAction::triggered, this, &QmlProfilerTool::showLoadDialog, Qt::QueuedConnection);
|
||||
options->addAction(command);
|
||||
|
||||
act = d->m_saveQmlTrace = new QAction(tr("Save QML Trace"), options);
|
||||
d->m_saveQmlTrace->setEnabled(false);
|
||||
command = ActionManager::registerAction(act, Constants::QmlProfilerSaveActionId);
|
||||
connect(act, &QAction::triggered, this, &QmlProfilerTool::showSaveDialog, Qt::QueuedConnection);
|
||||
options->addAction(command);
|
||||
|
||||
d->m_recordingTimer.setInterval(100);
|
||||
connect(&d->m_recordingTimer, &QTimer::timeout, this, &QmlProfilerTool::updateTimeDisplay);
|
||||
@@ -246,32 +223,10 @@ QmlProfilerTool::QmlProfilerTool()
|
||||
// is available, then we can populate the file finder
|
||||
d->m_profilerModelManager->populateFileFinder();
|
||||
|
||||
QString description = tr("The QML Profiler can be used to find performance "
|
||||
"bottlenecks in applications using QML.");
|
||||
|
||||
d->m_startAction = Debugger::createStartAction();
|
||||
d->m_stopAction = Debugger::createStopAction();
|
||||
|
||||
act = new QAction(tr("QML Profiler"), this);
|
||||
act->setToolTip(description);
|
||||
menu->addAction(ActionManager::registerAction(act, "QmlProfiler.Internal"),
|
||||
Debugger::Constants::G_ANALYZER_TOOLS);
|
||||
QObject::connect(act, &QAction::triggered, this, [this] {
|
||||
if (!prepareTool())
|
||||
return;
|
||||
Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId);
|
||||
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
});
|
||||
QObject::connect(d->m_startAction, &QAction::triggered, act, &QAction::triggered);
|
||||
QObject::connect(d->m_startAction, &QAction::changed, act, [act, this] {
|
||||
act->setEnabled(d->m_startAction->isEnabled());
|
||||
});
|
||||
|
||||
act = new QAction(tr("QML Profiler (Attach to Waiting Application)"), this);
|
||||
act->setToolTip(description);
|
||||
menu->addAction(ActionManager::registerAction(act, "QmlProfiler.AttachToWaitingApplication"),
|
||||
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
|
||||
QObject::connect(act, &QAction::triggered, this, &QmlProfilerTool::attachToWaitingApplication);
|
||||
QObject::connect(d->m_startAction, &QAction::triggered, this, &QmlProfilerTool::profileStartupProject);
|
||||
|
||||
Utils::ToolbarDescription toolbar;
|
||||
toolbar.addAction(d->m_startAction);
|
||||
@@ -618,16 +573,6 @@ void QmlProfilerTool::showErrorDialog(const QString &error)
|
||||
errorDialog->show();
|
||||
}
|
||||
|
||||
void QmlProfilerTool::showLoadOption()
|
||||
{
|
||||
d->m_loadQmlTrace->setEnabled(!d->m_profilerState->serverRecording());
|
||||
}
|
||||
|
||||
void QmlProfilerTool::showSaveOption()
|
||||
{
|
||||
d->m_saveQmlTrace->setEnabled(!d->m_profilerModelManager->isEmpty());
|
||||
}
|
||||
|
||||
void saveLastTraceFile(const QString &filename)
|
||||
{
|
||||
QmlProfilerSettings *settings = QmlProfilerPlugin::globalSettings();
|
||||
@@ -681,6 +626,24 @@ void QmlProfilerTool::showLoadDialog()
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerTool::profileStartupProject()
|
||||
{
|
||||
if (!prepareTool())
|
||||
return;
|
||||
Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId);
|
||||
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
}
|
||||
|
||||
QAction *QmlProfilerTool::startAction() const
|
||||
{
|
||||
return d->m_startAction;
|
||||
}
|
||||
|
||||
QAction *QmlProfilerTool::stopAction() const
|
||||
{
|
||||
return d->m_stopAction;
|
||||
}
|
||||
|
||||
void QmlProfilerTool::onLoadSaveFinished()
|
||||
{
|
||||
disconnect(d->m_profilerModelManager, &QmlProfilerModelManager::recordedFeaturesChanged,
|
||||
@@ -793,7 +756,6 @@ void QmlProfilerTool::initialize()
|
||||
|
||||
void QmlProfilerTool::finalize()
|
||||
{
|
||||
showSaveOption();
|
||||
updateTimeDisplay();
|
||||
createTextMarks();
|
||||
setButtonsEnabled(true);
|
||||
@@ -878,7 +840,6 @@ void QmlProfilerTool::profilerStateChanged()
|
||||
|
||||
void QmlProfilerTool::serverRecordingChanged()
|
||||
{
|
||||
showLoadOption();
|
||||
if (d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
|
||||
// clear the old data each time we start a new profiling session
|
||||
if (d->m_profilerState->serverRecording()) {
|
||||
|
||||
@@ -77,6 +77,14 @@ public:
|
||||
|
||||
void gotoSourceLocation(const QString &fileUrl, int lineNumber, int columnNumber);
|
||||
|
||||
void showSaveDialog();
|
||||
void showLoadDialog();
|
||||
|
||||
void profileStartupProject();
|
||||
|
||||
QAction *startAction() const;
|
||||
QAction *stopAction() const;
|
||||
|
||||
private:
|
||||
void clearEvents();
|
||||
void clearData();
|
||||
@@ -85,10 +93,6 @@ private:
|
||||
void updateTimeDisplay();
|
||||
void showTimeLineSearch();
|
||||
|
||||
void showSaveOption();
|
||||
void showLoadOption();
|
||||
void showSaveDialog();
|
||||
void showLoadDialog();
|
||||
void onLoadSaveFinished();
|
||||
|
||||
void toggleRequestedFeature(QAction *action);
|
||||
|
||||
Reference in New Issue
Block a user