qmlprofilerplugin.cpp 4.91 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Kai Koehne's avatar
Kai Koehne committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
Kai Koehne's avatar
Kai Koehne committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Kai Koehne's avatar
Kai Koehne committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
Kai Koehne's avatar
Kai Koehne committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
Kai Koehne's avatar
Kai Koehne committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
Kai Koehne's avatar
Kai Koehne committed
30

Christiaan Janssen's avatar
Christiaan Janssen committed
31
#include "qmlprofilerplugin.h"
32
#include "qmlprofilerruncontrolfactory.h"
33
#include "qmlprofileroptionspage.h"
34
#include "qmlprofilertool.h"
35
#include "qmlprofilertimelinemodel.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
36 37

#include <analyzerbase/analyzermanager.h>
Christiaan Janssen's avatar
Christiaan Janssen committed
38
#include <extensionsystem/pluginmanager.h>
39
#include <utils/hostosinfo.h>
Christiaan Janssen's avatar
Christiaan Janssen committed
40

41
#include <QtPlugin>
Christiaan Janssen's avatar
Christiaan Janssen committed
42 43

using namespace Analyzer;
hjk's avatar
hjk committed
44 45 46 47

namespace QmlProfiler {
namespace Internal {

48 49
Q_GLOBAL_STATIC(QmlProfilerSettings, qmlProfilerGlobalSettings)

Christiaan Janssen's avatar
Christiaan Janssen committed
50
bool QmlProfilerPlugin::debugOutput = false;
Christiaan Janssen's avatar
Christiaan Janssen committed
51
QmlProfilerPlugin *QmlProfilerPlugin::instance = 0;
Christiaan Janssen's avatar
Christiaan Janssen committed
52 53 54

bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
{
55
    Q_UNUSED(arguments)
56

57
    if (!Utils::HostOsInfo::canCreateOpenGLContext(errorString))
58
        return false;
59

hjk's avatar
hjk committed
60 61 62
    auto tool = new QmlProfilerTool(this);
    auto widgetCreator = [tool] { return tool->createWidgets(); };
    auto runControlCreator = [tool](const AnalyzerStartParameters &sp,
63
        ProjectExplorer::RunConfiguration *runConfiguration, Core::Id) {
hjk's avatar
hjk committed
64 65
        return tool->createRunControl(sp, runConfiguration);
    };
hjk's avatar
hjk committed
66

hjk's avatar
hjk committed
67
    AnalyzerAction *action = 0;
hjk's avatar
hjk committed
68 69 70 71 72

    QString description = QmlProfilerTool::tr(
        "The QML Profiler can be used to find performance bottlenecks in "
        "applications using QML.");

hjk's avatar
hjk committed
73
    action = new AnalyzerAction(this);
74 75
    action->setActionId(Constants::QmlProfilerLocalActionId);
    action->setToolId(Constants::QmlProfilerToolId);
hjk's avatar
hjk committed
76 77
    action->setWidgetCreator(widgetCreator);
    action->setRunControlCreator(runControlCreator);
78
    action->setToolPreparer([tool] { return tool->prepareTool(); });
79
    action->setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
hjk's avatar
hjk committed
80 81
    action->setText(tr("QML Profiler"));
    action->setToolTip(description);
82
    action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
hjk's avatar
hjk committed
83 84
    AnalyzerManager::addAction(action);

hjk's avatar
hjk committed
85
    action = new AnalyzerAction(this);
86 87
    action->setActionId(Constants::QmlProfilerRemoteActionId);
    action->setToolId(Constants::QmlProfilerToolId);
hjk's avatar
hjk committed
88 89
    action->setWidgetCreator(widgetCreator);
    action->setRunControlCreator(runControlCreator);
90
    action->setCustomToolStarter([tool] { tool->startRemoteTool(); });
91
    action->setToolPreparer([tool] { return tool->prepareTool(); });
92
    action->setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
hjk's avatar
hjk committed
93 94
    action->setText(tr("QML Profiler (External)"));
    action->setToolTip(description);
95
    action->setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
hjk's avatar
hjk committed
96
    AnalyzerManager::addAction(action);
97

98
    addAutoReleasedObject(new QmlProfilerRunControlFactory());
99
    addAutoReleasedObject(new Internal::QmlProfilerOptionsPage());
Christiaan Janssen's avatar
Christiaan Janssen committed
100
    QmlProfilerPlugin::instance = this;
101

Christiaan Janssen's avatar
Christiaan Janssen committed
102 103 104 105 106
    return true;
}

void QmlProfilerPlugin::extensionsInitialized()
{
107
    factory = ExtensionSystem::PluginManager::getObject<QmlProfilerTimelineModelFactory>();
Christiaan Janssen's avatar
Christiaan Janssen committed
108 109 110 111
}

ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown()
{
112
    // Save settings.
Christiaan Janssen's avatar
Christiaan Janssen committed
113 114 115 116 117
    // Disconnect from signals that are not needed during shutdown
    // Hide UI (if you add UI that is not in the main window directly)
    return SynchronousShutdown;
}

118
QList<QmlProfilerTimelineModel *> QmlProfilerPlugin::getModels(QmlProfilerModelManager *manager) const
Christiaan Janssen's avatar
Christiaan Janssen committed
119
{
120 121 122 123
    if (factory)
        return factory->create(manager);
    else
        return QList<QmlProfilerTimelineModel *>();
Christiaan Janssen's avatar
Christiaan Janssen committed
124 125
}

126 127 128 129 130
QmlProfilerSettings *QmlProfilerPlugin::globalSettings()
{
    return qmlProfilerGlobalSettings();
}

hjk's avatar
hjk committed
131 132
} // namespace Internal
} // namespace QmlProfiler