2012-02-09 16:04:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-09-20 05:21:40 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
2014-08-22 06:13:59 +00:00
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
2012-09-20 05:21:40 +00:00
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
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-02-09 16:04:43 +00:00
|
|
|
**
|
2012-09-20 05:21:40 +00:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
2014-08-22 06:13:59 +00:00
|
|
|
** rights. These rights are described in the Digia Qt 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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
#include "qmlprofilerclient.h"
|
2012-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
#include <QtCore/QStack>
|
|
|
|
#include <QtCore/QStringList>
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
ProfilerClient::ProfilerClient(const QString &clientName,
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection *client)
|
|
|
|
: QQmlDebugClient(clientName, client),
|
2012-02-09 16:04:43 +00:00
|
|
|
m_recording(false),
|
|
|
|
m_enabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
ProfilerClient::~ProfilerClient()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
//Disable profiling if started by client
|
|
|
|
//Profiling data will be lost!!
|
|
|
|
if (isRecording())
|
|
|
|
setRecording(false);
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void ProfilerClient::clearData()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
emit cleared();
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
bool ProfilerClient::isEnabled() const
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
return m_enabled;
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void ProfilerClient::sendRecordingStatus()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
bool ProfilerClient::isRecording() const
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
return m_recording;
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void ProfilerClient::setRecording(bool v)
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
if (v == m_recording)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_recording = v;
|
|
|
|
|
|
|
|
if (state() == Enabled) {
|
|
|
|
sendRecordingStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit recordingChanged(v);
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void ProfilerClient::stateChanged(State status)
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
if ((m_enabled && status != Enabled) ||
|
|
|
|
(!m_enabled && status == Enabled))
|
|
|
|
emit enabledChanged();
|
|
|
|
|
|
|
|
m_enabled = status == Enabled;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
class QmlProfilerClientPrivate
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-03-08 15:50:14 +00:00
|
|
|
QmlProfilerClientPrivate()
|
2012-02-09 16:04:43 +00:00
|
|
|
: inProgressRanges(0)
|
|
|
|
, maximumTime(0)
|
|
|
|
{
|
|
|
|
::memset(rangeCount, 0,
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlProfilerService::MaximumRangeType * sizeof(int));
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 inProgressRanges;
|
2012-02-16 04:43:03 +00:00
|
|
|
QStack<qint64> rangeStartTimes[QQmlProfilerService::MaximumRangeType];
|
|
|
|
QStack<QStringList> rangeDatas[QQmlProfilerService::MaximumRangeType];
|
2012-03-08 15:50:14 +00:00
|
|
|
QStack<QmlEventLocation> rangeLocations[QQmlProfilerService::MaximumRangeType];
|
2012-05-02 15:32:57 +00:00
|
|
|
QStack<QQmlProfilerService::BindingType> bindingTypes;
|
2012-02-16 04:43:03 +00:00
|
|
|
int rangeCount[QQmlProfilerService::MaximumRangeType];
|
2012-02-09 16:04:43 +00:00
|
|
|
qint64 maximumTime;
|
|
|
|
};
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
QmlProfilerClient::QmlProfilerClient(
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection *client)
|
2012-03-08 15:50:14 +00:00
|
|
|
: ProfilerClient(QStringLiteral("CanvasFrameRate"), client),
|
|
|
|
d(new QmlProfilerClientPrivate)
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
QmlProfilerClient::~QmlProfilerClient()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void QmlProfilerClient::clearData()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
::memset(d->rangeCount, 0,
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlProfilerService::MaximumRangeType * sizeof(int));
|
2012-05-02 15:32:57 +00:00
|
|
|
d->bindingTypes.clear();
|
2012-03-08 15:50:14 +00:00
|
|
|
ProfilerClient::clearData();
|
2012-02-09 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void QmlProfilerClient::sendRecordingStatus()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
QByteArray ba;
|
|
|
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
|
|
|
stream << isRecording();
|
|
|
|
sendMessage(ba);
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void QmlProfilerClient::messageReceived(const QByteArray &data)
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
QByteArray rwData = data;
|
|
|
|
QDataStream stream(&rwData, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
qint64 time;
|
|
|
|
int messageType;
|
|
|
|
|
|
|
|
stream >> time >> messageType;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
if (messageType >= QQmlProfilerService::MaximumMessage)
|
2012-02-09 16:04:43 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
if (messageType == QQmlProfilerService::Event) {
|
2012-02-09 16:04:43 +00:00
|
|
|
int event;
|
|
|
|
stream >> event;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
if (event == QQmlProfilerService::EndTrace) {
|
2012-02-09 16:04:43 +00:00
|
|
|
emit this->traceFinished(time);
|
|
|
|
d->maximumTime = time;
|
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2012-02-16 04:43:03 +00:00
|
|
|
} else if (event == QQmlProfilerService::AnimationFrame) {
|
2012-02-09 16:04:43 +00:00
|
|
|
int frameRate, animationCount;
|
2014-03-17 13:52:01 +00:00
|
|
|
int threadId = 0;
|
2012-02-09 16:04:43 +00:00
|
|
|
stream >> frameRate >> animationCount;
|
2014-03-17 13:52:01 +00:00
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> threadId;
|
|
|
|
emit this->frame(time, frameRate, animationCount, threadId);
|
2012-02-09 16:04:43 +00:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2012-02-16 04:43:03 +00:00
|
|
|
} else if (event == QQmlProfilerService::StartTrace) {
|
2012-02-09 16:04:43 +00:00
|
|
|
emit this->traceStarted(time);
|
|
|
|
d->maximumTime = time;
|
2012-02-16 04:43:03 +00:00
|
|
|
} else if (event < QQmlProfilerService::MaximumEventType) {
|
2012-02-09 16:04:43 +00:00
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
|
|
|
}
|
2012-02-16 04:43:03 +00:00
|
|
|
} else if (messageType == QQmlProfilerService::Complete) {
|
2012-02-09 16:04:43 +00:00
|
|
|
emit complete();
|
2014-02-19 17:11:41 +00:00
|
|
|
} else if (messageType == QQmlProfilerService::SceneGraphFrame) {
|
|
|
|
int sgEventType;
|
|
|
|
int count = 0;
|
|
|
|
qint64 params[5];
|
|
|
|
|
|
|
|
stream >> sgEventType;
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
stream >> params[count++];
|
|
|
|
}
|
|
|
|
while (count<5)
|
|
|
|
params[count++] = 0;
|
|
|
|
emit sceneGraphFrame((QQmlProfilerService::SceneGraphFrameType)sgEventType, time,
|
|
|
|
params[0], params[1], params[2], params[3], params[4]);
|
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
|
|
|
} else if (messageType == QQmlProfilerService::PixmapCacheEvent) {
|
|
|
|
int pixEvTy, width = 0, height = 0, refcount = 0;
|
|
|
|
QString pixUrl;
|
|
|
|
stream >> pixEvTy >> pixUrl;
|
|
|
|
if (pixEvTy == (int)QQmlProfilerService::PixmapReferenceCountChanged ||
|
|
|
|
pixEvTy == (int)QQmlProfilerService::PixmapCacheCountChanged) {
|
|
|
|
stream >> refcount;
|
|
|
|
} else if (pixEvTy == (int)QQmlProfilerService::PixmapSizeKnown) {
|
|
|
|
stream >> width >> height;
|
|
|
|
refcount = 1;
|
|
|
|
}
|
|
|
|
emit pixmapCache((QQmlProfilerService::PixmapEventType)pixEvTy, time,
|
|
|
|
QmlEventLocation(pixUrl,0,0), width, height, refcount);
|
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2014-06-16 11:33:33 +00:00
|
|
|
} else if (messageType == QQmlProfilerService::MemoryAllocation) {
|
|
|
|
int type;
|
|
|
|
qint64 delta;
|
|
|
|
stream >> type >> delta;
|
|
|
|
emit memoryAllocation((QQmlProfilerService::MemoryType)type, time, delta);
|
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
2012-02-09 16:04:43 +00:00
|
|
|
} else {
|
|
|
|
int range;
|
|
|
|
stream >> range;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
if (range >= QQmlProfilerService::MaximumRangeType)
|
2012-02-09 16:04:43 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
if (messageType == QQmlProfilerService::RangeStart) {
|
2012-02-09 16:04:43 +00:00
|
|
|
d->rangeStartTimes[range].push(time);
|
|
|
|
d->inProgressRanges |= (static_cast<qint64>(1) << range);
|
|
|
|
++d->rangeCount[range];
|
2012-05-02 15:32:57 +00:00
|
|
|
|
|
|
|
// read binding type
|
|
|
|
if (range == (int)QQmlProfilerService::Binding) {
|
|
|
|
int bindingType = (int)QQmlProfilerService::QmlBinding;
|
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> bindingType;
|
|
|
|
d->bindingTypes.push((QQmlProfilerService::BindingType)bindingType);
|
|
|
|
}
|
2012-02-16 04:43:03 +00:00
|
|
|
} else if (messageType == QQmlProfilerService::RangeData) {
|
2012-02-09 16:04:43 +00:00
|
|
|
QString data;
|
|
|
|
stream >> data;
|
|
|
|
|
|
|
|
int count = d->rangeCount[range];
|
|
|
|
if (count > 0) {
|
|
|
|
while (d->rangeDatas[range].count() < count)
|
|
|
|
d->rangeDatas[range].push(QStringList());
|
|
|
|
d->rangeDatas[range][count-1] << data;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
} else if (messageType == QQmlProfilerService::RangeLocation) {
|
2012-02-09 16:04:43 +00:00
|
|
|
QString fileName;
|
|
|
|
int line;
|
|
|
|
int column = -1;
|
|
|
|
stream >> fileName >> line;
|
|
|
|
|
|
|
|
if (!stream.atEnd())
|
|
|
|
stream >> column;
|
|
|
|
|
|
|
|
if (d->rangeCount[range] > 0) {
|
2012-03-08 15:50:14 +00:00
|
|
|
d->rangeLocations[range].push(QmlEventLocation(fileName, line,
|
2012-02-09 16:04:43 +00:00
|
|
|
column));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (d->rangeCount[range] > 0) {
|
|
|
|
--d->rangeCount[range];
|
|
|
|
if (d->inProgressRanges & (static_cast<qint64>(1) << range))
|
|
|
|
d->inProgressRanges &= ~(static_cast<qint64>(1) << range);
|
|
|
|
|
|
|
|
d->maximumTime = qMax(time, d->maximumTime);
|
|
|
|
QStringList data = d->rangeDatas[range].count() ?
|
|
|
|
d->rangeDatas[range].pop() : QStringList();
|
2012-03-08 15:50:14 +00:00
|
|
|
QmlEventLocation location = d->rangeLocations[range].count() ?
|
|
|
|
d->rangeLocations[range].pop() : QmlEventLocation();
|
2012-02-09 16:04:43 +00:00
|
|
|
|
|
|
|
qint64 startTime = d->rangeStartTimes[range].pop();
|
2012-05-02 15:32:57 +00:00
|
|
|
QQmlProfilerService::BindingType bindingType = QQmlProfilerService::QmlBinding;
|
|
|
|
if (range == (int)QQmlProfilerService::Binding)
|
|
|
|
bindingType = d->bindingTypes.pop();
|
2012-02-16 04:43:03 +00:00
|
|
|
emit this->range((QQmlProfilerService::RangeType)range,
|
2012-05-02 15:32:57 +00:00
|
|
|
bindingType, startTime, time - startTime, data, location);
|
2012-02-09 16:04:43 +00:00
|
|
|
if (d->rangeCount[range] == 0) {
|
|
|
|
int count = d->rangeDatas[range].count() +
|
|
|
|
d->rangeStartTimes[range].count() +
|
|
|
|
d->rangeLocations[range].count();
|
|
|
|
if (count != 0)
|
|
|
|
qWarning() << "incorrectly nested data";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
V8ProfilerClient::V8ProfilerClient(QQmlDebugConnection *client)
|
|
|
|
: ProfilerClient(QStringLiteral("V8Profiler"), client)
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
V8ProfilerClient::~V8ProfilerClient()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void V8ProfilerClient::sendRecordingStatus()
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
QByteArray ba;
|
|
|
|
QDataStream stream(&ba, QIODevice::WriteOnly);
|
|
|
|
QByteArray cmd("V8PROFILER");
|
|
|
|
QByteArray option("");
|
|
|
|
QByteArray title("");
|
|
|
|
|
|
|
|
if (m_recording) {
|
|
|
|
option = "start";
|
|
|
|
} else {
|
|
|
|
option = "stop";
|
|
|
|
}
|
|
|
|
stream << cmd << option << title;
|
|
|
|
sendMessage(ba);
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void V8ProfilerClient::messageReceived(const QByteArray &data)
|
2012-02-09 16:04:43 +00:00
|
|
|
{
|
|
|
|
QByteArray rwData = data;
|
|
|
|
QDataStream stream(&rwData, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
int messageType;
|
|
|
|
|
|
|
|
stream >> messageType;
|
|
|
|
|
|
|
|
if (messageType == V8Complete) {
|
|
|
|
emit complete();
|
|
|
|
} else if (messageType == V8Entry) {
|
|
|
|
QString filename;
|
|
|
|
QString function;
|
|
|
|
int lineNumber;
|
|
|
|
double totalTime;
|
|
|
|
double selfTime;
|
|
|
|
int depth;
|
|
|
|
|
|
|
|
stream >> filename >> function >> lineNumber >> totalTime >>
|
|
|
|
selfTime >> depth;
|
|
|
|
emit this->range(depth, function, filename, lineNumber, totalTime,
|
|
|
|
selfTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|