qmlprofilerruncontrolfactory.cpp 5.17 KB
Newer Older
1
/****************************************************************************
2
**
Aurindam Jana's avatar
Aurindam Jana committed
3
** Copyright (C) 2013 Kläralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
hjk's avatar
hjk committed
16 17 18 19 20 21 22 23 24 25
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

30 31 32
#include "qmlprofilerruncontrolfactory.h"
#include "localqmlprofilerrunner.h"
#include "qmlprofilerengine.h"
33

34 35 36 37 38
#include <analyzerbase/ianalyzertool.h>
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerstartparameters.h>
#include <analyzerbase/analyzerruncontrol.h>

39 40 41
#include <debugger/debuggerrunconfigurationaspect.h>

#include <projectexplorer/environmentaspect.h>
42
#include <projectexplorer/kitinformation.h>
43 44 45 46
#include <projectexplorer/localapplicationrunconfiguration.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
47
#include <projectexplorer/target.h>
48

49
#include <utils/qtcassert.h>
50

51 52
#include <QTcpServer>

53
using namespace Analyzer;
54 55
using namespace ProjectExplorer;

56
namespace QmlProfiler {
57 58
namespace Internal {

59
QmlProfilerRunControlFactory::QmlProfilerRunControlFactory(QObject *parent) :
60 61 62 63
    IRunControlFactory(parent)
{
}

64
bool QmlProfilerRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
65
{
hjk's avatar
hjk committed
66
    return mode == QmlProfilerRunMode
67
            && (qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration));
68 69
}

70 71 72 73 74 75
static AnalyzerStartParameters createQmlProfilerStartParameters(RunConfiguration *runConfiguration)
{
    AnalyzerStartParameters sp;
    EnvironmentAspect *environment = runConfiguration->extraAspect<EnvironmentAspect>();

    // FIXME: This is only used to communicate the connParams settings.
76 77 78 79 80 81 82 83 84 85
    LocalApplicationRunConfiguration *rc =
                qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
    QTC_ASSERT(rc, return sp);
    if (environment)
        sp.environment = environment->environment();
    sp.workingDirectory = rc->workingDirectory();
    sp.debuggee = rc->executable();
    sp.debuggeeArgs = rc->commandLineArguments();
    sp.displayName = rc->displayName();

86 87 88 89 90 91 92 93 94 95
    const IDevice::ConstPtr device = DeviceKitInformation::device(runConfiguration->target()->kit());
    if (device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
        QTcpServer server;
        if (!server.listen(QHostAddress::LocalHost) && !server.listen(QHostAddress::LocalHostIPv6)) {
            qWarning() << "Cannot open port on host for QML profiling.";
            return sp;
        }
        sp.analyzerHost = server.serverAddress().toString();
        sp.analyzerPort = server.serverPort();
    }
96
    sp.startMode = StartLocal;
97 98 99
    return sp;
}

100
RunControl *QmlProfilerRunControlFactory::create(RunConfiguration *runConfiguration, RunMode mode, QString *errorMessage)
101 102 103
{
    QTC_ASSERT(canRun(runConfiguration, mode), return 0);

104
    AnalyzerStartParameters sp = createQmlProfilerStartParameters(runConfiguration);
105
    sp.runMode = mode;
106

107
    // only desktop device is supported
108
    const IDevice::ConstPtr device = DeviceKitInformation::device(runConfiguration->target()->kit());
109 110
    QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);

111
    AnalyzerRunControl *rc = AnalyzerManager::createRunControl(sp, runConfiguration);
112
    QmlProfilerRunControl *engine = qobject_cast<QmlProfilerRunControl *>(rc);
113 114 115 116 117 118 119 120 121 122
    if (!engine) {
        delete rc;
        return 0;
    }
    LocalQmlProfilerRunner *runner = LocalQmlProfilerRunner::createLocalRunner(runConfiguration, sp, errorMessage, engine);
    if (!runner)
        return 0;
    connect(runner, SIGNAL(stopped()), engine, SLOT(notifyRemoteFinished()));
    connect(runner, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
            engine, SLOT(logApplicationMessage(QString,Utils::OutputFormat)));
123
    connect(engine, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)), runner,
124 125
            SLOT(start()));
    connect(rc, SIGNAL(finished()), runner, SLOT(stop()));
126 127 128 129
    return rc;
}

} // namespace Internal
130
} // namespace QmlProfiler