qmlprofilerplugin.cpp 5.24 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
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
12 13 14
** 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.
15
**
16 17 18 19 20 21 22
** 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.
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25

26
#include "qmlprofilerplugin.h"
27
#include "qmlprofilerrunconfigurationaspect.h"
28
#include "qmlprofileroptionspage.h"
29
#include "qmlprofilertool.h"
30
#include "qmlprofilertimelinemodel.h"
31

32
#ifdef WITH_TESTS
33

34
#include "tests/debugmessagesmodel_test.h"
35
#include "tests/flamegraphmodel_test.h"
36
#include "tests/flamegraphview_test.h"
37
#include "tests/inputeventsmodel_test.h"
38
#include "tests/localqmlprofilerrunner_test.h"
39
#include "tests/memoryusagemodel_test.h"
40
#include "tests/pixmapcachemodel_test.h"
41
#include "tests/qmlevent_test.h"
42
#include "tests/qmleventlocation_test.h"
43
#include "tests/qmleventtype_test.h"
44
#include "tests/qmlnote_test.h"
45
#include "tests/qmlprofileranimationsmodel_test.h"
46
#include "tests/qmlprofilerattachdialog_test.h"
47
#include "tests/qmlprofilerbindingloopsrenderpass_test.h"
48
#include "tests/qmlprofilerclientmanager_test.h"
49
#include "tests/qmlprofilerconfigwidget_test.h"
50 51 52 53 54 55 56 57

// Force QML Debugging to be enabled, so that we can selftest the profiler
#define QT_QML_DEBUG_NO_WARNING
#include <QQmlDebuggingEnabler>
#include <QQmlEngine>
#undef QT_QML_DEBUG_NO_WARNING

#endif // WITH_TESTS
58

Christiaan Janssen's avatar
Christiaan Janssen committed
59
#include <extensionsystem/pluginmanager.h>
60 61 62 63 64 65

#include <projectexplorer/environmentaspect.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>

66
#include <utils/hostosinfo.h>
67
#include <utils/qtcassert.h>
68

69
#include <QtPlugin>
70

71 72
using namespace ProjectExplorer;

hjk's avatar
hjk committed
73 74 75
namespace QmlProfiler {
namespace Internal {

76 77
Q_GLOBAL_STATIC(QmlProfilerSettings, qmlProfilerGlobalSettings)

78 79 80 81 82 83 84 85 86 87

class QmlProfilerRunControlFactory : public IRunControlFactory
{
public:
    IRunConfigurationAspect *createRunConfigurationAspect(RunConfiguration *rc) override
    {
        return new QmlProfilerRunConfigurationAspect(rc);
    }
};

88 89
bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
{
90
    Q_UNUSED(arguments)
91

92
    if (!Utils::HostOsInfo::canCreateOpenGLContext(errorString))
93
        return false;
94

95 96 97 98 99
    return true;
}

void QmlProfilerPlugin::extensionsInitialized()
{
100
    (void) new QmlProfilerTool(this);
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    addAutoReleasedObject(new QmlProfilerOptionsPage);
    addAutoReleasedObject(new QmlProfilerRunControlFactory);

    auto constraint = [](RunConfiguration *runConfiguration) {
        Target *target = runConfiguration ? runConfiguration->target() : nullptr;
        Kit *kit = target ? target->kit() : nullptr;
        return DeviceTypeKitInformation::deviceTypeId(kit)
                == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
    };

    RunControl::registerWorkerCreator(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE,
        [this](RunControl *runControl) { return new QmlProfilerRunner(runControl); });

    RunControl::registerWorker<LocalQmlProfilerSupport>
            (ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, constraint);
117 118 119 120
}

ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown()
{
121
    // Save settings.
122 123 124 125 126
    // 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;
}

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

132 133 134 135 136
QList<QObject *> QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() const
{
    QList<QObject *> tests;
#ifdef WITH_TESTS
    tests << new DebugMessagesModelTest;
137
    tests << new FlameGraphModelTest;
138
    tests << new FlameGraphViewTest;
139
    tests << new InputEventsModelTest;
140
    tests << new LocalQmlProfilerRunnerTest;
141
    tests << new MemoryUsageModelTest;
142
    tests << new PixmapCacheModelTest;
143
    tests << new QmlEventTest;
144
    tests << new QmlEventLocationTest;
145
    tests << new QmlEventTypeTest;
146
    tests << new QmlNoteTest;
147
    tests << new QmlProfilerAnimationsModelTest;
148
    tests << new QmlProfilerAttachDialogTest;
149
    tests << new QmlProfilerBindingLoopsRenderPassTest;
150
    tests << new QmlProfilerClientManagerTest;
151
    tests << new QmlProfilerConfigWidgetTest;
152 153

    tests << new QQmlEngine; // Trigger debug connector to be started
154 155 156 157
#endif
    return tests;
}

hjk's avatar
hjk committed
158 159
} // namespace Internal
} // namespace QmlProfiler