qmlprofilerruncontrolfactory.cpp 4.66 KB
Newer Older
1
/****************************************************************************
2
**
3 4
** Copyright (C) 2016 Kläralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
** 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 27
#include "qmlprofilerruncontrolfactory.h"
#include "localqmlprofilerrunner.h"
28
#include "qmlprofilerruncontrol.h"
29
#include "qmlprofilerrunconfigurationaspect.h"
30

31
#include <debugger/analyzer/analyzermanager.h>
hjk's avatar
hjk committed
32 33
#include <debugger/analyzer/analyzerruncontrol.h>
#include <debugger/analyzer/analyzerstartparameters.h>
34 35 36
#include <debugger/debuggerrunconfigurationaspect.h>

#include <projectexplorer/environmentaspect.h>
37
#include <projectexplorer/kitinformation.h>
38
#include <projectexplorer/runnables.h>
39 40 41
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
42
#include <projectexplorer/target.h>
43 44
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
45

46
#include <utils/qtcassert.h>
47

48
using namespace Debugger;
49 50
using namespace ProjectExplorer;

51
namespace QmlProfiler {
52 53
namespace Internal {

54 55 56 57 58 59 60
static bool isLocal(RunConfiguration *runConfiguration)
{
    Target *target = runConfiguration ? runConfiguration->target() : 0;
    Kit *kit = target ? target->kit() : 0;
    return DeviceTypeKitInformation::deviceTypeId(kit) == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
}

61
QmlProfilerRunControlFactory::QmlProfilerRunControlFactory(QObject *parent) :
62 63 64 65
    IRunControlFactory(parent)
{
}

66
bool QmlProfilerRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const
67
{
68
    return mode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE && isLocal(runConfiguration);
69 70
}

71
RunControl *QmlProfilerRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
72
{
73
    QTC_ASSERT(canRun(runConfiguration, mode), return 0);
74
    QTC_ASSERT(runConfiguration->runnable().is<StandardRunnable>(), return 0);
75
    auto runnable = runConfiguration->runnable().as<StandardRunnable>();
76

77 78 79 80 81 82
    if (runnable.executable.isEmpty()) {
        if (errorMessage)
            *errorMessage = tr("No executable file to launch.");
        return 0;
    }

83
    Kit *kit = runConfiguration->target()->kit();
84 85
    AnalyzerConnection connection;
    const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
86
    if (version) {
87
        if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0))
88
            connection.analyzerSocket = LocalQmlProfilerRunner::findFreeSocket();
89
        else
90
            connection.analyzerPort = LocalQmlProfilerRunner::findFreePort(connection.analyzerHost);
91 92
    } else {
        qWarning() << "Running QML profiler on Kit without Qt version??";
93
        connection.analyzerPort = LocalQmlProfilerRunner::findFreePort(connection.analyzerHost);
94
    }
95

96
    auto runControl = qobject_cast<QmlProfilerRunControl *>
97
             (Debugger::createAnalyzerRunControl(runConfiguration, mode));
98 99 100 101 102 103
    QTC_ASSERT(runControl, return 0);

    runControl->setRunnable(runnable);
    runControl->setConnection(connection);

    LocalQmlProfilerRunner::Configuration conf;
104
    conf.debuggee = runnable;
105 106
    if (EnvironmentAspect *environment = runConfiguration->extraAspect<EnvironmentAspect>())
        conf.debuggee.environment = environment->environment();
107 108 109 110 111
    conf.socket = connection.analyzerSocket;
    conf.port = connection.analyzerPort;

    (void) new LocalQmlProfilerRunner(conf, runControl);
    return runControl;
112 113
}

114 115 116 117 118 119
ProjectExplorer::IRunConfigurationAspect *
QmlProfilerRunControlFactory::createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc)
{
    return new QmlProfilerRunConfigurationAspect(rc);
}

120
} // namespace Internal
121
} // namespace QmlProfiler