remotelinuxanalyzesupport.cpp 7.06 KB
Newer Older
1 2
/****************************************************************************
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5 6 7 8 9 10 11
**
** 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
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.
15 16 17
**
** GNU Lesser General Public License Usage
** 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.
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
27 28 29 30 31 32 33 34
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "remotelinuxanalyzesupport.h"

#include "remotelinuxrunconfiguration.h"

35
#include <analyzerbase/analyzerruncontrol.h>
36 37 38 39 40 41 42 43 44

#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
#include <projectexplorer/kitinformation.h>

#include <utils/qtcassert.h>
45
#include <utils/qtcprocess.h>
46
#include <qmldebug/qmloutputparser.h>
47
#include <qmldebug/qmldebugcommandlinearguments.h>
48 49 50 51 52 53 54 55 56 57 58 59 60

#include <QPointer>

using namespace QSsh;
using namespace Analyzer;
using namespace ProjectExplorer;

namespace RemoteLinux {
namespace Internal {

class RemoteLinuxAnalyzeSupportPrivate
{
public:
61
    RemoteLinuxAnalyzeSupportPrivate(AnalyzerRunControl *rc, Core::Id runMode)
62
        : runControl(rc),
63
          qmlProfiling(runMode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE),
64 65 66 67
          qmlPort(-1)
    {
    }

68
    const QPointer<AnalyzerRunControl> runControl;
69 70
    bool qmlProfiling;
    int qmlPort;
71 72

    QmlDebug::QmlOutputParser outputParser;
73 74 75 76 77 78
};

} // namespace Internal

using namespace Internal;

79
RemoteLinuxAnalyzeSupport::RemoteLinuxAnalyzeSupport(AbstractRemoteLinuxRunConfiguration *runConfig,
80
                                                     AnalyzerRunControl *engine, Core::Id runMode)
81
    : AbstractRemoteLinuxRunSupport(runConfig, engine),
82 83
      d(new RemoteLinuxAnalyzeSupportPrivate(engine, runMode))
{
84 85
    connect(d->runControl.data(), &AnalyzerRunControl::starting,
            this, &RemoteLinuxAnalyzeSupport::handleRemoteSetupRequested);
Montel Laurent's avatar
Montel Laurent committed
86 87
    connect(&d->outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort,
            this, &RemoteLinuxAnalyzeSupport::remoteIsRunning);
88 89
    connect(engine, &RunControl::finished,
            this, &RemoteLinuxAnalyzeSupport::handleProfilingFinished);
90 91 92 93 94 95 96 97 98
}

RemoteLinuxAnalyzeSupport::~RemoteLinuxAnalyzeSupport()
{
    delete d;
}

void RemoteLinuxAnalyzeSupport::showMessage(const QString &msg, Utils::OutputFormat format)
{
99 100
    if (state() != Inactive && d->runControl)
        d->runControl->logApplicationMessage(msg, format);
101
    d->outputParser.processOutput(msg);
102 103 104 105 106 107
}

void RemoteLinuxAnalyzeSupport::handleRemoteSetupRequested()
{
    QTC_ASSERT(state() == Inactive, return);

108
    showMessage(tr("Checking available ports...") + QLatin1Char('\n'), Utils::NormalMessageFormat);
109
    AbstractRemoteLinuxRunSupport::handleRemoteSetupRequested();
110 111 112 113 114 115
}

void RemoteLinuxAnalyzeSupport::startExecution()
{
    QTC_ASSERT(state() == GatheringPorts, return);

116 117 118 119 120
    // Currently we support only QML profiling
    QTC_ASSERT(d->qmlProfiling, return);

    if (!setPort(d->qmlPort))
        return;
121 122 123 124

    setState(StartingRunner);

    DeviceApplicationRunner *runner = appRunner();
Montel Laurent's avatar
Montel Laurent committed
125 126 127 128 129 130 131 132 133 134 135 136
    connect(runner, &DeviceApplicationRunner::remoteStderr,
            this, &RemoteLinuxAnalyzeSupport::handleRemoteErrorOutput);
    connect(runner, &DeviceApplicationRunner::remoteStdout,
            this, &RemoteLinuxAnalyzeSupport::handleRemoteOutput);
    connect(runner, &DeviceApplicationRunner::remoteProcessStarted,
            this, &RemoteLinuxAnalyzeSupport::handleRemoteProcessStarted);
    connect(runner, &DeviceApplicationRunner::finished,
            this, &RemoteLinuxAnalyzeSupport::handleAppRunnerFinished);
    connect(runner, &DeviceApplicationRunner::reportProgress,
            this, &RemoteLinuxAnalyzeSupport::handleProgressReport);
    connect(runner, &DeviceApplicationRunner::reportError,
            this, &RemoteLinuxAnalyzeSupport::handleAppRunnerError);
137

138
    const QStringList args = arguments()
139
            << QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, d->qmlPort);
140

141 142 143
    runner->setWorkingDirectory(workingDirectory());
    runner->setEnvironment(environment());
    runner->start(device(), remoteFilePath(), args);
144 145 146 147 148 149 150 151 152 153 154 155
}

void RemoteLinuxAnalyzeSupport::handleAppRunnerError(const QString &error)
{
    if (state() == Running)
        showMessage(error, Utils::ErrorMessageFormat);
    else if (state() != Inactive)
        handleAdapterSetupFailed(error);
}

void RemoteLinuxAnalyzeSupport::handleAppRunnerFinished(bool success)
{
156 157
    // reset needs to be called first to ensure that the correct state is set.
    reset();
158 159
    if (!success)
        showMessage(tr("Failure running remote process."), Utils::NormalMessageFormat);
160
    d->runControl->notifyRemoteFinished();
161 162 163 164 165 166 167
}

void RemoteLinuxAnalyzeSupport::handleProfilingFinished()
{
    setFinished();
}

168 169
void RemoteLinuxAnalyzeSupport::remoteIsRunning()
{
170
    d->runControl->notifyRemoteSetupDone(d->qmlPort);
171 172
}

173 174 175 176 177 178 179 180 181 182 183
void RemoteLinuxAnalyzeSupport::handleRemoteOutput(const QByteArray &output)
{
    QTC_ASSERT(state() == Inactive || state() == Running, return);

    showMessage(QString::fromUtf8(output), Utils::StdOutFormat);
}

void RemoteLinuxAnalyzeSupport::handleRemoteErrorOutput(const QByteArray &output)
{
    QTC_ASSERT(state() != GatheringPorts, return);

184
    if (!d->runControl)
185 186 187 188 189 190 191 192 193 194 195 196
        return;

    showMessage(QString::fromUtf8(output), Utils::StdErrFormat);
}

void RemoteLinuxAnalyzeSupport::handleProgressReport(const QString &progressOutput)
{
    showMessage(progressOutput + QLatin1Char('\n'), Utils::NormalMessageFormat);
}

void RemoteLinuxAnalyzeSupport::handleAdapterSetupFailed(const QString &error)
{
197
    AbstractRemoteLinuxRunSupport::handleAdapterSetupFailed(error);
198 199 200 201 202 203 204 205 206 207 208 209
    showMessage(tr("Initial setup failed: %1").arg(error), Utils::NormalMessageFormat);
}

void RemoteLinuxAnalyzeSupport::handleRemoteProcessStarted()
{
    QTC_ASSERT(d->qmlProfiling, return);
    QTC_ASSERT(state() == StartingRunner, return);

    handleAdapterSetupDone();
}

} // namespace RemoteLinux