2012-03-08 15:50:14 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-03-08 15:50:14 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
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
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-03-08 15:50:14 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlprofilerdata.h"
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
|
2015-07-28 13:58:07 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2014-02-19 17:11:41 +00:00
|
|
|
const char PROFILER_FILE_VERSION[] = "1.02";
|
|
|
|
|
|
|
|
static const char *RANGE_TYPE_STRINGS[] = {
|
|
|
|
"Painting",
|
|
|
|
"Compiling",
|
|
|
|
"Creating",
|
|
|
|
"Binding",
|
|
|
|
"HandlingSignal",
|
|
|
|
"Javascript"
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_STATIC_ASSERT(sizeof(RANGE_TYPE_STRINGS) ==
|
|
|
|
QQmlProfilerDefinitions::MaximumRangeType * sizeof(const char *));
|
|
|
|
|
|
|
|
static const char *MESSAGE_STRINGS[] = {
|
|
|
|
"Event",
|
|
|
|
"RangeStart",
|
|
|
|
"RangeData",
|
|
|
|
"RangeLocation",
|
|
|
|
"RangeEnd",
|
|
|
|
"Complete",
|
|
|
|
"PixmapCache",
|
2014-06-02 16:33:19 +00:00
|
|
|
"SceneGraph",
|
|
|
|
"MemoryAllocation"
|
2014-02-19 17:11:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_STATIC_ASSERT(sizeof(MESSAGE_STRINGS) ==
|
|
|
|
QQmlProfilerDefinitions::MaximumMessage * sizeof(const char *));
|
2012-03-08 15:50:14 +00:00
|
|
|
|
|
|
|
struct QmlRangeEventData {
|
|
|
|
QmlRangeEventData() {} // never called
|
2014-02-19 17:11:41 +00:00
|
|
|
QmlRangeEventData(const QString &_displayName, int _detailType, const QString &_eventHashStr,
|
2015-09-17 11:39:00 +00:00
|
|
|
const QQmlEventLocation &_location, const QString &_details,
|
2015-07-08 14:03:51 +00:00
|
|
|
QQmlProfilerDefinitions::Message _message,
|
|
|
|
QQmlProfilerDefinitions::RangeType _rangeType)
|
2014-02-19 17:11:41 +00:00
|
|
|
: displayName(_displayName), eventHashStr(_eventHashStr), location(_location),
|
|
|
|
details(_details), message(_message), rangeType(_rangeType), detailType(_detailType) {}
|
2012-03-08 15:50:14 +00:00
|
|
|
QString displayName;
|
|
|
|
QString eventHashStr;
|
2015-09-17 11:39:00 +00:00
|
|
|
QQmlEventLocation location;
|
2012-03-08 15:50:14 +00:00
|
|
|
QString details;
|
2015-07-08 14:03:51 +00:00
|
|
|
QQmlProfilerDefinitions::Message message;
|
|
|
|
QQmlProfilerDefinitions::RangeType rangeType;
|
2014-02-19 17:11:41 +00:00
|
|
|
int detailType; // can be BindingType, PixmapCacheEventType or SceneGraphFrameType
|
2012-03-08 15:50:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct QmlRangeEventStartInstance {
|
|
|
|
QmlRangeEventStartInstance() {} // never called
|
|
|
|
QmlRangeEventStartInstance(qint64 _startTime, qint64 _duration, int _frameRate,
|
2014-03-17 13:52:01 +00:00
|
|
|
int _animationCount, int _threadId, QmlRangeEventData *_data)
|
2012-03-08 15:50:14 +00:00
|
|
|
: startTime(_startTime), duration(_duration), frameRate(_frameRate),
|
2014-02-19 17:11:41 +00:00
|
|
|
animationCount(_animationCount), threadId(_threadId), numericData4(-1), numericData5(-1),
|
|
|
|
data(_data)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
QmlRangeEventStartInstance(qint64 _startTime, qint64 _numericData1, qint64 _numericData2,
|
|
|
|
qint64 _numericData3, qint64 _numericData4, qint64 _numericData5,
|
|
|
|
QmlRangeEventData *_data)
|
|
|
|
: startTime(_startTime), duration(-1), numericData1(_numericData1),
|
|
|
|
numericData2(_numericData2), numericData3(_numericData3), numericData4(_numericData4),
|
|
|
|
numericData5(_numericData5), data(_data)
|
2012-03-08 15:50:14 +00:00
|
|
|
{ }
|
|
|
|
qint64 startTime;
|
|
|
|
qint64 duration;
|
2014-02-19 17:11:41 +00:00
|
|
|
union {
|
|
|
|
int frameRate;
|
2015-09-17 11:34:38 +00:00
|
|
|
int inputType;
|
2014-02-19 17:11:41 +00:00
|
|
|
qint64 numericData1;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
int animationCount;
|
2015-09-17 11:34:38 +00:00
|
|
|
int inputA;
|
2014-02-19 17:11:41 +00:00
|
|
|
qint64 numericData2;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
int threadId;
|
2015-09-17 11:34:38 +00:00
|
|
|
int inputB;
|
2014-02-19 17:11:41 +00:00
|
|
|
qint64 numericData3;
|
|
|
|
};
|
|
|
|
qint64 numericData4;
|
|
|
|
qint64 numericData5;
|
2012-03-08 15:50:14 +00:00
|
|
|
QmlRangeEventData *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
Q_DECLARE_TYPEINFO(QmlRangeEventData, Q_MOVABLE_TYPE);
|
|
|
|
Q_DECLARE_TYPEINFO(QmlRangeEventStartInstance, Q_MOVABLE_TYPE);
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
class QmlProfilerDataPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmlProfilerDataPrivate(QmlProfilerData *qq){ Q_UNUSED(qq); }
|
|
|
|
|
|
|
|
// data storage
|
|
|
|
QHash<QString, QmlRangeEventData *> eventDescriptions;
|
|
|
|
QVector<QmlRangeEventStartInstance> startInstanceList;
|
|
|
|
|
|
|
|
qint64 traceStartTime;
|
|
|
|
qint64 traceEndTime;
|
|
|
|
|
|
|
|
// internal state while collecting events
|
|
|
|
qint64 qmlMeasuredTime;
|
|
|
|
QmlProfilerData::State state;
|
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
QmlProfilerData::QmlProfilerData(QObject *parent) :
|
|
|
|
QObject(parent),d(new QmlProfilerDataPrivate(this))
|
|
|
|
{
|
|
|
|
d->state = Empty;
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerData::~QmlProfilerData()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::clear()
|
|
|
|
{
|
2015-06-19 16:57:54 +00:00
|
|
|
qDeleteAll(d->eventDescriptions);
|
2012-03-08 15:50:14 +00:00
|
|
|
d->eventDescriptions.clear();
|
|
|
|
d->startInstanceList.clear();
|
|
|
|
|
2015-05-20 09:35:04 +00:00
|
|
|
d->traceEndTime = std::numeric_limits<qint64>::min();
|
|
|
|
d->traceStartTime = std::numeric_limits<qint64>::max();
|
2012-03-08 15:50:14 +00:00
|
|
|
d->qmlMeasuredTime = 0;
|
|
|
|
|
|
|
|
setState(Empty);
|
|
|
|
}
|
|
|
|
|
2015-09-17 11:39:00 +00:00
|
|
|
QString QmlProfilerData::getHashStringForQmlEvent(const QQmlEventLocation &location, int eventType)
|
2012-03-08 15:50:14 +00:00
|
|
|
{
|
|
|
|
return QString(QStringLiteral("%1:%2:%3:%4")).arg(
|
|
|
|
location.filename,
|
|
|
|
QString::number(location.line),
|
|
|
|
QString::number(location.column),
|
|
|
|
QString::number(eventType));
|
|
|
|
}
|
|
|
|
|
2015-07-08 14:03:51 +00:00
|
|
|
QString QmlProfilerData::qmlRangeTypeAsString(QQmlProfilerDefinitions::RangeType type)
|
2012-03-08 15:50:14 +00:00
|
|
|
{
|
2015-10-23 15:03:14 +00:00
|
|
|
if (type * sizeof(char *) < sizeof(RANGE_TYPE_STRINGS))
|
2014-02-19 17:11:41 +00:00
|
|
|
return QLatin1String(RANGE_TYPE_STRINGS[type]);
|
|
|
|
else
|
|
|
|
return QString::number(type);
|
|
|
|
}
|
|
|
|
|
2015-07-08 14:03:51 +00:00
|
|
|
QString QmlProfilerData::qmlMessageAsString(QQmlProfilerDefinitions::Message type)
|
2014-02-19 17:11:41 +00:00
|
|
|
{
|
2015-10-23 15:03:14 +00:00
|
|
|
if (type * sizeof(char *) < sizeof(MESSAGE_STRINGS))
|
2014-02-19 17:11:41 +00:00
|
|
|
return QLatin1String(MESSAGE_STRINGS[type]);
|
|
|
|
else
|
|
|
|
return QString::number(type);
|
2012-03-08 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::setTraceStartTime(qint64 time)
|
|
|
|
{
|
2015-05-20 09:35:04 +00:00
|
|
|
if (time < d->traceStartTime)
|
|
|
|
d->traceStartTime = time;
|
2012-03-08 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::setTraceEndTime(qint64 time)
|
|
|
|
{
|
2015-05-20 09:35:04 +00:00
|
|
|
if (time > d->traceEndTime)
|
|
|
|
d->traceEndTime = time;
|
2012-03-08 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerData::traceStartTime() const
|
|
|
|
{
|
|
|
|
return d->traceStartTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerData::traceEndTime() const
|
|
|
|
{
|
|
|
|
return d->traceEndTime;
|
|
|
|
}
|
|
|
|
|
2015-07-08 14:03:51 +00:00
|
|
|
void QmlProfilerData::addQmlEvent(QQmlProfilerDefinitions::RangeType type,
|
|
|
|
QQmlProfilerDefinitions::BindingType bindingType,
|
2012-03-08 15:50:14 +00:00
|
|
|
qint64 startTime,
|
|
|
|
qint64 duration,
|
|
|
|
const QStringList &data,
|
2015-09-17 11:39:00 +00:00
|
|
|
const QQmlEventLocation &location)
|
2012-03-08 15:50:14 +00:00
|
|
|
{
|
|
|
|
setState(AcquiringData);
|
|
|
|
|
|
|
|
QString details;
|
|
|
|
// generate details string
|
2015-11-02 15:06:12 +00:00
|
|
|
if (!data.isEmpty()) {
|
2015-10-13 10:26:45 +00:00
|
|
|
details = data.join(QLatin1Char(' ')).replace(
|
|
|
|
QLatin1Char('\n'), QLatin1Char(' ')).simplified();
|
2012-03-08 15:50:14 +00:00
|
|
|
QRegExp rewrite(QStringLiteral("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)"));
|
|
|
|
bool match = rewrite.exactMatch(details);
|
|
|
|
if (match) {
|
|
|
|
details = rewrite.cap(1) +QLatin1String(": ") + rewrite.cap(3);
|
|
|
|
}
|
|
|
|
if (details.startsWith(QLatin1String("file://")))
|
|
|
|
details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1);
|
|
|
|
}
|
|
|
|
|
2015-09-17 11:39:00 +00:00
|
|
|
QQmlEventLocation eventLocation = location;
|
2012-03-08 15:50:14 +00:00
|
|
|
QString displayName, eventHashStr;
|
|
|
|
// generate hash
|
|
|
|
if (eventLocation.filename.isEmpty()) {
|
|
|
|
displayName = tr("<bytecode>");
|
|
|
|
eventHashStr = getHashStringForQmlEvent(eventLocation, type);
|
|
|
|
} else {
|
|
|
|
const QString filePath = QUrl(eventLocation.filename).path();
|
2016-06-08 12:12:08 +00:00
|
|
|
displayName = filePath.midRef(
|
2012-03-08 15:50:14 +00:00
|
|
|
filePath.lastIndexOf(QLatin1Char('/')) + 1) +
|
|
|
|
QLatin1Char(':') + QString::number(eventLocation.line);
|
|
|
|
eventHashStr = getHashStringForQmlEvent(eventLocation, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRangeEventData *newEvent;
|
|
|
|
if (d->eventDescriptions.contains(eventHashStr)) {
|
|
|
|
newEvent = d->eventDescriptions[eventHashStr];
|
|
|
|
} else {
|
2014-02-19 17:11:41 +00:00
|
|
|
newEvent = new QmlRangeEventData(displayName, bindingType, eventHashStr, location, details,
|
2015-07-08 14:03:51 +00:00
|
|
|
QQmlProfilerDefinitions::MaximumMessage, type);
|
2012-03-08 15:50:14 +00:00
|
|
|
d->eventDescriptions.insert(eventHashStr, newEvent);
|
|
|
|
}
|
|
|
|
|
2014-03-17 13:52:01 +00:00
|
|
|
QmlRangeEventStartInstance rangeEventStartInstance(startTime, duration, -1, -1, -1, newEvent);
|
2012-03-08 15:50:14 +00:00
|
|
|
|
|
|
|
d->startInstanceList.append(rangeEventStartInstance);
|
|
|
|
}
|
|
|
|
|
2014-03-17 13:52:01 +00:00
|
|
|
void QmlProfilerData::addFrameEvent(qint64 time, int framerate, int animationcount, int threadId)
|
2012-03-08 15:50:14 +00:00
|
|
|
{
|
|
|
|
setState(AcquiringData);
|
|
|
|
|
|
|
|
QString details = tr("Animation Timer Update");
|
|
|
|
QString displayName = tr("<Animation Update>");
|
|
|
|
QString eventHashStr = displayName;
|
|
|
|
|
|
|
|
QmlRangeEventData *newEvent;
|
|
|
|
if (d->eventDescriptions.contains(eventHashStr)) {
|
|
|
|
newEvent = d->eventDescriptions[eventHashStr];
|
|
|
|
} else {
|
2015-07-08 14:03:51 +00:00
|
|
|
newEvent = new QmlRangeEventData(displayName, QQmlProfilerDefinitions::AnimationFrame,
|
2014-02-19 17:11:41 +00:00
|
|
|
eventHashStr,
|
2015-09-17 11:39:00 +00:00
|
|
|
QQmlEventLocation(), details,
|
2015-07-08 14:03:51 +00:00
|
|
|
QQmlProfilerDefinitions::Event,
|
|
|
|
QQmlProfilerDefinitions::MaximumRangeType);
|
2012-03-08 15:50:14 +00:00
|
|
|
d->eventDescriptions.insert(eventHashStr, newEvent);
|
|
|
|
}
|
|
|
|
|
2014-03-17 13:52:01 +00:00
|
|
|
QmlRangeEventStartInstance rangeEventStartInstance(time, -1, framerate, animationcount,
|
|
|
|
threadId, newEvent);
|
2012-03-08 15:50:14 +00:00
|
|
|
|
|
|
|
d->startInstanceList.append(rangeEventStartInstance);
|
|
|
|
}
|
|
|
|
|
2015-07-08 14:03:51 +00:00
|
|
|
void QmlProfilerData::addSceneGraphFrameEvent(QQmlProfilerDefinitions::SceneGraphFrameType type,
|
|
|
|
qint64 time, qint64 numericData1, qint64 numericData2,
|
|
|
|
qint64 numericData3, qint64 numericData4,
|
|
|
|
qint64 numericData5)
|
2014-02-19 17:11:41 +00:00
|
|
|
{
|
|
|
|
setState(AcquiringData);
|
|
|
|
|
|
|
|
QString eventHashStr = QString::fromLatin1("SceneGraph:%1").arg(type);
|
|
|
|
QmlRangeEventData *newEvent;
|
|
|
|
if (d->eventDescriptions.contains(eventHashStr)) {
|
|
|
|
newEvent = d->eventDescriptions[eventHashStr];
|
|
|
|
} else {
|
|
|
|
newEvent = new QmlRangeEventData(QStringLiteral("<SceneGraph>"), type, eventHashStr,
|
2015-09-17 11:39:00 +00:00
|
|
|
QQmlEventLocation(), QString(),
|
2015-07-08 14:03:51 +00:00
|
|
|
QQmlProfilerDefinitions::SceneGraphFrame,
|
|
|
|
QQmlProfilerDefinitions::MaximumRangeType);
|
2014-02-19 17:11:41 +00:00
|
|
|
d->eventDescriptions.insert(eventHashStr, newEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlRangeEventStartInstance rangeEventStartInstance(time, numericData1, numericData2,
|
|
|
|
numericData3, numericData4, numericData5,
|
|
|
|
newEvent);
|
|
|
|
d->startInstanceList.append(rangeEventStartInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type,
|
2015-09-17 11:39:00 +00:00
|
|
|
qint64 time, const QString &location,
|
|
|
|
int numericData1, int numericData2)
|
2014-02-19 17:11:41 +00:00
|
|
|
{
|
|
|
|
setState(AcquiringData);
|
|
|
|
|
2015-09-17 11:39:00 +00:00
|
|
|
QString filePath = QUrl(location).path();
|
2014-02-19 17:11:41 +00:00
|
|
|
|
2016-06-08 12:12:08 +00:00
|
|
|
const QString eventHashStr = filePath.midRef(filePath.lastIndexOf(QLatin1Char('/')) + 1)
|
|
|
|
+ QLatin1Char(':') + QString::number(type);
|
2014-02-19 17:11:41 +00:00
|
|
|
QmlRangeEventData *newEvent;
|
|
|
|
if (d->eventDescriptions.contains(eventHashStr)) {
|
|
|
|
newEvent = d->eventDescriptions[eventHashStr];
|
|
|
|
} else {
|
2015-09-17 11:39:00 +00:00
|
|
|
newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr,
|
|
|
|
QQmlEventLocation(location, -1, -1), QString(),
|
2015-07-08 14:03:51 +00:00
|
|
|
QQmlProfilerDefinitions::PixmapCacheEvent,
|
|
|
|
QQmlProfilerDefinitions::MaximumRangeType);
|
2014-02-19 17:11:41 +00:00
|
|
|
d->eventDescriptions.insert(eventHashStr, newEvent);
|
|
|
|
}
|
|
|
|
|
2015-09-17 11:39:00 +00:00
|
|
|
QmlRangeEventStartInstance rangeEventStartInstance(time, numericData1, numericData2, 0, 0, 0,
|
2014-02-19 17:11:41 +00:00
|
|
|
newEvent);
|
|
|
|
d->startInstanceList.append(rangeEventStartInstance);
|
|
|
|
}
|
|
|
|
|
2015-07-08 14:03:51 +00:00
|
|
|
void QmlProfilerData::addMemoryEvent(QQmlProfilerDefinitions::MemoryType type, qint64 time,
|
2014-06-16 11:33:33 +00:00
|
|
|
qint64 size)
|
|
|
|
{
|
|
|
|
setState(AcquiringData);
|
|
|
|
QString eventHashStr = QString::fromLatin1("MemoryAllocation:%1").arg(type);
|
|
|
|
QmlRangeEventData *newEvent;
|
|
|
|
if (d->eventDescriptions.contains(eventHashStr)) {
|
|
|
|
newEvent = d->eventDescriptions[eventHashStr];
|
|
|
|
} else {
|
2015-09-17 11:39:00 +00:00
|
|
|
newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr, QQmlEventLocation(),
|
2015-07-08 14:03:51 +00:00
|
|
|
QString(), QQmlProfilerDefinitions::MemoryAllocation,
|
|
|
|
QQmlProfilerDefinitions::MaximumRangeType);
|
2014-06-16 11:33:33 +00:00
|
|
|
d->eventDescriptions.insert(eventHashStr, newEvent);
|
|
|
|
}
|
|
|
|
QmlRangeEventStartInstance rangeEventStartInstance(time, size, 0, 0, 0, 0, newEvent);
|
|
|
|
d->startInstanceList.append(rangeEventStartInstance);
|
|
|
|
}
|
|
|
|
|
2015-09-17 11:34:38 +00:00
|
|
|
void QmlProfilerData::addInputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time,
|
|
|
|
int a, int b)
|
2015-05-21 15:48:58 +00:00
|
|
|
{
|
|
|
|
setState(AcquiringData);
|
|
|
|
|
2015-09-17 11:34:38 +00:00
|
|
|
QQmlProfilerDefinitions::EventType eventType;
|
|
|
|
switch (type) {
|
|
|
|
case QQmlProfilerDefinitions::InputKeyPress:
|
|
|
|
case QQmlProfilerDefinitions::InputKeyRelease:
|
|
|
|
case QQmlProfilerDefinitions::InputKeyUnknown:
|
|
|
|
eventType = QQmlProfilerDefinitions::Key;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eventType = QQmlProfilerDefinitions::Mouse;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString eventHashStr = QString::fromLatin1("Input:%1").arg(eventType);
|
2015-05-21 15:48:58 +00:00
|
|
|
|
|
|
|
QmlRangeEventData *newEvent;
|
|
|
|
if (d->eventDescriptions.contains(eventHashStr)) {
|
|
|
|
newEvent = d->eventDescriptions[eventHashStr];
|
|
|
|
} else {
|
2015-09-17 11:39:00 +00:00
|
|
|
newEvent = new QmlRangeEventData(QString(), eventType, eventHashStr, QQmlEventLocation(),
|
2015-07-08 14:03:51 +00:00
|
|
|
QString(), QQmlProfilerDefinitions::Event,
|
|
|
|
QQmlProfilerDefinitions::MaximumRangeType);
|
2015-05-21 15:48:58 +00:00
|
|
|
d->eventDescriptions.insert(eventHashStr, newEvent);
|
|
|
|
}
|
|
|
|
|
2015-09-17 11:34:38 +00:00
|
|
|
d->startInstanceList.append(QmlRangeEventStartInstance(time, -1, type, a, b, newEvent));
|
2015-05-21 15:48:58 +00:00
|
|
|
}
|
|
|
|
|
2012-03-08 15:50:14 +00:00
|
|
|
void QmlProfilerData::computeQmlTime()
|
|
|
|
{
|
|
|
|
// compute levels
|
|
|
|
QHash<int, qint64> endtimesPerLevel;
|
|
|
|
int minimumLevel = 1;
|
|
|
|
int level = minimumLevel;
|
|
|
|
|
|
|
|
for (int i = 0; i < d->startInstanceList.count(); i++) {
|
|
|
|
qint64 st = d->startInstanceList[i].startTime;
|
|
|
|
|
2015-07-08 14:03:51 +00:00
|
|
|
if (d->startInstanceList[i].data->rangeType == QQmlProfilerDefinitions::Painting) {
|
2012-03-08 15:50:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// general level
|
|
|
|
if (endtimesPerLevel[level] > st) {
|
|
|
|
level++;
|
|
|
|
} else {
|
|
|
|
while (level > minimumLevel && endtimesPerLevel[level-1] <= st)
|
|
|
|
level--;
|
|
|
|
}
|
|
|
|
endtimesPerLevel[level] = st + d->startInstanceList[i].duration;
|
|
|
|
|
|
|
|
if (level == minimumLevel) {
|
|
|
|
d->qmlMeasuredTime += d->startInstanceList[i].duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareStartTimes(const QmlRangeEventStartInstance &t1, const QmlRangeEventStartInstance &t2)
|
|
|
|
{
|
|
|
|
return t1.startTime < t2.startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::sortStartTimes()
|
|
|
|
{
|
|
|
|
if (d->startInstanceList.count() < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// assuming startTimes is partially sorted
|
|
|
|
// identify blocks of events and sort them with quicksort
|
|
|
|
QVector<QmlRangeEventStartInstance>::iterator itFrom = d->startInstanceList.end() - 2;
|
|
|
|
QVector<QmlRangeEventStartInstance>::iterator itTo = d->startInstanceList.end() - 1;
|
|
|
|
|
|
|
|
while (itFrom != d->startInstanceList.begin() && itTo != d->startInstanceList.begin()) {
|
|
|
|
// find block to sort
|
|
|
|
while ( itFrom != d->startInstanceList.begin()
|
|
|
|
&& itTo->startTime > itFrom->startTime ) {
|
2015-12-24 08:38:04 +00:00
|
|
|
--itTo;
|
2012-03-08 15:50:14 +00:00
|
|
|
itFrom = itTo - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're at the end of the list
|
|
|
|
if (itFrom == d->startInstanceList.begin())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// find block length
|
|
|
|
while ( itFrom != d->startInstanceList.begin()
|
|
|
|
&& itTo->startTime <= itFrom->startTime )
|
2015-12-24 08:38:04 +00:00
|
|
|
--itFrom;
|
2012-03-08 15:50:14 +00:00
|
|
|
|
|
|
|
if (itTo->startTime <= itFrom->startTime)
|
2013-09-12 09:06:59 +00:00
|
|
|
std::sort(itFrom, itTo + 1, compareStartTimes);
|
2012-03-08 15:50:14 +00:00
|
|
|
else
|
2013-09-12 09:06:59 +00:00
|
|
|
std::sort(itFrom + 1, itTo + 1, compareStartTimes);
|
2012-03-08 15:50:14 +00:00
|
|
|
|
|
|
|
// move to next block
|
|
|
|
itTo = itFrom;
|
|
|
|
itFrom = itTo - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::complete()
|
|
|
|
{
|
|
|
|
setState(ProcessingData);
|
|
|
|
sortStartTimes();
|
|
|
|
computeQmlTime();
|
|
|
|
setState(Done);
|
|
|
|
emit dataReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerData::isEmpty() const
|
|
|
|
{
|
2015-08-28 08:51:06 +00:00
|
|
|
return d->startInstanceList.isEmpty();
|
2012-03-08 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerData::save(const QString &filename)
|
|
|
|
{
|
|
|
|
if (isEmpty()) {
|
|
|
|
emit error(tr("No data to save"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-21 15:13:03 +00:00
|
|
|
QFile file;
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
file.setFileName(filename);
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
|
|
emit error(tr("Could not open %1 for writing").arg(filename));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!file.open(stdout, QIODevice::WriteOnly)) {
|
|
|
|
emit error(tr("Could not open stdout for writing"));
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-08 15:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QXmlStreamWriter stream(&file);
|
|
|
|
stream.setAutoFormatting(true);
|
|
|
|
stream.writeStartDocument();
|
|
|
|
|
|
|
|
stream.writeStartElement(QStringLiteral("trace"));
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("version"), PROFILER_FILE_VERSION);
|
2012-03-08 15:50:14 +00:00
|
|
|
|
|
|
|
stream.writeAttribute(QStringLiteral("traceStart"), QString::number(traceStartTime()));
|
|
|
|
stream.writeAttribute(QStringLiteral("traceEnd"), QString::number(traceEndTime()));
|
|
|
|
|
|
|
|
stream.writeStartElement(QStringLiteral("eventData"));
|
|
|
|
stream.writeAttribute(QStringLiteral("totalTime"), QString::number(d->qmlMeasuredTime));
|
|
|
|
|
2016-01-15 12:23:25 +00:00
|
|
|
const auto eventDescriptionsKeys = d->eventDescriptions.keys();
|
|
|
|
for (auto it = d->eventDescriptions.cbegin(), end = d->eventDescriptions.cend();
|
|
|
|
it != end; ++it) {
|
|
|
|
const QmlRangeEventData *eventData = it.value();
|
2012-03-08 15:50:14 +00:00
|
|
|
stream.writeStartElement(QStringLiteral("event"));
|
2015-07-08 14:03:51 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("index"), QString::number(
|
2016-01-15 12:23:25 +00:00
|
|
|
eventDescriptionsKeys.indexOf(eventData->eventHashStr)));
|
2015-05-26 09:12:09 +00:00
|
|
|
if (!eventData->displayName.isEmpty())
|
|
|
|
stream.writeTextElement(QStringLiteral("displayname"), eventData->displayName);
|
2015-07-08 14:03:51 +00:00
|
|
|
if (eventData->rangeType != QQmlProfilerDefinitions::MaximumRangeType)
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("type"),
|
|
|
|
qmlRangeTypeAsString(eventData->rangeType));
|
|
|
|
else
|
|
|
|
stream.writeTextElement(QStringLiteral("type"),
|
|
|
|
qmlMessageAsString(eventData->message));
|
2015-05-26 09:12:09 +00:00
|
|
|
if (!eventData->location.filename.isEmpty())
|
2012-03-08 15:50:14 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("filename"), eventData->location.filename);
|
2015-05-26 09:12:09 +00:00
|
|
|
if (eventData->location.line >= 0)
|
2015-07-08 14:03:51 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("line"),
|
|
|
|
QString::number(eventData->location.line));
|
2015-05-26 09:12:09 +00:00
|
|
|
if (eventData->location.column >= 0)
|
2015-07-08 14:03:51 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("column"),
|
|
|
|
QString::number(eventData->location.column));
|
2015-05-26 09:12:09 +00:00
|
|
|
if (!eventData->details.isEmpty())
|
|
|
|
stream.writeTextElement(QStringLiteral("details"), eventData->details);
|
2015-07-08 14:03:51 +00:00
|
|
|
if (eventData->rangeType == QQmlProfilerDefinitions::Binding)
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("bindingType"),
|
|
|
|
QString::number((int)eventData->detailType));
|
2015-07-08 14:03:51 +00:00
|
|
|
else if (eventData->message == QQmlProfilerDefinitions::Event) {
|
2015-05-21 15:48:58 +00:00
|
|
|
switch (eventData->detailType) {
|
2015-07-08 14:03:51 +00:00
|
|
|
case QQmlProfilerDefinitions::AnimationFrame:
|
2015-05-21 15:48:58 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("animationFrame"),
|
|
|
|
QString::number((int)eventData->detailType));
|
|
|
|
break;
|
2015-07-08 14:03:51 +00:00
|
|
|
case QQmlProfilerDefinitions::Key:
|
2015-05-21 15:48:58 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("keyEvent"),
|
|
|
|
QString::number((int)eventData->detailType));
|
|
|
|
break;
|
2015-07-08 14:03:51 +00:00
|
|
|
case QQmlProfilerDefinitions::Mouse:
|
2015-05-21 15:48:58 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("mouseEvent"),
|
|
|
|
QString::number((int)eventData->detailType));
|
|
|
|
break;
|
|
|
|
}
|
2015-07-08 14:03:51 +00:00
|
|
|
} else if (eventData->message == QQmlProfilerDefinitions::PixmapCacheEvent)
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("cacheEventType"),
|
|
|
|
QString::number((int)eventData->detailType));
|
2015-07-08 14:03:51 +00:00
|
|
|
else if (eventData->message == QQmlProfilerDefinitions::SceneGraphFrame)
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("sgEventType"),
|
|
|
|
QString::number((int)eventData->detailType));
|
2015-07-08 14:03:51 +00:00
|
|
|
else if (eventData->message == QQmlProfilerDefinitions::MemoryAllocation)
|
2014-06-16 11:33:33 +00:00
|
|
|
stream.writeTextElement(QStringLiteral("memoryEventType"),
|
|
|
|
QString::number((int)eventData->detailType));
|
2012-03-08 15:50:14 +00:00
|
|
|
stream.writeEndElement();
|
|
|
|
}
|
|
|
|
stream.writeEndElement(); // eventData
|
|
|
|
|
|
|
|
stream.writeStartElement(QStringLiteral("profilerDataModel"));
|
2014-02-19 17:11:41 +00:00
|
|
|
foreach (const QmlRangeEventStartInstance &event, d->startInstanceList) {
|
2012-03-08 15:50:14 +00:00
|
|
|
stream.writeStartElement(QStringLiteral("range"));
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("startTime"), QString::number(event.startTime));
|
|
|
|
if (event.duration >= 0)
|
2014-03-17 13:52:01 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("duration"),
|
2014-02-19 17:11:41 +00:00
|
|
|
QString::number(event.duration));
|
2015-07-08 14:03:51 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("eventIndex"), QString::number(
|
2016-01-15 12:23:25 +00:00
|
|
|
eventDescriptionsKeys.indexOf(event.data->eventHashStr)));
|
2015-09-17 11:34:38 +00:00
|
|
|
if (event.data->message == QQmlProfilerDefinitions::Event) {
|
|
|
|
if (event.data->detailType == QQmlProfilerDefinitions::AnimationFrame) {
|
|
|
|
// special: animation frame
|
|
|
|
stream.writeAttribute(QStringLiteral("framerate"), QString::number(event.frameRate));
|
|
|
|
stream.writeAttribute(QStringLiteral("animationcount"),
|
|
|
|
QString::number(event.animationCount));
|
|
|
|
stream.writeAttribute(QStringLiteral("thread"), QString::number(event.threadId));
|
|
|
|
} else if (event.data->detailType == QQmlProfilerDefinitions::Key ||
|
|
|
|
event.data->detailType == QQmlProfilerDefinitions::Mouse) {
|
|
|
|
// numerical value here, to keep the format a bit more compact
|
|
|
|
stream.writeAttribute(QStringLiteral("type"),
|
|
|
|
QString::number(event.inputType));
|
|
|
|
stream.writeAttribute(QStringLiteral("data1"),
|
|
|
|
QString::number(event.inputA));
|
|
|
|
stream.writeAttribute(QStringLiteral("data2"),
|
|
|
|
QString::number(event.inputB));
|
|
|
|
}
|
2015-07-08 14:03:51 +00:00
|
|
|
} else if (event.data->message == QQmlProfilerDefinitions::PixmapCacheEvent) {
|
2014-02-19 17:11:41 +00:00
|
|
|
// special: pixmap cache event
|
2015-07-08 14:03:51 +00:00
|
|
|
if (event.data->detailType == QQmlProfilerDefinitions::PixmapSizeKnown) {
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("width"),
|
|
|
|
QString::number(event.numericData1));
|
|
|
|
stream.writeAttribute(QStringLiteral("height"),
|
|
|
|
QString::number(event.numericData2));
|
2015-07-08 14:03:51 +00:00
|
|
|
} else if (event.data->detailType ==
|
|
|
|
QQmlProfilerDefinitions::PixmapReferenceCountChanged ||
|
|
|
|
event.data->detailType ==
|
|
|
|
QQmlProfilerDefinitions::PixmapCacheCountChanged) {
|
2014-02-19 17:11:41 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("refCount"),
|
2015-09-17 11:39:00 +00:00
|
|
|
QString::number(event.numericData1));
|
2014-02-19 17:11:41 +00:00
|
|
|
}
|
2015-07-08 14:03:51 +00:00
|
|
|
} else if (event.data->message == QQmlProfilerDefinitions::SceneGraphFrame) {
|
2014-02-19 17:11:41 +00:00
|
|
|
// special: scenegraph frame events
|
|
|
|
if (event.numericData1 > 0)
|
|
|
|
stream.writeAttribute(QStringLiteral("timing1"),
|
|
|
|
QString::number(event.numericData1));
|
|
|
|
if (event.numericData2 > 0)
|
|
|
|
stream.writeAttribute(QStringLiteral("timing2"),
|
|
|
|
QString::number(event.numericData2));
|
|
|
|
if (event.numericData3 > 0)
|
|
|
|
stream.writeAttribute(QStringLiteral("timing3"),
|
|
|
|
QString::number(event.numericData3));
|
|
|
|
if (event.numericData4 > 0)
|
|
|
|
stream.writeAttribute(QStringLiteral("timing4"),
|
|
|
|
QString::number(event.numericData4));
|
|
|
|
if (event.numericData5 > 0)
|
|
|
|
stream.writeAttribute(QStringLiteral("timing5"),
|
|
|
|
QString::number(event.numericData5));
|
2015-07-08 14:03:51 +00:00
|
|
|
} else if (event.data->message == QQmlProfilerDefinitions::MemoryAllocation) {
|
2014-06-16 11:33:33 +00:00
|
|
|
stream.writeAttribute(QStringLiteral("amount"), QString::number(event.numericData1));
|
2012-03-08 15:50:14 +00:00
|
|
|
}
|
|
|
|
stream.writeEndElement();
|
|
|
|
}
|
|
|
|
stream.writeEndElement(); // profilerDataModel
|
|
|
|
|
|
|
|
stream.writeEndElement(); // trace
|
|
|
|
stream.writeEndDocument();
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerData::setState(QmlProfilerData::State state)
|
|
|
|
{
|
|
|
|
// It's not an error, we are continuously calling "AcquiringData" for example
|
|
|
|
if (d->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case Empty:
|
|
|
|
// if it's not empty, complain but go on
|
|
|
|
if (!isEmpty())
|
|
|
|
emit error("Invalid qmlprofiler state change (Empty)");
|
|
|
|
break;
|
|
|
|
case AcquiringData:
|
|
|
|
// we're not supposed to receive new data while processing older data
|
|
|
|
if (d->state == ProcessingData)
|
|
|
|
emit error("Invalid qmlprofiler state change (AcquiringData)");
|
|
|
|
break;
|
|
|
|
case ProcessingData:
|
|
|
|
if (d->state != AcquiringData)
|
|
|
|
emit error("Invalid qmlprofiler state change (ProcessingData)");
|
|
|
|
break;
|
|
|
|
case Done:
|
|
|
|
if (d->state != ProcessingData && d->state != Empty)
|
|
|
|
emit error("Invalid qmlprofiler state change (Done)");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
emit error("Trying to set unknown state in events list");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->state = state;
|
|
|
|
emit stateChanged();
|
|
|
|
|
|
|
|
// special: if we were done with an empty list, clean internal data and go back to empty
|
|
|
|
if (d->state == Done && isEmpty()) {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|