2012-02-09 16:04:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2012-02-09 16:04:43 +00:00
|
|
|
**
|
2012-02-16 04:43:03 +00:00
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
2012-02-09 16:04:43 +00:00
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-20 05:21:40 +00: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-28 11:55:39 +00: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 use the contact form at http://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2012-02-09 16:04:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-22 06:13:59 +00: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-09-20 05:21:40 +00:00
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2012-02-09 16:04:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlprofilerapplication.h"
|
|
|
|
#include "constants.h"
|
|
|
|
#include <QtCore/QStringList>
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
#include <QtCore/QDateTime>
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
#include <QtCore/QDebug>
|
2015-05-18 15:43:25 +00:00
|
|
|
#include <QtCore/QCommandLineParser>
|
2012-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
static const char commandTextC[] =
|
2015-05-19 13:54:16 +00:00
|
|
|
"The following commands are available:\n"
|
|
|
|
"\"r\", \"record\" Switch recording on or off.\n"
|
|
|
|
"\"q\", \"quit\" Terminate program.";
|
2012-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
static const char TraceFileExtension[] = ".qtd";
|
|
|
|
|
|
|
|
QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) :
|
|
|
|
QCoreApplication(argc, argv),
|
|
|
|
m_runMode(LaunchMode),
|
|
|
|
m_process(0),
|
|
|
|
m_tracePrefix(QLatin1String("trace")),
|
|
|
|
m_hostName(QLatin1String("127.0.0.1")),
|
|
|
|
m_port(3768),
|
|
|
|
m_verbose(false),
|
|
|
|
m_quitAfterSave(false),
|
2015-05-19 12:50:06 +00:00
|
|
|
m_recording(true),
|
2015-05-19 13:54:16 +00:00
|
|
|
m_interactive(false),
|
2012-03-05 01:39:24 +00:00
|
|
|
m_qmlProfilerClient(&m_connection),
|
2012-02-09 16:04:43 +00:00
|
|
|
m_v8profilerClient(&m_connection),
|
|
|
|
m_connectionAttempts(0),
|
2012-03-05 01:39:24 +00:00
|
|
|
m_qmlDataReady(false),
|
2012-02-09 16:04:43 +00:00
|
|
|
m_v8DataReady(false)
|
|
|
|
{
|
|
|
|
m_connectTimer.setInterval(1000);
|
|
|
|
connect(&m_connectTimer, SIGNAL(timeout()), this, SLOT(tryToConnect()));
|
|
|
|
|
|
|
|
connect(&m_connection, SIGNAL(connected()), this, SLOT(connected()));
|
|
|
|
connect(&m_connection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(connectionStateChanged(QAbstractSocket::SocketState)));
|
|
|
|
connect(&m_connection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError)));
|
|
|
|
|
2012-03-05 01:39:24 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(enabledChanged()), this, SLOT(traceClientEnabled()));
|
2012-05-02 15:32:57 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(range(QQmlProfilerService::RangeType,QQmlProfilerService::BindingType,qint64,qint64,QStringList,QmlEventLocation)),
|
|
|
|
&m_profilerData, SLOT(addQmlEvent(QQmlProfilerService::RangeType,QQmlProfilerService::BindingType,qint64,qint64,QStringList,QmlEventLocation)));
|
2012-03-08 15:50:14 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(traceFinished(qint64)), &m_profilerData, SLOT(setTraceEndTime(qint64)));
|
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(traceStarted(qint64)), &m_profilerData, SLOT(setTraceStartTime(qint64)));
|
2015-05-19 12:50:06 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(traceStarted(qint64)), this, SLOT(notifyTraceStarted()));
|
2014-03-17 13:52:01 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(frame(qint64,int,int,int)), &m_profilerData, SLOT(addFrameEvent(qint64,int,int,int)));
|
2014-02-19 17:11:41 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(sceneGraphFrame(QQmlProfilerService::SceneGraphFrameType,
|
|
|
|
qint64,qint64,qint64,qint64,qint64,qint64)),
|
|
|
|
&m_profilerData, SLOT(addSceneGraphFrameEvent(QQmlProfilerService::SceneGraphFrameType,
|
|
|
|
qint64,qint64,qint64,qint64,qint64,qint64)));
|
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(pixmapCache(QQmlProfilerService::PixmapEventType,qint64,
|
|
|
|
QmlEventLocation,int,int,int)),
|
|
|
|
&m_profilerData, SLOT(addPixmapCacheEvent(QQmlProfilerService::PixmapEventType,qint64,
|
|
|
|
QmlEventLocation,int,int,int)));
|
2014-06-16 11:33:33 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(memoryAllocation(QQmlProfilerService::MemoryType,qint64,
|
|
|
|
qint64)),
|
|
|
|
&m_profilerData, SLOT(addMemoryEvent(QQmlProfilerService::MemoryType,qint64,
|
|
|
|
qint64)));
|
2014-02-19 17:11:41 +00:00
|
|
|
|
2012-03-05 01:39:24 +00:00
|
|
|
connect(&m_qmlProfilerClient, SIGNAL(complete()), this, SLOT(qmlComplete()));
|
2012-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
connect(&m_v8profilerClient, SIGNAL(enabledChanged()), this, SLOT(profilerClientEnabled()));
|
|
|
|
connect(&m_v8profilerClient, SIGNAL(range(int,QString,QString,int,double,double)),
|
2012-03-08 15:50:14 +00:00
|
|
|
&m_profilerData, SLOT(addV8Event(int,QString,QString,int,double,double)));
|
2012-02-09 16:04:43 +00:00
|
|
|
connect(&m_v8profilerClient, SIGNAL(complete()), this, SLOT(v8Complete()));
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
connect(&m_profilerData, SIGNAL(error(QString)), this, SLOT(logError(QString)));
|
|
|
|
connect(&m_profilerData, SIGNAL(dataReady()), this, SLOT(traceFinished()));
|
2012-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerApplication::~QmlProfilerApplication()
|
|
|
|
{
|
|
|
|
if (!m_process)
|
|
|
|
return;
|
|
|
|
logStatus("Terminating process ...");
|
|
|
|
m_process->disconnect();
|
|
|
|
m_process->terminate();
|
|
|
|
if (!m_process->waitForFinished(1000)) {
|
|
|
|
logStatus("Killing process ...");
|
|
|
|
m_process->kill();
|
|
|
|
}
|
|
|
|
delete m_process;
|
|
|
|
}
|
|
|
|
|
2015-05-18 15:43:25 +00:00
|
|
|
void QmlProfilerApplication::parseArguments()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
2015-05-18 15:43:25 +00:00
|
|
|
setApplicationName(QLatin1String("qmlprofiler"));
|
|
|
|
setApplicationVersion(QLatin1String(qVersion()));
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
|
|
|
parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
|
|
|
|
|
|
|
|
parser.setApplicationDescription(QChar::LineFeed + tr(
|
|
|
|
"The QML Profiler retrieves QML tracing data from an application. The data\n"
|
|
|
|
"collected can then be visualized in Qt Creator. The application to be profiled\n"
|
|
|
|
"has to enable QML debugging. See the Qt Creator documentation on how to do\n"
|
2015-05-19 13:54:16 +00:00
|
|
|
"this for different Qt versions."));
|
2015-05-18 15:43:25 +00:00
|
|
|
|
|
|
|
QCommandLineOption attach(QStringList() << QLatin1String("a") << QLatin1String("attach"),
|
|
|
|
tr("Attach to an application already running on <hostname>, "
|
|
|
|
"instead of starting it locally."),
|
|
|
|
QLatin1String("hostname"));
|
|
|
|
parser.addOption(attach);
|
|
|
|
|
|
|
|
QCommandLineOption port(QStringList() << QLatin1String("p") << QLatin1String("port"),
|
|
|
|
tr("Connect to the TCP port <port>. The default is 3768."),
|
|
|
|
QLatin1String("port"), QLatin1String("3768"));
|
|
|
|
parser.addOption(port);
|
|
|
|
|
2015-05-19 12:50:06 +00:00
|
|
|
QCommandLineOption record(QLatin1String("record"),
|
|
|
|
tr("If set to 'off', don't immediately start recording data when the "
|
|
|
|
"QML engine starts, but instead either start the recording "
|
|
|
|
"interactively or with the JavaScript console.profile() function. "
|
|
|
|
"By default the recording starts immediately."),
|
|
|
|
QLatin1String("on|off"), QLatin1String("on"));
|
|
|
|
parser.addOption(record);
|
2015-05-18 15:43:25 +00:00
|
|
|
|
2015-05-19 13:54:16 +00:00
|
|
|
QCommandLineOption interactive(QLatin1String("interactive"),
|
|
|
|
tr("Manually control the recording from the command line. The "
|
|
|
|
"profiler will not terminate itself when the application "
|
|
|
|
"does so in this case.") + QChar::Space + tr(commandTextC));
|
|
|
|
parser.addOption(interactive);
|
|
|
|
|
2015-05-18 15:43:25 +00:00
|
|
|
QCommandLineOption verbose(QStringList() << QLatin1String("verbose"),
|
|
|
|
tr("Print debugging output."));
|
|
|
|
parser.addOption(verbose);
|
|
|
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
|
|
|
parser.addPositionalArgument(QLatin1String("program"),
|
|
|
|
tr("The program to be started and profiled."),
|
|
|
|
QLatin1String("[program]"));
|
|
|
|
parser.addPositionalArgument(QLatin1String("parameters"),
|
|
|
|
tr("Parameters for the program to be started."),
|
|
|
|
QLatin1String("[parameters...]"));
|
|
|
|
|
|
|
|
parser.process(*this);
|
|
|
|
|
|
|
|
if (parser.isSet(attach)) {
|
|
|
|
m_hostName = parser.value(attach);
|
|
|
|
m_runMode = AttachMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(port)) {
|
|
|
|
bool isNumber;
|
|
|
|
m_port = parser.value(port).toUShort(&isNumber);
|
|
|
|
if (!isNumber) {
|
|
|
|
logError(tr("'%1' is not a valid port.").arg(parser.value(port)));
|
|
|
|
parser.showHelp(1);
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 12:50:06 +00:00
|
|
|
m_recording = (parser.value(record) == QLatin1String("on"));
|
2015-05-19 13:54:16 +00:00
|
|
|
m_interactive = parser.isSet(interactive);
|
2012-02-09 16:04:43 +00:00
|
|
|
|
2015-05-18 15:43:25 +00:00
|
|
|
if (parser.isSet(verbose))
|
|
|
|
m_verbose = true;
|
2012-02-09 16:04:43 +00:00
|
|
|
|
2015-05-18 15:43:25 +00:00
|
|
|
m_programArguments = parser.positionalArguments();
|
|
|
|
if (!m_programArguments.isEmpty()) {
|
|
|
|
m_programPath = m_programArguments.takeFirst();
|
|
|
|
m_tracePrefix = QFileInfo(m_programPath).fileName();
|
|
|
|
}
|
2012-02-09 16:04:43 +00:00
|
|
|
|
2015-05-18 15:43:25 +00:00
|
|
|
if (m_runMode == LaunchMode && m_programPath.isEmpty()) {
|
|
|
|
logError(tr("You have to specify either --attach or a program to start."));
|
|
|
|
parser.showHelp(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_runMode == AttachMode && !m_programPath.isEmpty()) {
|
|
|
|
logError(tr("--attach cannot be used when starting a program."));
|
|
|
|
parser.showHelp(3);
|
|
|
|
}
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerApplication::exec()
|
|
|
|
{
|
|
|
|
QTimer::singleShot(0, this, SLOT(run()));
|
|
|
|
return QCoreApplication::exec();
|
|
|
|
}
|
|
|
|
|
2015-05-19 13:54:16 +00:00
|
|
|
bool QmlProfilerApplication::isInteractive() const
|
|
|
|
{
|
|
|
|
return m_interactive;
|
|
|
|
}
|
|
|
|
|
2012-02-09 16:04:43 +00:00
|
|
|
void QmlProfilerApplication::printCommands()
|
|
|
|
{
|
2015-05-18 15:43:25 +00:00
|
|
|
print(tr(commandTextC));
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProfilerApplication::traceFileName() const
|
|
|
|
{
|
|
|
|
QString fileName = m_tracePrefix + "_" +
|
|
|
|
QDateTime::currentDateTime().toString(QLatin1String("yyMMdd_hhmmss")) +
|
|
|
|
TraceFileExtension;
|
|
|
|
if (QFileInfo(fileName).exists()) {
|
|
|
|
QString baseName;
|
|
|
|
int suffixIndex = 0;
|
|
|
|
do {
|
|
|
|
baseName = QFileInfo(fileName).baseName()
|
|
|
|
+ QString::number(suffixIndex++);
|
|
|
|
} while (QFileInfo(baseName + TraceFileExtension).exists());
|
|
|
|
fileName = baseName + TraceFileExtension;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QFileInfo(fileName).absoluteFilePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::userCommand(const QString &command)
|
|
|
|
{
|
|
|
|
QString cmd = command.trimmed();
|
2015-05-21 13:39:28 +00:00
|
|
|
if (cmd == Constants::CMD_RECORD || cmd == Constants::CMD_RECORD2) {
|
2015-05-19 12:50:06 +00:00
|
|
|
m_qmlProfilerClient.sendRecordingStatus(!m_recording);
|
|
|
|
m_v8profilerClient.sendRecordingStatus(!m_recording);
|
2015-05-21 13:39:28 +00:00
|
|
|
emit readyForCommand();
|
2012-02-09 16:04:43 +00:00
|
|
|
} else if (cmd == Constants::CMD_QUIT
|
|
|
|
|| cmd == Constants::CMD_QUIT2) {
|
|
|
|
print(QLatin1String("Quit"));
|
2015-05-19 12:50:06 +00:00
|
|
|
if (m_recording) {
|
2012-02-09 16:04:43 +00:00
|
|
|
m_quitAfterSave = true;
|
2015-05-19 12:50:06 +00:00
|
|
|
m_qmlProfilerClient.sendRecordingStatus(false);
|
|
|
|
m_v8profilerClient.sendRecordingStatus(false);
|
2012-02-09 16:04:43 +00:00
|
|
|
} else {
|
|
|
|
quit();
|
|
|
|
}
|
2015-05-21 13:39:28 +00:00
|
|
|
} else {
|
|
|
|
printCommands();
|
|
|
|
emit readyForCommand();
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 12:50:06 +00:00
|
|
|
void QmlProfilerApplication::notifyTraceStarted()
|
|
|
|
{
|
|
|
|
// Synchronize to server state. It doesn't hurt to do this multiple times in a row for
|
|
|
|
// different traces. There is no symmetric event to "Complete" after all.
|
|
|
|
m_recording = true;
|
|
|
|
}
|
|
|
|
|
2012-02-09 16:04:43 +00:00
|
|
|
void QmlProfilerApplication::run()
|
|
|
|
{
|
|
|
|
if (m_runMode == LaunchMode) {
|
|
|
|
m_process = new QProcess(this);
|
|
|
|
QStringList arguments;
|
|
|
|
arguments << QString::fromLatin1("-qmljsdebugger=port:%1,block").arg(m_port);
|
|
|
|
arguments << m_programArguments;
|
|
|
|
|
|
|
|
m_process->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
connect(m_process, SIGNAL(readyRead()), this, SLOT(processHasOutput()));
|
|
|
|
connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this,
|
|
|
|
SLOT(processFinished()));
|
|
|
|
logStatus(QString("Starting '%1 %2' ...").arg(m_programPath,
|
|
|
|
arguments.join(" ")));
|
|
|
|
m_process->start(m_programPath, arguments);
|
|
|
|
if (!m_process->waitForStarted()) {
|
|
|
|
logError(QString("Could not run '%1': %2").arg(m_programPath,
|
|
|
|
m_process->errorString()));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
m_connectTimer.start();
|
2015-05-21 13:39:28 +00:00
|
|
|
emit readyForCommand();
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::tryToConnect()
|
|
|
|
{
|
|
|
|
Q_ASSERT(!m_connection.isConnected());
|
|
|
|
++ m_connectionAttempts;
|
|
|
|
|
|
|
|
if (!m_verbose && !(m_connectionAttempts % 5)) {// print every 5 seconds
|
|
|
|
if (!m_verbose)
|
|
|
|
logError(QString("Could not connect to %1:%2 for %3 seconds ...").arg(
|
|
|
|
m_hostName, QString::number(m_port),
|
|
|
|
QString::number(m_connectionAttempts)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_connection.state() == QAbstractSocket::UnconnectedState) {
|
|
|
|
logStatus(QString("Connecting to %1:%2 ...").arg(m_hostName,
|
|
|
|
QString::number(m_port)));
|
|
|
|
m_connection.connectToHost(m_hostName, m_port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::connected()
|
|
|
|
{
|
|
|
|
m_connectTimer.stop();
|
2015-05-19 12:50:06 +00:00
|
|
|
print(tr("Connected to host:port %1:%2. Wait for profile data or type a command (type 'help' "
|
|
|
|
"to show list of commands).").arg(m_hostName).arg((m_port)));
|
|
|
|
print(tr("Recording Status: %1").arg(m_recording ? tr("on") : tr("off")));
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::connectionStateChanged(
|
|
|
|
QAbstractSocket::SocketState state)
|
|
|
|
{
|
|
|
|
if (m_verbose)
|
|
|
|
qDebug() << state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::connectionError(QAbstractSocket::SocketError error)
|
|
|
|
{
|
|
|
|
if (m_verbose)
|
|
|
|
qDebug() << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::processHasOutput()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_process);
|
|
|
|
while (m_process->bytesAvailable()) {
|
|
|
|
QTextStream out(stdout);
|
|
|
|
out << m_process->readAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::processFinished()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_process);
|
2015-05-20 11:12:33 +00:00
|
|
|
int exitCode = 0;
|
2012-02-09 16:04:43 +00:00
|
|
|
if (m_process->exitStatus() == QProcess::NormalExit) {
|
|
|
|
logStatus(QString("Process exited (%1).").arg(m_process->exitCode()));
|
2015-05-19 12:50:06 +00:00
|
|
|
if (m_recording) {
|
2015-05-20 11:12:33 +00:00
|
|
|
logError("Process exited while recording, last trace is damaged!");
|
|
|
|
exitCode = 2;
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-05-20 11:12:33 +00:00
|
|
|
logError("Process crashed!");
|
|
|
|
exitCode = 3;
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
2015-05-20 11:12:33 +00:00
|
|
|
if (!m_interactive)
|
|
|
|
exit(exitCode);
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::traceClientEnabled()
|
|
|
|
{
|
|
|
|
logStatus("Trace client is attached.");
|
|
|
|
// blocked server is waiting for recording message from both clients
|
|
|
|
// once the last one is connected, both messages should be sent
|
2015-05-19 12:50:06 +00:00
|
|
|
m_qmlProfilerClient.sendRecordingStatus(m_recording);
|
|
|
|
m_v8profilerClient.sendRecordingStatus(m_recording);
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::profilerClientEnabled()
|
|
|
|
{
|
|
|
|
logStatus("Profiler client is attached.");
|
|
|
|
|
|
|
|
// blocked server is waiting for recording message from both clients
|
|
|
|
// once the last one is connected, both messages should be sent
|
2015-05-19 12:50:06 +00:00
|
|
|
m_qmlProfilerClient.sendRecordingStatus(m_recording);
|
|
|
|
m_v8profilerClient.sendRecordingStatus(m_recording);
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::traceFinished()
|
|
|
|
{
|
2015-05-19 12:50:06 +00:00
|
|
|
m_recording = false; // only on "Complete" we know that the trace is really finished.
|
2012-02-09 16:04:43 +00:00
|
|
|
const QString fileName = traceFileName();
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
if (m_profilerData.save(fileName))
|
2012-02-09 16:04:43 +00:00
|
|
|
print(QString("Saving trace to %1.").arg(fileName));
|
|
|
|
|
2015-05-19 12:50:06 +00:00
|
|
|
// after saving, reset the flags
|
|
|
|
m_qmlDataReady = false;
|
|
|
|
m_v8DataReady = false;
|
|
|
|
|
2012-02-09 16:04:43 +00:00
|
|
|
if (m_quitAfterSave)
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::print(const QString &line)
|
|
|
|
{
|
|
|
|
QTextStream err(stderr);
|
|
|
|
err << line << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::logError(const QString &error)
|
|
|
|
{
|
|
|
|
QTextStream err(stderr);
|
|
|
|
err << "Error: " << error << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::logStatus(const QString &status)
|
|
|
|
{
|
|
|
|
if (!m_verbose)
|
|
|
|
return;
|
|
|
|
QTextStream err(stderr);
|
|
|
|
err << status << endl;
|
|
|
|
}
|
|
|
|
|
2012-03-05 01:39:24 +00:00
|
|
|
void QmlProfilerApplication::qmlComplete()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
2012-03-05 01:39:24 +00:00
|
|
|
m_qmlDataReady = true;
|
2012-02-16 04:43:03 +00:00
|
|
|
if (m_v8profilerClient.state() != QQmlDebugClient::Enabled ||
|
2012-02-09 16:04:43 +00:00
|
|
|
m_v8DataReady) {
|
2012-03-08 15:50:14 +00:00
|
|
|
m_profilerData.complete();
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerApplication::v8Complete()
|
|
|
|
{
|
|
|
|
m_v8DataReady = true;
|
2012-03-05 01:39:24 +00:00
|
|
|
if (m_qmlProfilerClient.state() != QQmlDebugClient::Enabled ||
|
|
|
|
m_qmlDataReady) {
|
2012-03-08 15:50:14 +00:00
|
|
|
m_profilerData.complete();
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
}
|