2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** 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.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-05-04 16:50:24 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
#include "localqmlprofilerrunner.h"
|
|
|
|
|
#include "qmlprofilerplugin.h"
|
2015-07-01 18:11:54 +02:00
|
|
|
#include "qmlprofilerruncontrol.h"
|
2013-07-19 16:13:10 +02:00
|
|
|
|
2015-06-12 18:14:00 +02:00
|
|
|
#include <analyzerbase/analyzermanager.h>
|
|
|
|
|
#include <analyzerbase/analyzerruncontrol.h>
|
2013-07-19 16:13:10 +02:00
|
|
|
#include <analyzerbase/analyzerstartparameters.h>
|
|
|
|
|
#include <projectexplorer/runconfiguration.h>
|
|
|
|
|
#include <projectexplorer/localapplicationrunconfiguration.h>
|
|
|
|
|
#include <projectexplorer/environmentaspect.h>
|
2015-06-12 18:14:00 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2015-08-10 17:43:58 +02:00
|
|
|
#include <qmldebug/qmldebugcommandlinearguments.h>
|
2015-06-12 18:14:00 +02:00
|
|
|
|
|
|
|
|
#include <QTcpServer>
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
using namespace QmlProfiler;
|
2013-07-19 16:13:10 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2015-06-12 18:14:00 +02:00
|
|
|
Analyzer::AnalyzerRunControl *LocalQmlProfilerRunner::createLocalRunControl(
|
2013-07-19 16:13:10 +02:00
|
|
|
RunConfiguration *runConfiguration,
|
|
|
|
|
const Analyzer::AnalyzerStartParameters &sp,
|
2015-06-12 18:14:00 +02:00
|
|
|
QString *errorMessage)
|
2013-07-19 16:13:10 +02:00
|
|
|
{
|
2015-06-12 18:14:00 +02:00
|
|
|
// only desktop device is supported
|
|
|
|
|
const IDevice::ConstPtr device = DeviceKitInformation::device(
|
|
|
|
|
runConfiguration->target()->kit());
|
|
|
|
|
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);
|
|
|
|
|
|
|
|
|
|
Analyzer::AnalyzerRunControl *rc = Analyzer::AnalyzerManager::createRunControl(
|
|
|
|
|
sp, runConfiguration);
|
|
|
|
|
QmlProfilerRunControl *engine = qobject_cast<QmlProfilerRunControl *>(rc);
|
|
|
|
|
if (!engine) {
|
|
|
|
|
delete rc;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 16:13:10 +02:00
|
|
|
Configuration conf;
|
2015-06-12 18:14:00 +02:00
|
|
|
conf.executable = sp.debuggee;
|
|
|
|
|
conf.executableArguments = sp.debuggeeArgs;
|
|
|
|
|
conf.workingDirectory = sp.workingDirectory;
|
|
|
|
|
conf.environment = sp.environment;
|
2013-07-19 16:13:10 +02:00
|
|
|
|
|
|
|
|
conf.port = sp.analyzerPort;
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2013-07-19 16:13:10 +02:00
|
|
|
if (conf.executable.isEmpty()) {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("No executable file to launch.");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-06-12 18:14:00 +02:00
|
|
|
|
|
|
|
|
LocalQmlProfilerRunner *runner = new LocalQmlProfilerRunner(conf, engine);
|
|
|
|
|
|
|
|
|
|
QObject::connect(runner, SIGNAL(stopped()), engine, SLOT(notifyRemoteFinished()));
|
|
|
|
|
QObject::connect(runner, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
|
|
|
|
|
engine, SLOT(logApplicationMessage(QString,Utils::OutputFormat)));
|
|
|
|
|
QObject::connect(engine, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)), runner,
|
|
|
|
|
SLOT(start()));
|
|
|
|
|
QObject::connect(rc, SIGNAL(finished()), runner, SLOT(stop()));
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quint16 LocalQmlProfilerRunner::findFreePort(QString &host)
|
|
|
|
|
{
|
|
|
|
|
QTcpServer server;
|
|
|
|
|
if (!server.listen(QHostAddress::LocalHost)
|
|
|
|
|
&& !server.listen(QHostAddress::LocalHostIPv6)) {
|
|
|
|
|
qWarning() << "Cannot open port on host for QML profiling.";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
host = server.serverAddress().toString();
|
|
|
|
|
return server.serverPort();
|
2013-07-19 16:13:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration,
|
2013-07-30 14:08:01 +02:00
|
|
|
QmlProfilerRunControl *engine) :
|
2015-06-12 18:14:00 +02:00
|
|
|
QObject(engine),
|
2013-07-19 16:13:10 +02:00
|
|
|
m_configuration(configuration),
|
|
|
|
|
m_engine(engine)
|
2011-05-04 16:50:24 +02:00
|
|
|
{
|
|
|
|
|
connect(&m_launcher, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
|
|
|
|
|
this, SIGNAL(appendMessage(QString,Utils::OutputFormat)));
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-05 10:48:16 +02:00
|
|
|
LocalQmlProfilerRunner::~LocalQmlProfilerRunner()
|
|
|
|
|
{
|
|
|
|
|
disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-04 16:50:24 +02:00
|
|
|
void LocalQmlProfilerRunner::start()
|
|
|
|
|
{
|
2015-08-10 17:43:58 +02:00
|
|
|
QString arguments = QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlProfilerServices,
|
|
|
|
|
m_configuration.port);
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
if (!m_configuration.executableArguments.isEmpty())
|
2012-11-26 21:18:13 +02:00
|
|
|
arguments += QLatin1Char(' ') + m_configuration.executableArguments;
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
if (QmlProfilerPlugin::debugOutput)
|
|
|
|
|
qWarning("QmlProfiler: Launching %s:%d", qPrintable(m_configuration.executable),
|
|
|
|
|
m_configuration.port);
|
|
|
|
|
|
|
|
|
|
m_launcher.setWorkingDirectory(m_configuration.workingDirectory);
|
|
|
|
|
m_launcher.setEnvironment(m_configuration.environment);
|
2013-08-01 17:38:49 +02:00
|
|
|
connect(&m_launcher, SIGNAL(processExited(int,QProcess::ExitStatus)),
|
|
|
|
|
this, SLOT(spontaneousStop(int,QProcess::ExitStatus)));
|
2015-02-03 23:48:57 +02:00
|
|
|
m_launcher.start(ApplicationLauncher::Gui, m_configuration.executable, arguments);
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
emit started();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 17:38:49 +02:00
|
|
|
void LocalQmlProfilerRunner::spontaneousStop(int exitCode, QProcess::ExitStatus status)
|
2011-05-04 16:50:24 +02:00
|
|
|
{
|
2013-08-01 17:38:49 +02:00
|
|
|
if (QmlProfilerPlugin::debugOutput) {
|
|
|
|
|
if (status == QProcess::CrashExit)
|
|
|
|
|
qWarning("QmlProfiler: Application crashed.");
|
|
|
|
|
else
|
|
|
|
|
qWarning("QmlProfiler: Application exited (exit code %d).", exitCode);
|
|
|
|
|
}
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2013-08-01 17:38:49 +02:00
|
|
|
disconnect(&m_launcher, SIGNAL(processExited(int,QProcess::ExitStatus)),
|
|
|
|
|
this, SLOT(spontaneousStop(int,QProcess::ExitStatus)));
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
emit stopped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalQmlProfilerRunner::stop()
|
|
|
|
|
{
|
|
|
|
|
if (QmlProfilerPlugin::debugOutput)
|
2011-05-05 09:14:41 +02:00
|
|
|
qWarning("QmlProfiler: Stopping application ...");
|
2011-05-04 16:50:24 +02:00
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_launcher.isRunning())
|
2011-05-04 16:50:24 +02:00
|
|
|
m_launcher.stop();
|
|
|
|
|
}
|