2013-08-08 13:28:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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-14 18:07:15 +01: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
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02: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.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-08-08 13:28:08 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmlprofilertracefile.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QIODevice>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
// import QmlEventType, QmlBindingType enums, QmlEventLocation
|
|
|
|
|
using namespace QmlDebug;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char PROFILER_FILE_VERSION[] = "1.02";
|
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
static const char *RANGE_TYPE_STRINGS[] = {
|
|
|
|
|
"Painting",
|
|
|
|
|
"Compiling",
|
|
|
|
|
"Creating",
|
|
|
|
|
"Binding",
|
|
|
|
|
"HandlingSignal",
|
|
|
|
|
"Javascript"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Q_STATIC_ASSERT(sizeof(RANGE_TYPE_STRINGS) == QmlDebug::MaximumRangeType * sizeof(const char *));
|
|
|
|
|
|
|
|
|
|
static const char *MESSAGE_STRINGS[] = {
|
|
|
|
|
// So far only pixmap and scenegraph are used. The others are padding.
|
|
|
|
|
"Event",
|
|
|
|
|
"RangeStart",
|
|
|
|
|
"RangeData",
|
|
|
|
|
"RangeLocation",
|
|
|
|
|
"RangeEnd",
|
|
|
|
|
"Complete",
|
|
|
|
|
"PixmapCache",
|
2014-05-27 19:19:03 +02:00
|
|
|
"SceneGraph",
|
|
|
|
|
"MemoryAllocation"
|
2014-06-03 16:57:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Q_STATIC_ASSERT(sizeof(MESSAGE_STRINGS) == QmlDebug::MaximumMessage * sizeof(const char *));
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
#define _(X) QLatin1String(X)
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// "be strict in your output but tolerant in your inputs"
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
static QPair<Message, RangeType> qmlTypeAsEnum(const QString &typeString)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-02-03 23:48:57 +02:00
|
|
|
QPair<Message, RangeType> ret(MaximumMessage,
|
|
|
|
|
MaximumRangeType);
|
2014-06-03 16:57:32 +02:00
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
for (int i = 0; i < MaximumMessage; ++i) {
|
2014-06-03 16:57:32 +02:00
|
|
|
if (typeString == _(MESSAGE_STRINGS[i])) {
|
2015-02-03 23:48:57 +02:00
|
|
|
ret.first = static_cast<Message>(i);
|
2014-06-03 16:57:32 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
for (int i = 0; i < MaximumRangeType; ++i) {
|
2014-06-03 16:57:32 +02:00
|
|
|
if (typeString == _(RANGE_TYPE_STRINGS[i])) {
|
2015-02-03 23:48:57 +02:00
|
|
|
ret.second = static_cast<RangeType>(i);
|
2014-06-03 16:57:32 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
if (ret.first == MaximumMessage && ret.second == MaximumRangeType) {
|
2013-08-08 13:28:08 +02:00
|
|
|
bool isNumber = false;
|
|
|
|
|
int type = typeString.toUInt(&isNumber);
|
2015-02-03 23:48:57 +02:00
|
|
|
if (isNumber && type < MaximumRangeType)
|
2014-06-03 16:57:32 +02:00
|
|
|
// Allow saving ranges as numbers, but not messages.
|
2015-02-03 23:48:57 +02:00
|
|
|
ret.second = static_cast<RangeType>(type);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-06-03 16:57:32 +02:00
|
|
|
|
|
|
|
|
return ret;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
static QString qmlTypeAsString(Message message, RangeType rangeType)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-02-03 23:48:57 +02:00
|
|
|
if (rangeType < MaximumRangeType)
|
2014-06-03 16:57:32 +02:00
|
|
|
return _(RANGE_TYPE_STRINGS[rangeType]);
|
2015-02-03 23:48:57 +02:00
|
|
|
else if (message != MaximumMessage)
|
2014-06-03 16:57:32 +02:00
|
|
|
return _(MESSAGE_STRINGS[message]);
|
|
|
|
|
else
|
|
|
|
|
return QString::number((int)rangeType);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QmlProfilerFileReader::QmlProfilerFileReader(QObject *parent) :
|
|
|
|
|
QObject(parent),
|
2015-02-17 14:25:24 +01:00
|
|
|
m_v8Model(0),
|
|
|
|
|
m_future(0)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerFileReader::setV8DataModel(QV8ProfilerDataModel *dataModel)
|
|
|
|
|
{
|
|
|
|
|
m_v8Model = dataModel;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 13:39:22 +02:00
|
|
|
void QmlProfilerFileReader::setQmlDataModel(QmlProfilerDataModel *dataModel)
|
|
|
|
|
{
|
|
|
|
|
m_qmlModel = dataModel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 14:25:24 +01:00
|
|
|
void QmlProfilerFileReader::setFuture(QFutureInterface<void> *future)
|
|
|
|
|
{
|
|
|
|
|
m_future = future;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
bool QmlProfilerFileReader::load(QIODevice *device)
|
|
|
|
|
{
|
2015-02-17 14:25:24 +01:00
|
|
|
if (m_future) {
|
|
|
|
|
m_future->setProgressRange(0, qMin(device->size(), qint64(INT_MAX)));
|
|
|
|
|
m_future->setProgressValue(0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
QXmlStreamReader stream(device);
|
|
|
|
|
|
|
|
|
|
bool validVersion = true;
|
2014-10-14 16:44:45 +02:00
|
|
|
qint64 traceStart = -1;
|
|
|
|
|
qint64 traceEnd = -1;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
while (validVersion && !stream.atEnd() && !stream.hasError()) {
|
2015-02-17 14:25:24 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return false;
|
2015-02-17 14:31:04 +01:00
|
|
|
QXmlStreamReader::TokenType token = stream.readNext();
|
|
|
|
|
const QStringRef elementName = stream.name();
|
|
|
|
|
switch (token) {
|
|
|
|
|
case QXmlStreamReader::StartDocument : continue;
|
|
|
|
|
case QXmlStreamReader::StartElement : {
|
|
|
|
|
if (elementName == _("trace")) {
|
|
|
|
|
QXmlStreamAttributes attributes = stream.attributes();
|
|
|
|
|
if (attributes.hasAttribute(_("version")))
|
|
|
|
|
validVersion = attributes.value(_("version")) == _(PROFILER_FILE_VERSION);
|
|
|
|
|
else
|
|
|
|
|
validVersion = false;
|
|
|
|
|
if (attributes.hasAttribute(_("traceStart")))
|
|
|
|
|
traceStart = attributes.value(_("traceStart")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("traceEnd")))
|
|
|
|
|
traceEnd = attributes.value(_("traceEnd")).toString().toLongLong();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("eventData")) {
|
|
|
|
|
loadEventData(stream);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("profilerDataModel")) {
|
|
|
|
|
loadProfilerDataModel(stream);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("noteData")) {
|
|
|
|
|
loadNoteData(stream);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("v8profile")) {
|
|
|
|
|
if (m_v8Model)
|
2015-02-17 14:25:24 +01:00
|
|
|
m_v8Model->load(stream, m_future);
|
2015-02-17 14:31:04 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.hasError()) {
|
|
|
|
|
emit error(tr("Error while parsing trace data file: %1").arg(stream.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
m_qmlModel->setData(traceStart, qMax(traceStart, traceEnd), m_qmlEvents, m_ranges);
|
|
|
|
|
m_qmlModel->setNoteData(m_notes);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerFileReader::loadEventData(QXmlStreamReader &stream)
|
|
|
|
|
{
|
2013-08-29 11:04:09 +02:00
|
|
|
QTC_ASSERT(stream.name() == _("eventData"), return);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
QXmlStreamAttributes attributes = stream.attributes();
|
|
|
|
|
|
|
|
|
|
int eventIndex = -1;
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlProfilerDataModel::QmlEventTypeData event = {
|
2013-08-08 13:28:08 +02:00
|
|
|
QString(), // displayname
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlEventLocation(),
|
2014-06-03 16:57:32 +02:00
|
|
|
MaximumMessage,
|
2013-08-08 13:28:08 +02:00
|
|
|
Painting, // type
|
|
|
|
|
QmlBinding, // bindingType, set for backwards compatibility
|
2014-06-13 16:34:30 +02:00
|
|
|
QString(), // details
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData defaultEvent = event;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
while (!stream.atEnd() && !stream.hasError()) {
|
2015-02-17 14:25:24 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
QXmlStreamReader::TokenType token = stream.readNext();
|
2013-08-29 11:04:09 +02:00
|
|
|
const QStringRef elementName = stream.name();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
|
case QXmlStreamReader::StartElement: {
|
|
|
|
|
if (elementName == _("event")) {
|
2015-02-17 14:25:24 +01:00
|
|
|
progress(stream.device());
|
2013-08-08 13:28:08 +02:00
|
|
|
event = defaultEvent;
|
|
|
|
|
|
|
|
|
|
const QXmlStreamAttributes attributes = stream.attributes();
|
|
|
|
|
if (attributes.hasAttribute(_("index"))) {
|
|
|
|
|
eventIndex = attributes.value(_("index")).toString().toInt();
|
|
|
|
|
} else {
|
|
|
|
|
// ignore event
|
|
|
|
|
eventIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stream.readNext();
|
|
|
|
|
if (stream.tokenType() != QXmlStreamReader::Characters)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const QString readData = stream.text().toString();
|
|
|
|
|
|
|
|
|
|
if (elementName == _("displayname")) {
|
|
|
|
|
event.displayName = readData;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("type")) {
|
2015-02-03 23:48:57 +02:00
|
|
|
QPair<Message, RangeType> enums = qmlTypeAsEnum(readData);
|
2014-06-03 16:57:32 +02:00
|
|
|
event.message = enums.first;
|
|
|
|
|
event.rangeType = enums.second;
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("filename")) {
|
2014-06-13 16:34:30 +02:00
|
|
|
event.location.filename = readData;
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("line")) {
|
2014-06-13 16:34:30 +02:00
|
|
|
event.location.line = readData.toInt();
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("column")) {
|
2014-06-13 16:34:30 +02:00
|
|
|
event.location.column = readData.toInt();
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("details")) {
|
2014-06-13 16:34:30 +02:00
|
|
|
event.data = readData;
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
if (elementName == _("animationFrame")) {
|
|
|
|
|
event.detailType = readData.toInt();
|
|
|
|
|
// new animation frames used to be saved as ranges of range type Painting with
|
|
|
|
|
// binding type 4 (which was called "AnimationFrame" to make everything even more
|
|
|
|
|
// confusing), even though they clearly aren't ranges. Convert that to something
|
|
|
|
|
// sane here.
|
|
|
|
|
if (event.detailType == 4) {
|
|
|
|
|
event.message = Event;
|
|
|
|
|
event.rangeType = MaximumRangeType;
|
|
|
|
|
event.detailType = AnimationFrame;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
if (elementName == _("bindingType") ||
|
|
|
|
|
elementName == _("cacheEventType") ||
|
2014-06-13 19:18:01 +02:00
|
|
|
elementName == _("sgEventType") ||
|
2015-05-21 11:52:27 +02:00
|
|
|
elementName == _("memoryEventType") ||
|
|
|
|
|
elementName == _("mouseEvent") ||
|
|
|
|
|
elementName == _("keyEvent")) {
|
2014-06-03 16:57:32 +02:00
|
|
|
event.detailType = readData.toInt();
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QXmlStreamReader::EndElement: {
|
|
|
|
|
if (elementName == _("event")) {
|
|
|
|
|
if (eventIndex >= 0) {
|
|
|
|
|
if (eventIndex >= m_qmlEvents.size())
|
|
|
|
|
m_qmlEvents.resize(eventIndex + 1);
|
|
|
|
|
m_qmlEvents[eventIndex] = event;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elementName == _("eventData")) {
|
|
|
|
|
// done reading eventData
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: break;
|
|
|
|
|
} // switch
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerFileReader::loadProfilerDataModel(QXmlStreamReader &stream)
|
|
|
|
|
{
|
2013-08-29 11:04:09 +02:00
|
|
|
QTC_ASSERT(stream.name() == _("profilerDataModel"), return);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
while (!stream.atEnd() && !stream.hasError()) {
|
2015-02-17 14:25:24 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
QXmlStreamReader::TokenType token = stream.readNext();
|
2013-08-29 11:04:09 +02:00
|
|
|
const QStringRef elementName = stream.name();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
|
case QXmlStreamReader::StartElement: {
|
|
|
|
|
if (elementName == _("range")) {
|
2015-02-17 14:25:24 +01:00
|
|
|
progress(stream.device());
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlProfilerDataModel::QmlEventData range = { -1, 0, 0, 0, 0, 0, 0, 0 };
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
const QXmlStreamAttributes attributes = stream.attributes();
|
|
|
|
|
if (!attributes.hasAttribute(_("startTime"))
|
|
|
|
|
|| !attributes.hasAttribute(_("eventIndex"))) {
|
|
|
|
|
// ignore incomplete entry
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
range.startTime = attributes.value(_("startTime")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("duration")))
|
|
|
|
|
range.duration = attributes.value(_("duration")).toString().toLongLong();
|
|
|
|
|
|
|
|
|
|
// attributes for special events
|
|
|
|
|
if (attributes.hasAttribute(_("framerate")))
|
|
|
|
|
range.numericData1 = attributes.value(_("framerate")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("animationcount")))
|
|
|
|
|
range.numericData2 = attributes.value(_("animationcount")).toString().toLongLong();
|
2014-03-17 12:04:23 +01:00
|
|
|
if (attributes.hasAttribute(_("thread")))
|
|
|
|
|
range.numericData3 = attributes.value(_("thread")).toString().toLongLong();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (attributes.hasAttribute(_("width")))
|
|
|
|
|
range.numericData1 = attributes.value(_("width")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("height")))
|
|
|
|
|
range.numericData2 = attributes.value(_("height")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("refCount")))
|
|
|
|
|
range.numericData3 = attributes.value(_("refCount")).toString().toLongLong();
|
2014-06-13 19:18:01 +02:00
|
|
|
if (attributes.hasAttribute(_("amount")))
|
|
|
|
|
range.numericData1 = attributes.value(_("amount")).toString().toLongLong();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (attributes.hasAttribute(_("timing1")))
|
|
|
|
|
range.numericData1 = attributes.value(_("timing1")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("timing2")))
|
|
|
|
|
range.numericData2 = attributes.value(_("timing2")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("timing3")))
|
|
|
|
|
range.numericData3 = attributes.value(_("timing3")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("timing4")))
|
|
|
|
|
range.numericData4 = attributes.value(_("timing4")).toString().toLongLong();
|
|
|
|
|
if (attributes.hasAttribute(_("timing5")))
|
|
|
|
|
range.numericData5 = attributes.value(_("timing5")).toString().toLongLong();
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
range.typeIndex = attributes.value(_("eventIndex")).toString().toInt();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
m_ranges.append(range);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QXmlStreamReader::EndElement: {
|
|
|
|
|
if (elementName == _("profilerDataModel")) {
|
|
|
|
|
// done reading profilerDataModel
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: break;
|
|
|
|
|
} // switch
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-24 18:23:01 +02:00
|
|
|
void QmlProfilerFileReader::loadNoteData(QXmlStreamReader &stream)
|
|
|
|
|
{
|
|
|
|
|
QmlProfilerDataModel::QmlEventNoteData currentNote;
|
|
|
|
|
while (!stream.atEnd() && !stream.hasError()) {
|
2015-02-17 14:25:24 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-09-24 18:23:01 +02:00
|
|
|
QXmlStreamReader::TokenType token = stream.readNext();
|
|
|
|
|
const QStringRef elementName = stream.name();
|
|
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
|
case QXmlStreamReader::StartElement: {
|
|
|
|
|
if (elementName == _("note")) {
|
2015-02-17 14:25:24 +01:00
|
|
|
progress(stream.device());
|
2014-09-24 18:23:01 +02:00
|
|
|
QXmlStreamAttributes attrs = stream.attributes();
|
|
|
|
|
currentNote.startTime = attrs.value(_("startTime")).toString().toLongLong();
|
|
|
|
|
currentNote.duration = attrs.value(_("duration")).toString().toLongLong();
|
|
|
|
|
currentNote.typeIndex = attrs.value(_("eventIndex")).toString().toInt();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QXmlStreamReader::Characters: {
|
|
|
|
|
currentNote.text = stream.text().toString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QXmlStreamReader::EndElement: {
|
|
|
|
|
if (elementName == _("note")) {
|
|
|
|
|
m_notes.append(currentNote);
|
|
|
|
|
} else if (elementName == _("noteData")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 14:25:24 +01:00
|
|
|
void QmlProfilerFileReader::progress(QIODevice *device)
|
|
|
|
|
{
|
|
|
|
|
if (!m_future)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_future->setProgressValue(qMin(device->pos(), qint64(INT_MAX)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlProfilerFileReader::isCanceled() const
|
|
|
|
|
{
|
|
|
|
|
return m_future && m_future->isCanceled();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
QmlProfilerFileWriter::QmlProfilerFileWriter(QObject *parent) :
|
|
|
|
|
QObject(parent),
|
|
|
|
|
m_startTime(0),
|
|
|
|
|
m_endTime(0),
|
|
|
|
|
m_measuredTime(0),
|
2015-02-10 20:29:54 +01:00
|
|
|
m_v8Model(0),
|
|
|
|
|
m_future(0)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerFileWriter::setTraceTime(qint64 startTime, qint64 endTime, qint64 measuredTime)
|
|
|
|
|
{
|
|
|
|
|
m_startTime = startTime;
|
|
|
|
|
m_endTime = endTime;
|
|
|
|
|
m_measuredTime = measuredTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerFileWriter::setV8DataModel(QV8ProfilerDataModel *dataModel)
|
|
|
|
|
{
|
|
|
|
|
m_v8Model = dataModel;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
void QmlProfilerFileWriter::setQmlEvents(const QVector<QmlProfilerDataModel::QmlEventTypeData> &types,
|
|
|
|
|
const QVector<QmlProfilerDataModel::QmlEventData> &events)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-06-13 16:34:30 +02:00
|
|
|
m_qmlEvents = types;
|
|
|
|
|
m_ranges = events;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-24 18:23:01 +02:00
|
|
|
void QmlProfilerFileWriter::setNotes(const QVector<QmlProfilerDataModel::QmlEventNoteData> ¬es)
|
|
|
|
|
{
|
|
|
|
|
m_notes = notes;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 20:29:54 +01:00
|
|
|
void QmlProfilerFileWriter::setFuture(QFutureInterface<void> *future)
|
|
|
|
|
{
|
|
|
|
|
m_future = future;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void QmlProfilerFileWriter::save(QIODevice *device)
|
|
|
|
|
{
|
2015-02-10 20:29:54 +01:00
|
|
|
if (m_future) {
|
|
|
|
|
m_future->setProgressRange(0,
|
|
|
|
|
qMax(m_qmlEvents.size() + m_ranges.size() + m_notes.size()
|
|
|
|
|
+ m_v8Model->numberOfV8Events(), 1));
|
|
|
|
|
m_future->setProgressValue(0);
|
|
|
|
|
m_newProgressValue = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
QXmlStreamWriter stream(device);
|
|
|
|
|
|
|
|
|
|
stream.setAutoFormatting(true);
|
|
|
|
|
stream.writeStartDocument();
|
|
|
|
|
|
|
|
|
|
stream.writeStartElement(_("trace"));
|
|
|
|
|
stream.writeAttribute(_("version"), _(PROFILER_FILE_VERSION));
|
|
|
|
|
|
|
|
|
|
stream.writeAttribute(_("traceStart"), QString::number(m_startTime));
|
|
|
|
|
stream.writeAttribute(_("traceEnd"), QString::number(m_endTime));
|
|
|
|
|
|
|
|
|
|
stream.writeStartElement(_("eventData"));
|
|
|
|
|
stream.writeAttribute(_("totalTime"), QString::number(m_measuredTime));
|
|
|
|
|
|
2015-02-10 20:29:54 +01:00
|
|
|
for (int typeIndex = 0; typeIndex < m_qmlEvents.size(); ++typeIndex) {
|
|
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &event = m_qmlEvents[typeIndex];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
stream.writeStartElement(_("event"));
|
2014-06-13 16:34:30 +02:00
|
|
|
stream.writeAttribute(_("index"), QString::number(typeIndex));
|
2013-08-08 13:28:08 +02:00
|
|
|
stream.writeTextElement(_("displayname"), event.displayName);
|
2014-06-03 16:57:32 +02:00
|
|
|
stream.writeTextElement(_("type"), qmlTypeAsString(event.message, event.rangeType));
|
2014-06-13 16:34:30 +02:00
|
|
|
if (!event.location.filename.isEmpty()) {
|
|
|
|
|
stream.writeTextElement(_("filename"), event.location.filename);
|
|
|
|
|
stream.writeTextElement(_("line"), QString::number(event.location.line));
|
|
|
|
|
stream.writeTextElement(_("column"), QString::number(event.location.column));
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-06-13 19:16:35 +02:00
|
|
|
|
|
|
|
|
if (!event.data.isEmpty())
|
|
|
|
|
stream.writeTextElement(_("details"), event.data);
|
|
|
|
|
|
2015-05-21 11:52:27 +02:00
|
|
|
if (event.rangeType == Binding) {
|
2014-06-03 16:57:32 +02:00
|
|
|
stream.writeTextElement(_("bindingType"), QString::number(event.detailType));
|
2015-05-21 11:52:27 +02:00
|
|
|
} else if (event.message == Event) {
|
|
|
|
|
switch (event.detailType) {
|
|
|
|
|
case AnimationFrame:
|
|
|
|
|
stream.writeTextElement(_("animationFrame"), QString::number(event.detailType));
|
|
|
|
|
break;
|
|
|
|
|
case Key:
|
|
|
|
|
stream.writeTextElement(_("keyEvent"), QString::number(event.detailType));
|
|
|
|
|
break;
|
|
|
|
|
case Mouse:
|
|
|
|
|
stream.writeTextElement(_("mouseEvent"), QString::number(event.detailType));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (event.message == PixmapCacheEvent) {
|
2014-06-03 16:57:32 +02:00
|
|
|
stream.writeTextElement(_("cacheEventType"), QString::number(event.detailType));
|
2015-05-21 11:52:27 +02:00
|
|
|
} else if (event.message == SceneGraphFrame) {
|
2014-06-03 16:57:32 +02:00
|
|
|
stream.writeTextElement(_("sgEventType"), QString::number(event.detailType));
|
2015-05-21 11:52:27 +02:00
|
|
|
} else if (event.message == MemoryAllocation) {
|
2014-06-13 19:18:01 +02:00
|
|
|
stream.writeTextElement(_("memoryEventType"), QString::number(event.detailType));
|
2015-05-21 11:52:27 +02:00
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
stream.writeEndElement();
|
2015-02-10 20:29:54 +01:00
|
|
|
incrementProgress();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
stream.writeEndElement(); // eventData
|
|
|
|
|
|
|
|
|
|
stream.writeStartElement(_("profilerDataModel"));
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
for (int rangeIndex = 0; rangeIndex < m_ranges.size(); ++rangeIndex) {
|
2015-02-10 20:29:54 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventData &range = m_ranges[rangeIndex];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
stream.writeStartElement(_("range"));
|
|
|
|
|
stream.writeAttribute(_("startTime"), QString::number(range.startTime));
|
|
|
|
|
if (range.duration > 0) // no need to store duration of instantaneous events
|
|
|
|
|
stream.writeAttribute(_("duration"), QString::number(range.duration));
|
2014-06-13 16:34:30 +02:00
|
|
|
stream.writeAttribute(_("eventIndex"), QString::number(range.typeIndex));
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &event = m_qmlEvents[range.typeIndex];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// special: animation event
|
2015-02-03 23:48:57 +02:00
|
|
|
if (event.message == Event && event.detailType == AnimationFrame) {
|
2013-08-08 13:28:08 +02:00
|
|
|
stream.writeAttribute(_("framerate"), QString::number(range.numericData1));
|
|
|
|
|
stream.writeAttribute(_("animationcount"), QString::number(range.numericData2));
|
2014-03-17 12:04:23 +01:00
|
|
|
stream.writeAttribute(_("thread"), QString::number(range.numericData3));
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// special: pixmap cache event
|
2015-02-03 23:48:57 +02:00
|
|
|
if (event.message == PixmapCacheEvent) {
|
2014-06-03 16:57:32 +02:00
|
|
|
if (event.detailType == PixmapSizeKnown) {
|
2013-08-08 13:28:08 +02:00
|
|
|
stream.writeAttribute(_("width"), QString::number(range.numericData1));
|
|
|
|
|
stream.writeAttribute(_("height"), QString::number(range.numericData2));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
if (event.detailType == PixmapReferenceCountChanged ||
|
|
|
|
|
event.detailType == PixmapCacheCountChanged)
|
2013-08-08 13:28:08 +02:00
|
|
|
stream.writeAttribute(_("refCount"), QString::number(range.numericData3));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
if (event.message == SceneGraphFrame) {
|
2013-08-08 13:28:08 +02:00
|
|
|
// special: scenegraph frame events
|
|
|
|
|
if (range.numericData1 > 0)
|
|
|
|
|
stream.writeAttribute(_("timing1"), QString::number(range.numericData1));
|
|
|
|
|
if (range.numericData2 > 0)
|
|
|
|
|
stream.writeAttribute(_("timing2"), QString::number(range.numericData2));
|
|
|
|
|
if (range.numericData3 > 0)
|
|
|
|
|
stream.writeAttribute(_("timing3"), QString::number(range.numericData3));
|
|
|
|
|
if (range.numericData4 > 0)
|
|
|
|
|
stream.writeAttribute(_("timing4"), QString::number(range.numericData4));
|
|
|
|
|
if (range.numericData5 > 0)
|
|
|
|
|
stream.writeAttribute(_("timing5"), QString::number(range.numericData5));
|
|
|
|
|
}
|
2014-06-13 19:18:01 +02:00
|
|
|
|
|
|
|
|
// special: memory allocation event
|
2015-02-03 23:48:57 +02:00
|
|
|
if (event.message == MemoryAllocation)
|
2014-06-13 19:18:01 +02:00
|
|
|
stream.writeAttribute(_("amount"), QString::number(range.numericData1));
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
stream.writeEndElement();
|
2015-02-10 20:29:54 +01:00
|
|
|
incrementProgress();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
stream.writeEndElement(); // profilerDataModel
|
|
|
|
|
|
2014-09-24 18:23:01 +02:00
|
|
|
stream.writeStartElement(_("noteData"));
|
|
|
|
|
for (int noteIndex = 0; noteIndex < m_notes.size(); ++noteIndex) {
|
2015-02-10 20:29:54 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
|
2014-09-24 18:23:01 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventNoteData ¬es = m_notes[noteIndex];
|
|
|
|
|
stream.writeStartElement(_("note"));
|
|
|
|
|
stream.writeAttribute(_("startTime"), QString::number(notes.startTime));
|
|
|
|
|
stream.writeAttribute(_("duration"), QString::number(notes.duration));
|
|
|
|
|
stream.writeAttribute(_("eventIndex"), QString::number(notes.typeIndex));
|
|
|
|
|
stream.writeCharacters(notes.text);
|
|
|
|
|
stream.writeEndElement(); // note
|
2015-02-10 20:29:54 +01:00
|
|
|
incrementProgress();
|
2014-09-24 18:23:01 +02:00
|
|
|
}
|
|
|
|
|
stream.writeEndElement(); // noteData
|
|
|
|
|
|
2015-02-10 20:29:54 +01:00
|
|
|
if (isCanceled())
|
|
|
|
|
return;
|
|
|
|
|
m_v8Model->save(stream, m_future);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
stream.writeEndElement(); // trace
|
|
|
|
|
stream.writeEndDocument();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 20:29:54 +01:00
|
|
|
void QmlProfilerFileWriter::incrementProgress()
|
|
|
|
|
{
|
|
|
|
|
if (!m_future)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_newProgressValue++;
|
|
|
|
|
if (float(m_newProgressValue - m_future->progressValue())
|
|
|
|
|
/ float(m_future->progressMaximum() - m_future->progressMinimum()) >= 0.01) {
|
|
|
|
|
m_future->setProgressValue(m_newProgressValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlProfilerFileWriter::isCanceled() const
|
|
|
|
|
{
|
|
|
|
|
return m_future && m_future->isCanceled();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|