2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2011-05-04 16:50:24 +02:00
|
|
|
**
|
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
|
|
|
|
|
|
|
|
#include <projectexplorer/runconfiguration.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>
|
2015-11-17 16:42:21 +01:00
|
|
|
#include <QTemporaryFile>
|
2011-05-04 16:50:24 +02:00
|
|
|
|
|
|
|
|
using namespace QmlProfiler;
|
2013-07-19 16:13:10 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2015-11-17 16:42:21 +01:00
|
|
|
QString LocalQmlProfilerRunner::findFreeSocket()
|
|
|
|
|
{
|
|
|
|
|
QTemporaryFile file;
|
|
|
|
|
if (file.open()) {
|
|
|
|
|
return file.fileName();
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Could not open a temporary file to find a debug socket.";
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:43:30 +02:00
|
|
|
Utils::Port LocalQmlProfilerRunner::findFreePort(QString &host)
|
2015-06-12 18:14:00 +02:00
|
|
|
{
|
|
|
|
|
QTcpServer server;
|
|
|
|
|
if (!server.listen(QHostAddress::LocalHost)
|
|
|
|
|
&& !server.listen(QHostAddress::LocalHostIPv6)) {
|
|
|
|
|
qWarning() << "Cannot open port on host for QML profiling.";
|
2016-04-19 16:43:30 +02:00
|
|
|
return Utils::Port();
|
2015-06-12 18:14:00 +02:00
|
|
|
}
|
|
|
|
|
host = server.serverAddress().toString();
|
2016-04-19 16:43:30 +02:00
|
|
|
return Utils::Port(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),
|
2016-01-27 16:02:28 +01:00
|
|
|
m_configuration(configuration)
|
2011-05-04 16:50:24 +02:00
|
|
|
{
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::appendMessage,
|
|
|
|
|
this, &LocalQmlProfilerRunner::appendMessage);
|
2016-01-19 17:25:18 +01:00
|
|
|
connect(this, &LocalQmlProfilerRunner::stopped,
|
|
|
|
|
engine, &QmlProfilerRunControl::notifyRemoteFinished);
|
|
|
|
|
connect(this, &LocalQmlProfilerRunner::appendMessage,
|
|
|
|
|
engine, &QmlProfilerRunControl::logApplicationMessage);
|
2016-03-02 13:57:37 +01:00
|
|
|
connect(engine, &Debugger::AnalyzerRunControl::starting,
|
2016-01-19 17:25:18 +01:00
|
|
|
this, &LocalQmlProfilerRunner::start);
|
|
|
|
|
connect(engine, &RunControl::finished,
|
|
|
|
|
this, &LocalQmlProfilerRunner::stop);
|
2011-05-04 16:50:24 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-05 10:48:16 +02:00
|
|
|
LocalQmlProfilerRunner::~LocalQmlProfilerRunner()
|
|
|
|
|
{
|
|
|
|
|
disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-04 16:50:24 +02:00
|
|
|
void LocalQmlProfilerRunner::start()
|
|
|
|
|
{
|
2016-01-27 16:56:36 +01:00
|
|
|
StandardRunnable runnable = m_configuration.debuggee;
|
2015-11-17 16:42:21 +01:00
|
|
|
QString arguments = m_configuration.socket.isEmpty() ?
|
|
|
|
|
QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices,
|
|
|
|
|
m_configuration.port) :
|
|
|
|
|
QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlProfilerServices,
|
|
|
|
|
m_configuration.socket);
|
|
|
|
|
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2016-01-27 16:02:28 +01:00
|
|
|
if (!m_configuration.debuggee.commandLineArguments.isEmpty())
|
|
|
|
|
arguments += QLatin1Char(' ') + m_configuration.debuggee.commandLineArguments;
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2016-01-27 16:56:36 +01:00
|
|
|
runnable.commandLineArguments = arguments;
|
|
|
|
|
runnable.runMode = ApplicationLauncher::Gui;
|
|
|
|
|
|
2015-11-17 16:42:21 +01:00
|
|
|
if (QmlProfilerPlugin::debugOutput) {
|
2016-04-19 16:43:30 +02:00
|
|
|
QString portOrSocket = m_configuration.socket.isEmpty() ?
|
|
|
|
|
QString::number(m_configuration.port.isValid() ?
|
|
|
|
|
m_configuration.port.number() : -1) :
|
|
|
|
|
m_configuration.socket;
|
2016-01-27 16:02:28 +01:00
|
|
|
qWarning("QmlProfiler: Launching %s:%s", qPrintable(m_configuration.debuggee.executable),
|
2016-04-19 16:43:30 +02:00
|
|
|
qPrintable(portOrSocket));
|
2015-11-17 16:42:21 +01:00
|
|
|
}
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::processExited,
|
|
|
|
|
this, &LocalQmlProfilerRunner::spontaneousStop);
|
2016-01-27 16:56:36 +01:00
|
|
|
m_launcher.start(runnable);
|
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
|
|
|
|
2015-10-30 12:35:17 +01:00
|
|
|
disconnect(&m_launcher, &ApplicationLauncher::processExited,
|
|
|
|
|
this, &LocalQmlProfilerRunner::spontaneousStop);
|
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();
|
|
|
|
|
}
|