2011-06-28 15:51:20 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
2011-07-06 15:48:52 +00:00
|
|
|
** 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.
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-07-06 15:48:52 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-06-28 15:51:20 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-07-06 15:48:52 +00:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2011-06-28 15:51:20 +02:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlprofilertraceclient.h"
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
namespace QmlDebug {
|
2011-08-05 12:58:43 +02:00
|
|
|
|
|
|
|
class QmlProfilerTraceClientPrivate {
|
|
|
|
public:
|
2011-08-24 14:38:54 +02:00
|
|
|
QmlProfilerTraceClientPrivate(QmlProfilerTraceClient *_q)
|
|
|
|
: q(_q)
|
|
|
|
, inProgressRanges(0)
|
2011-08-05 12:58:43 +02:00
|
|
|
, maximumTime(0)
|
|
|
|
, recording(false)
|
|
|
|
{
|
|
|
|
::memset(rangeCount, 0, MaximumQmlEventType * sizeof(int));
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:38:54 +02:00
|
|
|
void sendRecordingStatus();
|
|
|
|
|
|
|
|
QmlProfilerTraceClient *q;
|
2011-08-05 12:58:43 +02:00
|
|
|
qint64 inProgressRanges;
|
|
|
|
QStack<qint64> rangeStartTimes[MaximumQmlEventType];
|
|
|
|
QStack<QStringList> rangeDatas[MaximumQmlEventType];
|
2012-01-12 16:36:40 +01:00
|
|
|
QStack<QmlEventLocation> rangeLocations[MaximumQmlEventType];
|
2012-05-02 17:53:50 +02:00
|
|
|
QStack<BindingType> bindingTypes;
|
2011-08-05 12:58:43 +02:00
|
|
|
int rangeCount[MaximumQmlEventType];
|
|
|
|
qint64 maximumTime;
|
|
|
|
bool recording;
|
|
|
|
};
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
} // namespace QmlDebug
|
2011-08-05 12:58:43 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
using namespace QmlDebug;
|
2011-06-28 15:51:20 +02:00
|
|
|
|
|
|
|
static const int GAP_TIME = 150;
|
|
|
|
|
2011-08-24 14:38:54 +02:00
|
|
|
void QmlProfilerTraceClientPrivate::sendRecordingStatus()
|
|
|
|
{
|
|
|
|
QByteArray ba;
|
|
|
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
|
|
|
stream << recording;
|
|
|
|
q->sendMessage(ba);
|
|
|
|
}
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlProfilerTraceClient::QmlProfilerTraceClient(QmlDebugConnection *client)
|
|
|
|
: QmlDebugClient(QLatin1String("CanvasFrameRate"), client)
|
2011-08-24 14:38:54 +02:00
|
|
|
, d(new QmlProfilerTraceClientPrivate(this))
|
2011-08-05 12:58:43 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerTraceClient::~QmlProfilerTraceClient()
|
|
|
|
{
|
2011-11-15 15:04:25 +01:00
|
|
|
//Disable profiling if started by client
|
|
|
|
//Profiling data will be lost!!
|
|
|
|
if (isRecording())
|
|
|
|
setRecording(false);
|
2011-08-05 12:58:43 +02:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::clearData()
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2011-08-05 12:58:43 +02:00
|
|
|
::memset(d->rangeCount, 0, MaximumQmlEventType * sizeof(int));
|
2012-02-13 15:26:57 +01:00
|
|
|
for (int eventType = 0; eventType < MaximumQmlEventType; eventType++) {
|
|
|
|
d->rangeDatas[eventType].clear();
|
|
|
|
d->rangeLocations[eventType].clear();
|
|
|
|
d->rangeStartTimes[eventType].clear();
|
|
|
|
}
|
2012-05-02 17:53:50 +02:00
|
|
|
d->bindingTypes.clear();
|
2011-08-05 12:58:43 +02:00
|
|
|
emit cleared();
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
2011-11-15 15:04:25 +01:00
|
|
|
void QmlProfilerTraceClient::sendRecordingStatus()
|
|
|
|
{
|
|
|
|
d->sendRecordingStatus();
|
|
|
|
}
|
|
|
|
|
2011-11-10 17:08:07 +01:00
|
|
|
bool QmlProfilerTraceClient::isEnabled() const
|
|
|
|
{
|
|
|
|
return status() == Enabled;
|
|
|
|
}
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
bool QmlProfilerTraceClient::isRecording() const
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2011-08-05 12:58:43 +02:00
|
|
|
return d->recording;
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::setRecording(bool v)
|
|
|
|
{
|
2011-08-05 12:58:43 +02:00
|
|
|
if (v == d->recording)
|
2011-06-28 15:51:20 +02:00
|
|
|
return;
|
|
|
|
|
2011-08-24 14:38:54 +02:00
|
|
|
d->recording = v;
|
|
|
|
|
2011-06-28 15:51:20 +02:00
|
|
|
if (status() == Enabled) {
|
2011-11-15 15:04:25 +01:00
|
|
|
sendRecordingStatus();
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
emit recordingChanged(v);
|
|
|
|
}
|
|
|
|
|
2012-02-13 15:26:57 +01:00
|
|
|
void QmlProfilerTraceClient::setRecordingFromServer(bool v)
|
|
|
|
{
|
|
|
|
if (v == d->recording)
|
|
|
|
return;
|
|
|
|
d->recording = v;
|
|
|
|
emit recordingChanged(v);
|
|
|
|
}
|
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
void QmlProfilerTraceClient::statusChanged(ClientStatus /*status*/)
|
2011-06-28 15:51:20 +02:00
|
|
|
{
|
2011-11-28 16:30:30 +01:00
|
|
|
emit enabledChanged();
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceClient::messageReceived(const QByteArray &data)
|
|
|
|
{
|
|
|
|
QByteArray rwData = data;
|
|
|
|
QDataStream stream(&rwData, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
qint64 time;
|
|
|
|
int messageType;
|
|
|
|
|
|
|
|
stream >> time >> messageType;
|
|
|
|
|
|
|
|
if (messageType >= MaximumMessage)
|
|
|
|
return;
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
if (time > (d->maximumTime + GAP_TIME) && 0 == d->inProgressRanges)
|
2011-06-28 15:51:20 +02:00
|
|
|
emit gap(time);
|
|
|
|
|
|
|
|
if (messageType == Event) {
|
|
|
|
int event;
|
|
|
|
stream >> event;
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
// stop with the first data
|
|
|
|
if (d->recording && event != StartTrace)
|
|
|
|
setRecordingFromServer(false);
|
|
|
|
else if ((!d->recording) && event == StartTrace)
|
|
|
|
setRecordingFromServer(true);
|
|
|
|
|
2011-09-22 16:58:59 +02:00
|
|
|
if (event == EndTrace) {
|
|
|
|
emit this->traceFinished(time);
|
|
|
|
d->maximumTime = time;
|
2011-12-14 16:44:33 +01:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
|
|
|
} else if (event == AnimationFrame) {
|
|
|
|
int frameRate, animationCount;
|
|
|
|
stream >> frameRate >> animationCount;
|
|
|
|
emit this->frame(time, frameRate, animationCount);
|
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2011-11-02 16:57:31 +01:00
|
|
|
} else if (event == StartTrace) {
|
|
|
|
emit this->traceStarted(time);
|
|
|
|
d->maximumTime = time;
|
2011-09-22 16:58:59 +02:00
|
|
|
} else if (event < MaximumEventType) {
|
2011-06-28 15:51:20 +02:00
|
|
|
emit this->event((EventType)event, time);
|
2011-08-05 12:58:43 +02:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
} else if (messageType == Complete) {
|
|
|
|
emit complete();
|
|
|
|
} else {
|
|
|
|
int range;
|
|
|
|
stream >> range;
|
|
|
|
|
2011-06-29 15:05:45 +02:00
|
|
|
if (range >= MaximumQmlEventType)
|
2011-06-28 15:51:20 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (messageType == RangeStart) {
|
2011-08-05 12:58:43 +02:00
|
|
|
d->rangeStartTimes[range].push(time);
|
|
|
|
d->inProgressRanges |= (static_cast<qint64>(1) << range);
|
|
|
|
++d->rangeCount[range];
|
2012-05-02 17:53:50 +02:00
|
|
|
|
|
|
|
// read binding type
|
|
|
|
if ((QmlEventType)range == Binding) {
|
|
|
|
int bindingType = (int)QmlBinding;
|
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> bindingType;
|
|
|
|
d->bindingTypes.push((BindingType)bindingType);
|
|
|
|
}
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
// stop with the first data
|
|
|
|
if (d->recording)
|
|
|
|
setRecordingFromServer(false);
|
2011-06-28 15:51:20 +02:00
|
|
|
} else if (messageType == RangeData) {
|
|
|
|
QString data;
|
|
|
|
stream >> data;
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
int count = d->rangeCount[range];
|
2011-06-28 15:51:20 +02:00
|
|
|
if (count > 0) {
|
2011-08-05 12:58:43 +02:00
|
|
|
while (d->rangeDatas[range].count() < count)
|
|
|
|
d->rangeDatas[range].push(QStringList());
|
|
|
|
d->rangeDatas[range][count-1] << data;
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (messageType == RangeLocation) {
|
|
|
|
QString fileName;
|
|
|
|
int line;
|
2012-01-12 16:36:40 +01:00
|
|
|
int column = -1;
|
2011-06-28 15:51:20 +02:00
|
|
|
stream >> fileName >> line;
|
|
|
|
|
2012-01-12 16:36:40 +01:00
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> column;
|
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
if (d->rangeCount[range] > 0) {
|
2012-01-12 16:36:40 +01:00
|
|
|
d->rangeLocations[range].push(QmlEventLocation(fileName, line, column));
|
2011-06-28 15:51:20 +02:00
|
|
|
}
|
|
|
|
} else {
|
2011-08-05 12:58:43 +02:00
|
|
|
if (d->rangeCount[range] > 0) {
|
|
|
|
--d->rangeCount[range];
|
|
|
|
if (d->inProgressRanges & (static_cast<qint64>(1) << range))
|
|
|
|
d->inProgressRanges &= ~(static_cast<qint64>(1) << range);
|
2011-06-28 15:51:20 +02:00
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
|
|
|
QStringList data = d->rangeDatas[range].count() ? d->rangeDatas[range].pop() : QStringList();
|
2012-01-12 16:36:40 +01:00
|
|
|
QmlEventLocation location = d->rangeLocations[range].count() ? d->rangeLocations[range].pop() : QmlEventLocation();
|
2011-06-28 15:51:20 +02:00
|
|
|
|
2011-08-05 12:58:43 +02:00
|
|
|
qint64 startTime = d->rangeStartTimes[range].pop();
|
2012-05-02 17:53:50 +02:00
|
|
|
BindingType bindingType = QmlBinding;
|
|
|
|
if ((QmlEventType)range == Binding)
|
|
|
|
bindingType = d->bindingTypes.pop();
|
|
|
|
emit this->range((QmlEventType)range, bindingType, startTime, time - startTime, data, location);
|
2011-08-05 12:58:43 +02:00
|
|
|
if (d->rangeCount[range] == 0) {
|
|
|
|
int count = d->rangeDatas[range].count() +
|
|
|
|
d->rangeStartTimes[range].count() +
|
|
|
|
d->rangeLocations[range].count();
|
2011-06-28 15:51:20 +02:00
|
|
|
if (count != 0)
|
|
|
|
qWarning() << "incorrectly nested data";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|