2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-25 09:25:17 +01: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-03-25 09:25:17 +01: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-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-25 09:25:17 +01:00
|
|
|
|
2015-07-01 18:11:54 +02:00
|
|
|
#include "qmlprofilerruncontrol.h"
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2017-08-10 16:11:55 +02:00
|
|
|
#include "qmlprofilerclientmanager.h"
|
|
|
|
|
#include "qmlprofilertool.h"
|
2016-01-28 18:24:08 +01:00
|
|
|
|
2011-06-09 14:30:15 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2011-06-28 15:51:20 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2016-05-30 16:56:46 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
2017-05-29 16:04:31 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2016-05-30 16:56:46 +02:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
2017-06-26 16:48:28 +02:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-10-15 16:46:35 +02:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2017-05-29 16:04:31 +02:00
|
|
|
|
|
|
|
|
#include <qmldebug/qmldebugcommandlinearguments.h>
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2016-05-30 16:56:46 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2018-04-16 13:42:43 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2017-09-29 12:41:53 +02:00
|
|
|
#include <utils/url.h>
|
2016-05-30 16:56:46 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMessageBox>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
using namespace Core;
|
2011-07-05 12:14:41 +02:00
|
|
|
using namespace ProjectExplorer;
|
2017-05-29 16:04:31 +02:00
|
|
|
using namespace QmlProfiler::Internal;
|
2011-06-30 13:44:22 +02:00
|
|
|
|
2011-05-20 13:36:16 +02:00
|
|
|
namespace QmlProfiler {
|
2018-01-09 14:50:12 +01:00
|
|
|
namespace Internal {
|
2011-05-04 16:50:24 +02:00
|
|
|
|
2017-06-14 10:50:18 +02:00
|
|
|
static QString QmlServerUrl = "QmlServerUrl";
|
|
|
|
|
|
2011-05-04 16:50:24 +02:00
|
|
|
//
|
2015-07-01 18:11:54 +02:00
|
|
|
// QmlProfilerRunControlPrivate
|
2011-05-04 16:50:24 +02:00
|
|
|
//
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
class QmlProfilerRunner::QmlProfilerRunnerPrivate
|
2011-05-20 13:36:16 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2017-08-15 16:41:32 +02:00
|
|
|
QPointer<QmlProfilerStateManager> m_profilerState;
|
2011-05-20 13:36:16 +02:00
|
|
|
};
|
|
|
|
|
|
2011-05-04 16:50:24 +02:00
|
|
|
//
|
2015-07-01 18:11:54 +02:00
|
|
|
// QmlProfilerRunControl
|
2011-05-04 16:50:24 +02:00
|
|
|
//
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
QmlProfilerRunner::QmlProfilerRunner(RunControl *runControl)
|
|
|
|
|
: RunWorker(runControl)
|
|
|
|
|
, d(new QmlProfilerRunnerPrivate)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2018-08-21 08:28:27 +02:00
|
|
|
setId("QmlProfilerRunner");
|
2017-05-29 13:14:16 +02:00
|
|
|
runControl->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL_TOOLBAR);
|
2017-07-05 15:17:38 +02:00
|
|
|
setSupportsReRunning(false);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
QmlProfilerRunner::~QmlProfilerRunner()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
void QmlProfilerRunner::start()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2018-01-09 14:50:12 +01:00
|
|
|
emit starting(this);
|
2017-05-29 16:04:31 +02:00
|
|
|
QTC_ASSERT(d->m_profilerState, return);
|
2017-06-26 16:48:28 +02:00
|
|
|
reportStarted();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
void QmlProfilerRunner::stop()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2018-01-08 15:19:27 +01:00
|
|
|
if (!d->m_profilerState) {
|
|
|
|
|
reportStopped();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-02-24 10:47:17 +01:00
|
|
|
|
|
|
|
|
switch (d->m_profilerState->currentState()) {
|
2015-10-20 12:48:26 +02:00
|
|
|
case QmlProfilerStateManager::AppRunning:
|
2012-02-24 10:47:17 +01:00
|
|
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppStopRequested);
|
2017-08-09 13:45:08 +02:00
|
|
|
break;
|
2015-10-20 12:48:26 +02:00
|
|
|
case QmlProfilerStateManager::AppStopRequested:
|
|
|
|
|
// Pressed "stop" a second time. Kill the application without collecting data
|
|
|
|
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::Idle);
|
2017-08-09 13:45:08 +02:00
|
|
|
reportStopped();
|
2015-10-20 12:48:26 +02:00
|
|
|
break;
|
2015-09-11 16:10:58 +02:00
|
|
|
case QmlProfilerStateManager::Idle:
|
|
|
|
|
case QmlProfilerStateManager::AppDying:
|
2012-05-08 15:14:11 +02:00
|
|
|
// valid, but no further action is needed
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
2012-07-27 15:43:00 +02:00
|
|
|
default: {
|
|
|
|
|
const QString message = QString::fromLatin1("Unexpected engine stop from state %1 in %2:%3")
|
|
|
|
|
.arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__));
|
|
|
|
|
qWarning("%s", qPrintable(message));
|
|
|
|
|
}
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
2011-05-04 16:50:24 +02:00
|
|
|
}
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
void QmlProfilerRunner::notifyRemoteFinished()
|
2011-03-24 12:42:15 +01:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
QTC_ASSERT(d->m_profilerState, return);
|
2011-07-13 14:47:34 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
switch (d->m_profilerState->currentState()) {
|
2015-09-11 16:10:58 +02:00
|
|
|
case QmlProfilerStateManager::AppRunning:
|
2014-03-18 13:00:21 +01:00
|
|
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppDying);
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
2015-09-11 16:10:58 +02:00
|
|
|
case QmlProfilerStateManager::Idle:
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
2015-09-11 16:10:58 +02:00
|
|
|
default:
|
2012-07-27 15:43:00 +02:00
|
|
|
const QString message = QString::fromLatin1("Process died unexpectedly from state %1 in %2:%3")
|
|
|
|
|
.arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__));
|
|
|
|
|
qWarning("%s", qPrintable(message));
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2011-04-14 15:23:17 +02:00
|
|
|
}
|
2011-04-06 12:26:19 +02:00
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
void QmlProfilerRunner::cancelProcess()
|
2011-05-20 13:36:16 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
QTC_ASSERT(d->m_profilerState, return);
|
2011-04-14 16:05:41 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
switch (d->m_profilerState->currentState()) {
|
2015-09-11 16:10:58 +02:00
|
|
|
case QmlProfilerStateManager::Idle:
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
2015-09-11 16:10:58 +02:00
|
|
|
case QmlProfilerStateManager::AppRunning:
|
2012-05-08 15:14:11 +02:00
|
|
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppDying);
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
|
|
|
|
default: {
|
2012-07-27 15:43:00 +02:00
|
|
|
const QString message = QString::fromLatin1("Unexpected process termination requested with state %1 in %2:%3")
|
|
|
|
|
.arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__));
|
|
|
|
|
qWarning("%s", qPrintable(message));
|
2012-02-24 10:47:17 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2011-04-06 12:26:19 +02:00
|
|
|
}
|
2017-05-29 16:04:31 +02:00
|
|
|
runControl()->initiateStop();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
void QmlProfilerRunner::registerProfilerStateManager( QmlProfilerStateManager *profilerState )
|
2012-02-24 10:47:17 +01:00
|
|
|
{
|
|
|
|
|
// disconnect old
|
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 (d->m_profilerState)
|
2015-10-30 12:35:17 +01:00
|
|
|
disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
|
2017-05-29 13:14:16 +02:00
|
|
|
this, &QmlProfilerRunner::profilerStateChanged);
|
2012-02-24 10:47:17 +01:00
|
|
|
|
|
|
|
|
d->m_profilerState = profilerState;
|
|
|
|
|
|
|
|
|
|
// connect
|
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 (d->m_profilerState)
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
|
2017-05-29 13:14:16 +02:00
|
|
|
this, &QmlProfilerRunner::profilerStateChanged);
|
2012-02-24 10:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:14:16 +02:00
|
|
|
void QmlProfilerRunner::profilerStateChanged()
|
2012-02-24 10:47:17 +01:00
|
|
|
{
|
|
|
|
|
switch (d->m_profilerState->currentState()) {
|
2015-09-11 16:10:58 +02:00
|
|
|
case QmlProfilerStateManager::Idle:
|
2017-08-08 15:11:23 +02:00
|
|
|
reportStopped();
|
2012-02-24 10:47:17 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 11:43:04 +02:00
|
|
|
void QmlProfilerRunner::setServerUrl(const QUrl &serverUrl)
|
2017-05-29 16:04:31 +02:00
|
|
|
{
|
2017-06-14 10:50:18 +02:00
|
|
|
recordData(QmlServerUrl, serverUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QUrl QmlProfilerRunner::serverUrl() const
|
|
|
|
|
{
|
|
|
|
|
QVariant recordedServer = recordedData(QmlServerUrl);
|
2017-06-29 18:32:01 +02:00
|
|
|
return recordedServer.toUrl();
|
2017-06-14 10:50:18 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-26 16:48:28 +02:00
|
|
|
//
|
|
|
|
|
// LocalQmlProfilerSupport
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static QUrl localServerUrl(RunControl *runControl)
|
2017-06-14 10:50:18 +02:00
|
|
|
{
|
2017-06-26 16:48:28 +02:00
|
|
|
QUrl serverUrl;
|
|
|
|
|
RunConfiguration *runConfiguration = runControl->runConfiguration();
|
|
|
|
|
Kit *kit = runConfiguration->target()->kit();
|
|
|
|
|
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
|
|
|
|
if (version) {
|
|
|
|
|
if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0))
|
2017-09-29 12:41:53 +02:00
|
|
|
serverUrl = Utils::urlFromLocalSocket();
|
2017-06-26 16:48:28 +02:00
|
|
|
else
|
2017-09-29 12:41:53 +02:00
|
|
|
serverUrl = Utils::urlFromLocalHostAndFreePort();
|
2017-06-26 16:48:28 +02:00
|
|
|
} else {
|
|
|
|
|
qWarning("Running QML profiler on Kit without Qt version?");
|
2017-09-29 12:41:53 +02:00
|
|
|
serverUrl = Utils::urlFromLocalHostAndFreePort();
|
2017-06-26 16:48:28 +02:00
|
|
|
}
|
|
|
|
|
return serverUrl;
|
|
|
|
|
}
|
2017-05-29 16:04:31 +02:00
|
|
|
|
2018-01-09 14:50:12 +01:00
|
|
|
LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
|
|
|
|
|
RunControl *runControl)
|
|
|
|
|
: LocalQmlProfilerSupport(profilerTool, runControl, localServerUrl(runControl))
|
2017-06-26 16:48:28 +02:00
|
|
|
{
|
|
|
|
|
}
|
2017-05-29 16:04:31 +02:00
|
|
|
|
2018-01-09 14:50:12 +01:00
|
|
|
LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
|
|
|
|
|
RunControl *runControl, const QUrl &serverUrl)
|
2017-08-09 10:46:21 +02:00
|
|
|
: SimpleTargetRunner(runControl)
|
2017-06-26 16:48:28 +02:00
|
|
|
{
|
2018-08-21 08:28:27 +02:00
|
|
|
setId("LocalQmlProfilerSupport");
|
2017-07-19 17:34:31 +02:00
|
|
|
|
2018-08-20 12:01:08 +02:00
|
|
|
QmlProfilerRunner *profiler = new QmlProfilerRunner(runControl);
|
|
|
|
|
profiler->setServerUrl(serverUrl);
|
|
|
|
|
connect(profiler, &QmlProfilerRunner::starting,
|
2018-01-09 14:50:12 +01:00
|
|
|
profilerTool, &QmlProfilerTool::finalizeRunControl);
|
2017-08-09 10:46:21 +02:00
|
|
|
|
2018-08-20 12:01:08 +02:00
|
|
|
addStopDependency(profiler);
|
2017-08-09 10:46:21 +02:00
|
|
|
// We need to open the local server before the application tries to connect.
|
|
|
|
|
// In the TCP case, it doesn't hurt either to start the profiler before.
|
2018-08-20 12:01:08 +02:00
|
|
|
addStartDependency(profiler);
|
2017-05-29 16:04:31 +02:00
|
|
|
|
2018-05-16 15:42:03 +02:00
|
|
|
Runnable debuggee = runnable();
|
2017-09-05 16:38:09 +02:00
|
|
|
|
2017-09-21 12:59:44 +02:00
|
|
|
QString code;
|
2017-09-29 12:41:53 +02:00
|
|
|
if (serverUrl.scheme() == Utils::urlSocketScheme())
|
2017-09-21 12:59:44 +02:00
|
|
|
code = QString("file:%1").arg(serverUrl.path());
|
2017-09-29 12:41:53 +02:00
|
|
|
else if (serverUrl.scheme() == Utils::urlTcpScheme())
|
2017-09-21 12:59:44 +02:00
|
|
|
code = QString("port:%1").arg(serverUrl.port());
|
|
|
|
|
else
|
|
|
|
|
QTC_CHECK(false);
|
2017-09-05 16:38:09 +02:00
|
|
|
|
2018-04-16 13:42:43 +02:00
|
|
|
QString arguments = Utils::QtcProcess::quoteArg(
|
|
|
|
|
QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlProfilerServices, code, true));
|
2017-05-29 16:04:31 +02:00
|
|
|
|
2017-06-26 16:48:28 +02:00
|
|
|
if (!debuggee.commandLineArguments.isEmpty())
|
|
|
|
|
arguments += ' ' + debuggee.commandLineArguments;
|
|
|
|
|
|
|
|
|
|
debuggee.commandLineArguments = arguments;
|
|
|
|
|
|
2017-08-09 10:46:21 +02:00
|
|
|
setRunnable(debuggee);
|
2017-05-29 16:04:31 +02:00
|
|
|
}
|
|
|
|
|
|
2018-01-09 14:50:12 +01:00
|
|
|
} // namespace Internal
|
2011-05-20 13:36:16 +02:00
|
|
|
} // namespace QmlProfiler
|