2011-03-25 09:25:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
|
|
|
** No Commercial Usage
|
|
|
|
**
|
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
** this package.
|
|
|
|
**
|
|
|
|
** 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, Nokia gives you certain additional
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
** Nokia at qt-info@nokia.com.
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
#include "qmlprofilerengine.h"
|
|
|
|
|
|
|
|
#include "qmlprofilerplugin.h"
|
|
|
|
#include "qmlprofilertool.h"
|
|
|
|
|
2011-03-24 12:42:15 +01:00
|
|
|
#include <analyzerbase/analyzermanager.h>
|
|
|
|
#include <analyzerbase/analyzerconstants.h>
|
2011-04-14 17:14:26 +02:00
|
|
|
#include <projectexplorer/applicationlauncher.h>
|
2011-03-24 12:42:15 +01:00
|
|
|
|
2011-04-14 15:49:12 +02:00
|
|
|
#include <qmljsdebugclient/qdeclarativedebugclient_p.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
#include "timelineview.h"
|
|
|
|
#include "tracewindow.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include "canvas/qdeclarativecanvas_p.h"
|
|
|
|
#include "canvas/qdeclarativecontext2d_p.h"
|
|
|
|
#include "canvas/qdeclarativetiledcanvas_p.h"
|
|
|
|
|
|
|
|
|
2011-03-24 13:02:57 +01:00
|
|
|
|
2011-03-25 09:21:00 +01:00
|
|
|
using namespace QmlProfiler::Internal;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
class QmlProfilerEngine::QmlProfilerEnginePrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmlProfilerEnginePrivate(QmlProfilerEngine *qq) : q(qq) {}
|
|
|
|
~QmlProfilerEnginePrivate() {}
|
|
|
|
|
2011-04-14 17:14:26 +02:00
|
|
|
void launchperfmonitor();
|
2011-04-04 15:03:31 +02:00
|
|
|
bool attach(const QString &address, uint port);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
QmlProfilerEngine *q;
|
|
|
|
|
2011-04-13 10:39:47 +02:00
|
|
|
Analyzer::AnalyzerStartParameters m_params;
|
2011-04-14 17:14:26 +02:00
|
|
|
ProjectExplorer::ApplicationLauncher m_launcher;
|
2011-03-11 12:22:57 +01:00
|
|
|
bool m_running;
|
2011-04-06 12:26:19 +02:00
|
|
|
bool m_fetchingData;
|
2011-04-14 16:05:41 +02:00
|
|
|
bool m_delayedDelete;
|
2011-03-11 12:22:57 +01:00
|
|
|
};
|
|
|
|
|
2011-04-04 14:39:28 +02:00
|
|
|
QmlProfilerEngine::QmlProfilerEngine(const Analyzer::AnalyzerStartParameters &sp, ProjectExplorer::RunConfiguration *runConfiguration)
|
|
|
|
: IAnalyzerEngine(sp, runConfiguration)
|
|
|
|
, d(new QmlProfilerEnginePrivate(this))
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-13 10:39:47 +02:00
|
|
|
d->m_params = sp;
|
2011-04-14 17:14:26 +02:00
|
|
|
|
2011-03-11 12:22:57 +01:00
|
|
|
d->m_running = false;
|
2011-04-06 12:26:19 +02:00
|
|
|
d->m_fetchingData = false;
|
2011-04-14 16:05:41 +02:00
|
|
|
d->m_delayedDelete = false;
|
2011-04-14 17:14:26 +02:00
|
|
|
|
|
|
|
connect(&d->m_launcher, SIGNAL(appendMessage(QString,ProjectExplorer::OutputFormat)),
|
|
|
|
this, SLOT(logApplicationMessage(QString,ProjectExplorer::OutputFormat)));
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerEngine::~QmlProfilerEngine()
|
|
|
|
{
|
|
|
|
if (d->m_running)
|
|
|
|
stop();
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEngine::start()
|
|
|
|
{
|
|
|
|
d->launchperfmonitor();
|
|
|
|
d->m_running = true;
|
2011-04-14 16:05:41 +02:00
|
|
|
d->m_delayedDelete = false;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
emit processRunning();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEngine::stop()
|
|
|
|
{
|
2011-04-14 16:05:41 +02:00
|
|
|
if (d->m_fetchingData) {
|
|
|
|
if (d->m_running)
|
|
|
|
d->m_delayedDelete = true;
|
2011-04-06 12:26:19 +02:00
|
|
|
emit stopRecording();
|
2011-04-14 16:05:41 +02:00
|
|
|
}
|
2011-04-06 12:26:19 +02:00
|
|
|
else
|
|
|
|
finishProcess();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 17:14:26 +02:00
|
|
|
void QmlProfilerEngine::spontaneousStop(int exitCode)
|
2011-03-24 12:42:15 +01:00
|
|
|
{
|
2011-04-14 17:14:26 +02:00
|
|
|
if (QmlProfilerPlugin::debugOutput)
|
|
|
|
qWarning() << "QmlProfiler: Application exited (exit code " << exitCode << ").";
|
2011-04-06 12:26:19 +02:00
|
|
|
d->m_running = false;
|
2011-03-25 09:21:00 +01:00
|
|
|
Analyzer::AnalyzerManager::instance()->stopTool();
|
2011-04-06 12:26:19 +02:00
|
|
|
emit finished();
|
2011-03-24 12:42:15 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 15:23:17 +02:00
|
|
|
void QmlProfilerEngine::setFetchingData(bool b)
|
|
|
|
{
|
2011-04-06 12:26:19 +02:00
|
|
|
d->m_fetchingData = b;
|
2011-04-14 15:23:17 +02:00
|
|
|
}
|
2011-04-06 12:26:19 +02:00
|
|
|
|
2011-04-14 16:05:41 +02:00
|
|
|
void QmlProfilerEngine::dataReceived() {
|
|
|
|
if (d->m_delayedDelete)
|
|
|
|
finishProcess();
|
|
|
|
d->m_delayedDelete = false;
|
|
|
|
}
|
|
|
|
|
2011-04-06 12:26:19 +02:00
|
|
|
void QmlProfilerEngine::finishProcess()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-14 17:14:26 +02:00
|
|
|
// user stop?
|
2011-04-14 15:23:17 +02:00
|
|
|
if (d->m_running) {
|
|
|
|
d->m_running = false;
|
2011-04-15 09:01:34 +02:00
|
|
|
disconnect(&d->m_launcher, SIGNAL(processExited(int)), this, SLOT(spontaneousStop(int)));
|
2011-04-14 17:14:26 +02:00
|
|
|
if (d->m_launcher.isRunning()) {
|
|
|
|
d->m_launcher.stop();
|
2011-03-24 12:42:15 +01:00
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-04-06 12:26:19 +02:00
|
|
|
emit finished();
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 17:14:26 +02:00
|
|
|
void QmlProfilerEngine::QmlProfilerEnginePrivate::launchperfmonitor()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-04-15 15:49:54 +02:00
|
|
|
QString arguments = QLatin1String("-qmljsdebugger=port:") + QString::number(m_params.connParams.port)
|
2011-04-14 17:14:26 +02:00
|
|
|
+ QLatin1String(",block");
|
2011-04-15 15:49:54 +02:00
|
|
|
if (!m_params.debuggeeArgs.isEmpty())
|
|
|
|
arguments += QChar(' ') + m_params.debuggeeArgs;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
if (QmlProfilerPlugin::debugOutput)
|
2011-04-14 17:14:26 +02:00
|
|
|
qWarning("QmlProfiler: Launching %s:%d", qPrintable(m_params.displayName), m_params.connParams.port);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-04-14 17:14:26 +02:00
|
|
|
m_launcher.setWorkingDirectory(m_params.workingDirectory);
|
|
|
|
m_launcher.setEnvironment(m_params.environment);
|
|
|
|
connect(&m_launcher, SIGNAL(processExited(int)), q, SLOT(spontaneousStop(int)));
|
|
|
|
m_launcher.start(ProjectExplorer::ApplicationLauncher::Gui, m_params.debuggee, arguments);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
2011-04-04 15:03:31 +02:00
|
|
|
|
2011-04-14 17:14:26 +02:00
|
|
|
void QmlProfilerEngine::logApplicationMessage(const QString &msg, ProjectExplorer::OutputFormat /*format*/)
|
|
|
|
{
|
|
|
|
qDebug() << "app: " << msg;
|
|
|
|
}
|