forked from qt-creator/qt-creator
QmlProfiler: Show profiling data initiated by console APIs
The profile clients now also listens to profiling data sent by console APIs console.profile and console.profileEnd Change-Id: I7f7100448263889076e94a1e251b8977ce047843 Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
This commit is contained in:
@@ -823,17 +823,17 @@ int QmlProfilerEventList::count() const
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void QmlProfilerEventList::save(const QString &filename)
|
||||
bool QmlProfilerEventList::save(const QString &filename)
|
||||
{
|
||||
if (count() == 0) {
|
||||
emit error(tr("No data to save"));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
emit error(tr("Could not open %1 for writing").arg(filename));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
QXmlStreamWriter stream(&file);
|
||||
@@ -899,6 +899,7 @@ void QmlProfilerEventList::save(const QString &filename)
|
||||
stream.writeEndDocument();
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void QmlProfilerEventList::setFilename(const QString &filename)
|
||||
|
||||
@@ -144,7 +144,7 @@ public slots:
|
||||
void complete();
|
||||
|
||||
void addV8Event(int depth,const QString &function,const QString &filename, int lineNumber, double totalTime, double selfTime);
|
||||
void save(const QString &filename);
|
||||
bool save(const QString &filename);
|
||||
void load(const QString &filename);
|
||||
void setFilename(const QString &filename);
|
||||
void load();
|
||||
|
||||
@@ -79,6 +79,10 @@ QmlProfilerTraceClient::QmlProfilerTraceClient(QDeclarativeDebugConnection *clie
|
||||
|
||||
QmlProfilerTraceClient::~QmlProfilerTraceClient()
|
||||
{
|
||||
//Disable profiling if started by client
|
||||
//Profiling data will be lost!!
|
||||
if (isRecording())
|
||||
setRecording(false);
|
||||
delete d;
|
||||
}
|
||||
|
||||
@@ -88,6 +92,11 @@ void QmlProfilerTraceClient::clearData()
|
||||
emit cleared();
|
||||
}
|
||||
|
||||
void QmlProfilerTraceClient::sendRecordingStatus()
|
||||
{
|
||||
d->sendRecordingStatus();
|
||||
}
|
||||
|
||||
bool QmlProfilerTraceClient::isEnabled() const
|
||||
{
|
||||
return status() == Enabled;
|
||||
@@ -106,17 +115,14 @@ void QmlProfilerTraceClient::setRecording(bool v)
|
||||
d->recording = v;
|
||||
|
||||
if (status() == Enabled) {
|
||||
d->sendRecordingStatus();
|
||||
sendRecordingStatus();
|
||||
}
|
||||
|
||||
emit recordingChanged(v);
|
||||
}
|
||||
|
||||
void QmlProfilerTraceClient::statusChanged(Status status)
|
||||
void QmlProfilerTraceClient::statusChanged(Status /*status*/)
|
||||
{
|
||||
if (status == Enabled) {
|
||||
d->sendRecordingStatus();
|
||||
}
|
||||
emit enabledChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ public:
|
||||
public slots:
|
||||
void setRecording(bool);
|
||||
void clearData();
|
||||
void sendRecordingStatus();
|
||||
|
||||
signals:
|
||||
void complete();
|
||||
|
||||
@@ -77,6 +77,10 @@ QV8ProfilerClient::QV8ProfilerClient(QDeclarativeDebugConnection *client)
|
||||
|
||||
QV8ProfilerClient::~QV8ProfilerClient()
|
||||
{
|
||||
//Disable profiling if started by client
|
||||
//Profiling data will be lost!!
|
||||
if (isRecording())
|
||||
setRecording(false);
|
||||
delete d;
|
||||
}
|
||||
|
||||
@@ -90,6 +94,11 @@ bool QV8ProfilerClient::isEnabled() const
|
||||
return status() == Enabled;
|
||||
}
|
||||
|
||||
void QV8ProfilerClient::sendRecordingStatus()
|
||||
{
|
||||
d->sendRecordingStatus();
|
||||
}
|
||||
|
||||
bool QV8ProfilerClient::isRecording() const
|
||||
{
|
||||
return d->recording;
|
||||
@@ -103,17 +112,14 @@ void QV8ProfilerClient::setRecording(bool v)
|
||||
d->recording = v;
|
||||
|
||||
if (status() == Enabled) {
|
||||
d->sendRecordingStatus();
|
||||
sendRecordingStatus();
|
||||
}
|
||||
|
||||
emit recordingChanged(v);
|
||||
}
|
||||
|
||||
void QV8ProfilerClient::statusChanged(Status status)
|
||||
void QV8ProfilerClient::statusChanged(Status /*status*/)
|
||||
{
|
||||
if (status == Enabled) {
|
||||
d->sendRecordingStatus();
|
||||
}
|
||||
emit enabledChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
public slots:
|
||||
void setRecording(bool);
|
||||
void clearData();
|
||||
void sendRecordingStatus();
|
||||
|
||||
signals:
|
||||
void complete();
|
||||
|
||||
@@ -312,11 +312,13 @@ void TraceWindow::connectClientSignals()
|
||||
connect(m_plugin.data(), SIGNAL(traceFinished(qint64)), this, SIGNAL(traceFinished(qint64)));
|
||||
connect(m_plugin.data(), SIGNAL(traceStarted(qint64)), this, SIGNAL(traceStarted(qint64)));
|
||||
connect(m_plugin.data(), SIGNAL(enabledChanged()), this, SLOT(updateProfilerState()));
|
||||
connect(m_plugin.data(), SIGNAL(enabledChanged()), m_plugin.data(), SLOT(sendRecordingStatus()));
|
||||
}
|
||||
if (m_v8plugin) {
|
||||
connect(m_v8plugin.data(), SIGNAL(complete()), this, SLOT(v8Complete()));
|
||||
connect(m_v8plugin.data(), SIGNAL(v8range(int,QString,QString,int,double,double)), this, SIGNAL(v8range(int,QString,QString,int,double,double)));
|
||||
connect(m_v8plugin.data(), SIGNAL(enabledChanged()), this, SLOT(updateProfilerState()));
|
||||
connect(m_v8plugin.data(), SIGNAL(enabledChanged()), m_v8plugin.data(), SLOT(sendRecordingStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,11 +331,13 @@ void TraceWindow::disconnectClientSignals()
|
||||
disconnect(m_plugin.data(), SIGNAL(traceFinished(qint64)), this, SIGNAL(traceFinished(qint64)));
|
||||
disconnect(m_plugin.data(), SIGNAL(traceStarted(qint64)), this, SIGNAL(traceStarted(qint64)));
|
||||
disconnect(m_plugin.data(), SIGNAL(enabledChanged()), this, SLOT(updateProfilerState()));
|
||||
disconnect(m_plugin.data(), SIGNAL(enabledChanged()), m_plugin.data(), SLOT(sendRecordingStatus()));
|
||||
}
|
||||
if (m_v8plugin) {
|
||||
disconnect(m_v8plugin.data(), SIGNAL(complete()), this, SLOT(v8Complete()));
|
||||
disconnect(m_v8plugin.data(), SIGNAL(v8range(int,QString,QString,int,double,double)), this, SIGNAL(v8range(int,QString,QString,int,double,double)));
|
||||
disconnect(m_v8plugin.data(), SIGNAL(enabledChanged()), this, SLOT(updateProfilerState()));
|
||||
disconnect(m_v8plugin.data(), SIGNAL(enabledChanged()), m_v8plugin.data(), SLOT(sendRecordingStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ static const char usageTextC[] =
|
||||
" -help Show this information and exit.\n"
|
||||
" -fromStart\n"
|
||||
" Record as soon as the engine is started, default is false.\n"
|
||||
" -p=<number>, -port=<number>\n"
|
||||
" -p <number>, -port <number>\n"
|
||||
" TCP/IP port to use, default is 3768.\n"
|
||||
" -v, -verbose\n"
|
||||
" Print debugging output.\n"
|
||||
@@ -83,7 +83,7 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) :
|
||||
m_port(3768),
|
||||
m_verbose(false),
|
||||
m_quitAfterSave(false),
|
||||
m_traceClient(&m_connection),
|
||||
m_qmlProfilerClient(&m_connection),
|
||||
m_v8profilerClient(&m_connection),
|
||||
m_connectionAttempts(0)
|
||||
{
|
||||
@@ -94,17 +94,17 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) :
|
||||
connect(&m_connection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(connectionStateChanged(QAbstractSocket::SocketState)));
|
||||
connect(&m_connection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError)));
|
||||
|
||||
connect(&m_traceClient, SIGNAL(enabled()), this, SLOT(traceClientEnabled()));
|
||||
connect(&m_traceClient, SIGNAL(recordingChanged(bool)), this, SLOT(recordingChanged()));
|
||||
connect(&m_traceClient, SIGNAL(range(int,qint64,qint64,QStringList,QString,int)), &m_eventList, SLOT(addRangedEvent(int,qint64,qint64,QStringList,QString,int)));
|
||||
connect(&m_traceClient, SIGNAL(complete()), this, SLOT(qmlComplete()));
|
||||
connect(&m_qmlProfilerClient, SIGNAL(enabled()), this, SLOT(traceClientEnabled()));
|
||||
connect(&m_qmlProfilerClient, SIGNAL(recordingChanged(bool)), this, SLOT(recordingChanged()));
|
||||
connect(&m_qmlProfilerClient, SIGNAL(range(int,qint64,qint64,QStringList,QString,int)), &m_eventList, SLOT(addRangedEvent(int,qint64,qint64,QStringList,QString,int)));
|
||||
connect(&m_qmlProfilerClient, SIGNAL(complete()), this, SLOT(qmlComplete()));
|
||||
|
||||
connect(&m_v8profilerClient, SIGNAL(enabled()), this, SLOT(profilerClientEnabled()));
|
||||
connect(&m_v8profilerClient, SIGNAL(v8range(int,QString,QString,int,double,double)), &m_eventList, SLOT(addV8Event(int,QString,QString,int,double,double)));
|
||||
connect(&m_v8profilerClient, SIGNAL(v8complete()), this, SLOT(v8complete()));
|
||||
connect(&m_v8profilerClient, SIGNAL(complete()), this, SLOT(v8Complete()));
|
||||
|
||||
connect(&m_eventList, SIGNAL(error(QString)), this, SLOT(logError(QString)));
|
||||
connect(&m_eventList, SIGNAL(dataReady()), this, SLOT(traceFinished()));
|
||||
connect(this, SIGNAL(done()), &m_eventList, SLOT(complete()));
|
||||
}
|
||||
|
||||
QmlProfilerApplication::~QmlProfilerApplication()
|
||||
@@ -143,7 +143,7 @@ bool QmlProfilerApplication::parseArguments()
|
||||
return false;
|
||||
}
|
||||
} else if (arg == QLatin1String("-fromStart")) {
|
||||
m_traceClient.setRecording(true);
|
||||
m_qmlProfilerClient.setRecording(true);
|
||||
m_v8profilerClient.setRecording(true);
|
||||
} else if (arg == QLatin1String("-help") || arg == QLatin1String("-h") || arg == QLatin1String("/h") || arg == QLatin1String("/?")) {
|
||||
return false;
|
||||
@@ -204,7 +204,8 @@ QString QmlProfilerApplication::traceFileName() const
|
||||
} while (QFileInfo(baseName + TraceFileExtension).exists());
|
||||
fileName = baseName + TraceFileExtension;
|
||||
}
|
||||
return fileName;
|
||||
|
||||
return QFileInfo(fileName).absoluteFilePath();
|
||||
}
|
||||
|
||||
void QmlProfilerApplication::userCommand(const QString &command)
|
||||
@@ -216,23 +217,22 @@ void QmlProfilerApplication::userCommand(const QString &command)
|
||||
printCommands();
|
||||
} else if (cmd == Constants::CMD_RECORD
|
||||
|| cmd == Constants::CMD_RECORD2) {
|
||||
m_traceClient.setRecording(!m_traceClient.isRecording());
|
||||
m_qmlProfilerClient.setRecording(!m_qmlProfilerClient.isRecording());
|
||||
m_v8profilerClient.setRecording(!m_v8profilerClient.isRecording());
|
||||
m_qmlDataReady = false;
|
||||
m_v8DataReady = false;
|
||||
} else if (cmd == Constants::CMD_QUIT
|
||||
|| cmd == Constants::CMD_QUIT2) {
|
||||
if (m_traceClient.isRecording()) {
|
||||
print(QLatin1String("Quit"));
|
||||
if (m_qmlProfilerClient.isRecording()) {
|
||||
m_quitAfterSave = true;
|
||||
m_qmlDataReady = false;
|
||||
m_v8DataReady = false;
|
||||
m_traceClient.setRecording(false);
|
||||
m_qmlProfilerClient.setRecording(false);
|
||||
m_v8profilerClient.setRecording(false);
|
||||
} else {
|
||||
quit();
|
||||
}
|
||||
} else {
|
||||
logError(QString("Unknown command '%1'").arg(cmd));
|
||||
printCommands();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,11 +278,13 @@ void QmlProfilerApplication::tryToConnect()
|
||||
void QmlProfilerApplication::connected()
|
||||
{
|
||||
m_connectTimer.stop();
|
||||
if (m_traceClient.isRecording()) {
|
||||
logStatus("Connected. Recording is on.");
|
||||
} else {
|
||||
logStatus("Connected. Recording is off.");
|
||||
}
|
||||
print(QString(QLatin1String("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)));
|
||||
QString recordingStatus(QLatin1String("Recording Status: %1"));
|
||||
if (!m_qmlProfilerClient.isRecording() && !m_v8profilerClient.isRecording())
|
||||
recordingStatus.arg(QLatin1String("Off"));
|
||||
else
|
||||
recordingStatus.arg(QLatin1String("On"));
|
||||
print(recordingStatus);
|
||||
}
|
||||
|
||||
void QmlProfilerApplication::connectionStateChanged(QAbstractSocket::SocketState state)
|
||||
@@ -312,7 +314,7 @@ void QmlProfilerApplication::processFinished()
|
||||
if (m_process->exitStatus() == QProcess::NormalExit) {
|
||||
logStatus(QString("Process exited (%1).").arg(m_process->exitCode()));
|
||||
|
||||
if (m_traceClient.isRecording()) {
|
||||
if (m_qmlProfilerClient.isRecording()) {
|
||||
logError("Process exited while recording, last trace is lost!");
|
||||
exit(2);
|
||||
} else {
|
||||
@@ -326,25 +328,35 @@ void QmlProfilerApplication::processFinished()
|
||||
|
||||
void QmlProfilerApplication::traceClientEnabled()
|
||||
{
|
||||
if (m_verbose)
|
||||
qDebug() << "Trace client is attached.";
|
||||
logStatus("Trace client is attached.");
|
||||
}
|
||||
|
||||
void QmlProfilerApplication::profilerClientEnabled()
|
||||
{
|
||||
if (m_verbose)
|
||||
qDebug() << "Profiler client is attached.";
|
||||
logStatus("Profiler client is attached.");
|
||||
}
|
||||
|
||||
void QmlProfilerApplication::traceFinished()
|
||||
{
|
||||
const QString fileName = traceFileName();
|
||||
print(QString("Saving trace to %1.").arg(fileName));
|
||||
m_eventList.save(fileName);
|
||||
|
||||
if (m_eventList.save(fileName))
|
||||
print(QString("Saving trace to %1.").arg(fileName));
|
||||
|
||||
if (m_quitAfterSave)
|
||||
quit();
|
||||
}
|
||||
|
||||
void QmlProfilerApplication::recordingChanged()
|
||||
{
|
||||
QTextStream err(stderr);
|
||||
if (m_traceClient.isRecording()) {
|
||||
err << "Recording is on." << endl;
|
||||
if (m_qmlProfilerClient.isRecording()) {
|
||||
print(QLatin1String("Recording is on."));
|
||||
} else {
|
||||
err << "Recording is off." << endl;
|
||||
print(QLatin1String("Recording is off."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,12 +384,12 @@ void QmlProfilerApplication::qmlComplete()
|
||||
{
|
||||
m_qmlDataReady = true;
|
||||
if (m_v8profilerClient.status() != QDeclarativeDebugClient::Enabled || m_v8DataReady)
|
||||
emit done();
|
||||
m_eventList.complete();
|
||||
}
|
||||
|
||||
void QmlProfilerApplication::v8Complete()
|
||||
{
|
||||
m_v8DataReady = true;
|
||||
if (m_traceClient.status() != QDeclarativeDebugClient::Enabled || m_qmlDataReady)
|
||||
emit done();
|
||||
if (m_qmlProfilerClient.status() != QDeclarativeDebugClient::Enabled || m_qmlDataReady)
|
||||
m_eventList.complete();
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ public:
|
||||
void printUsage();
|
||||
int exec();
|
||||
|
||||
signals:
|
||||
void done();
|
||||
|
||||
public slots:
|
||||
void userCommand(const QString &command);
|
||||
|
||||
@@ -71,6 +68,7 @@ private slots:
|
||||
void processFinished();
|
||||
|
||||
void traceClientEnabled();
|
||||
void profilerClientEnabled();
|
||||
void traceFinished();
|
||||
void recordingChanged();
|
||||
|
||||
@@ -102,7 +100,7 @@ private:
|
||||
bool m_quitAfterSave;
|
||||
|
||||
QmlJsDebugClient::QDeclarativeDebugConnection m_connection;
|
||||
QmlJsDebugClient::QmlProfilerTraceClient m_traceClient;
|
||||
QmlJsDebugClient::QmlProfilerTraceClient m_qmlProfilerClient;
|
||||
QmlJsDebugClient::QV8ProfilerClient m_v8profilerClient;
|
||||
QmlJsDebugClient::QmlProfilerEventList m_eventList;
|
||||
QTimer m_connectTimer;
|
||||
|
||||
Reference in New Issue
Block a user