diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-09-17 13:39:00 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-10-30 20:07:53 +0000 |
commit | 57430b2bdad32150e0ed8ceb6893430363ee6670 (patch) | |
tree | 73820f2c3696577b23595f30e5d11588a944447c | |
parent | cdb0ddeffd1bab0afd4c763e44431b11c8e8e0b0 (diff) |
Move QML profiler client to qmldebug
Change-Id: I506909b68be6cbad631d1645673c2d38460aed33
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r-- | src/qmldebug/qmldebug.pro | 10 | ||||
-rw-r--r-- | src/qmldebug/qqmleventlocation_p.h | 67 | ||||
-rw-r--r-- | src/qmldebug/qqmlprofilerclient.cpp | 356 | ||||
-rw-r--r-- | src/qmldebug/qqmlprofilerclient_p.h | 107 | ||||
-rw-r--r-- | src/qmldebug/qqmlprofilerclient_p_p.h (renamed from tools/qmlprofiler/qmlprofilereventlocation.h) | 37 | ||||
-rw-r--r-- | tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp | 466 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofiler.pro | 3 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerapplication.cpp | 32 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerclient.cpp | 310 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerclient.h | 55 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerdata.cpp | 31 | ||||
-rw-r--r-- | tools/qmlprofiler/qmlprofilerdata.h | 10 |
12 files changed, 934 insertions, 550 deletions
diff --git a/src/qmldebug/qmldebug.pro b/src/qmldebug/qmldebug.pro index 6166e85e82..295701eee3 100644 --- a/src/qmldebug/qmldebug.pro +++ b/src/qmldebug/qmldebug.pro @@ -1,14 +1,18 @@ TARGET = QtQmlDebug -QT = core-private network packetprotocol-private +QT = core-private network packetprotocol-private qml-private CONFIG += static internal_module load(qt_module) SOURCES += \ qqmldebugclient.cpp \ - qqmldebugconnection.cpp + qqmldebugconnection.cpp \ + qqmlprofilerclient.cpp HEADERS += \ qqmldebugclient_p.h \ qqmldebugclient_p_p.h \ - qqmldebugconnection_p.h + qqmldebugconnection_p.h \ + qqmleventlocation_p.h \ + qqmlprofilerclient_p.h \ + qqmlprofilerclient_p_p.h diff --git a/src/qmldebug/qqmleventlocation_p.h b/src/qmldebug/qqmleventlocation_p.h new file mode 100644 index 0000000000..25d81a5989 --- /dev/null +++ b/src/qmldebug/qqmleventlocation_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** 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. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQMLEVENTLOCATION_P_H +#define QQMLEVENTLOCATION_P_H + +#include <QtCore/qstring.h> + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +struct QQmlEventLocation +{ + QQmlEventLocation() : line(-1), column(-1) {} + QQmlEventLocation(const QString &file, int lineNumber, int columnNumber) : + filename(file), line(lineNumber), column(columnNumber) {} + + QString filename; + int line; + int column; +}; + +Q_DECLARE_TYPEINFO(QQmlEventLocation, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +#endif // QQMLEVENTLOCATION_P_H diff --git a/src/qmldebug/qqmlprofilerclient.cpp b/src/qmldebug/qqmlprofilerclient.cpp new file mode 100644 index 0000000000..1ac0ba9095 --- /dev/null +++ b/src/qmldebug/qqmlprofilerclient.cpp @@ -0,0 +1,356 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** 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. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qqmlprofilerclient_p_p.h" + +#include <QtCore/qdatastream.h> + +QT_BEGIN_NAMESPACE + +QQmlProfilerClient::QQmlProfilerClient(QQmlDebugConnection *connection) : + QQmlDebugClient(*(new QQmlProfilerClientPrivate(connection))) +{ +} + +QQmlProfilerClient::QQmlProfilerClient(QQmlProfilerClientPrivate &dd) : + QQmlDebugClient(dd) +{ +} + +QQmlProfilerClientPrivate::QQmlProfilerClientPrivate(QQmlDebugConnection *connection) : + QQmlDebugClientPrivate(QStringLiteral("CanvasFrameRate"), connection), + features(std::numeric_limits<quint64>::max()) +{ +} + +void QQmlProfilerClient::setFeatures(quint64 features) +{ + Q_D(QQmlProfilerClient); + d->features = features; +} + +void QQmlProfilerClient::sendRecordingStatus(bool record, int engineId, quint32 flushInterval) +{ + Q_D(const QQmlProfilerClient); + + QByteArray ba; + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << record << engineId << d->features << flushInterval; + sendMessage(ba); +} + +void QQmlProfilerClient::traceStarted(qint64 time, int engineId) +{ + Q_UNUSED(time); + Q_UNUSED(engineId); +} + +void QQmlProfilerClient::traceFinished(qint64 time, int engineId) +{ + Q_UNUSED(time); + Q_UNUSED(engineId); +} + +void QQmlProfilerClient::rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime) +{ + Q_UNUSED(type); + Q_UNUSED(startTime); +} + +void QQmlProfilerClient::rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QString &data) +{ + Q_UNUSED(type); + Q_UNUSED(time); + Q_UNUSED(data); +} + +void QQmlProfilerClient::rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QQmlEventLocation &location) +{ + Q_UNUSED(type); + Q_UNUSED(time); + Q_UNUSED(location); +} + +void QQmlProfilerClient::rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime) +{ + Q_UNUSED(type); + Q_UNUSED(endTime); +} + +void QQmlProfilerClient::animationFrame(qint64 time, int frameRate, int animationCount, + int threadId) +{ + Q_UNUSED(time); + Q_UNUSED(frameRate); + Q_UNUSED(animationCount); + Q_UNUSED(threadId); +} + +void QQmlProfilerClient::sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, + qint64 time, qint64 numericData1, qint64 numericData2, + qint64 numericData3, qint64 numericData4, + qint64 numericData5) +{ + Q_UNUSED(type); + Q_UNUSED(time); + Q_UNUSED(numericData1); + Q_UNUSED(numericData2); + Q_UNUSED(numericData3); + Q_UNUSED(numericData4); + Q_UNUSED(numericData5); +} + +void QQmlProfilerClient::pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, + qint64 time, const QString &url, int numericData1, + int numericData2) +{ + Q_UNUSED(type); + Q_UNUSED(time); + Q_UNUSED(url); + Q_UNUSED(numericData1); + Q_UNUSED(numericData2); +} + +void QQmlProfilerClient::memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, + qint64 amount) +{ + Q_UNUSED(type); + Q_UNUSED(time); + Q_UNUSED(amount); +} + +void QQmlProfilerClient::inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, + int a, int b) +{ + Q_UNUSED(type); + Q_UNUSED(time); + Q_UNUSED(a); + Q_UNUSED(b); +} + +void QQmlProfilerClient::complete() +{ +} + +void QQmlProfilerClient::unknownEvent(QQmlProfilerDefinitions::Message messageType, qint64 time, + int detailType) +{ + Q_UNUSED(messageType); + Q_UNUSED(time); + Q_UNUSED(detailType); +} + +void QQmlProfilerClient::unknownData(QDataStream &stream) +{ + Q_UNUSED(stream); +} + +inline QQmlProfilerDefinitions::ProfileFeature featureFromRangeType( + QQmlProfilerDefinitions::RangeType range) +{ + switch (range) { + case QQmlProfilerDefinitions::Painting: + return QQmlProfilerDefinitions::ProfilePainting; + case QQmlProfilerDefinitions::Compiling: + return QQmlProfilerDefinitions::ProfileCompiling; + case QQmlProfilerDefinitions::Creating: + return QQmlProfilerDefinitions::ProfileCreating; + case QQmlProfilerDefinitions::Binding: + return QQmlProfilerDefinitions::ProfileBinding; + case QQmlProfilerDefinitions::HandlingSignal: + return QQmlProfilerDefinitions::ProfileHandlingSignal; + case QQmlProfilerDefinitions::Javascript: + return QQmlProfilerDefinitions::ProfileJavaScript; + default: + return QQmlProfilerDefinitions::MaximumProfileFeature; + } +} + +void QQmlProfilerClient::messageReceived(const QByteArray &data) +{ + Q_D(const QQmlProfilerClient); + + QByteArray rwData = data; + QDataStream stream(&rwData, QIODevice::ReadOnly); + + // Force all the 1 << <FLAG> expressions to be done in 64 bit, to silence some warnings + const quint64 one = static_cast<quint64>(1); + + qint64 time; + int messageType; + + stream >> time >> messageType; + + if (messageType >= QQmlProfilerDefinitions::MaximumMessage) { + unknownEvent(static_cast<QQmlProfilerDefinitions::Message>(messageType), time, -1); + return; + } + + if (messageType == QQmlProfilerDefinitions::Event) { + int type; + stream >> type; + + QQmlProfilerDefinitions::EventType eventType = + static_cast<QQmlProfilerDefinitions::EventType>(type); + + if (eventType == QQmlProfilerDefinitions::EndTrace) { + int engineId = -1; + if (!stream.atEnd()) + stream >> engineId; + traceFinished(time, engineId); + } else if (eventType == QQmlProfilerDefinitions::AnimationFrame) { + if (!(d->features & one << QQmlProfilerDefinitions::ProfileAnimations)) + return; + + int frameRate, animationCount; + int threadId = 0; + stream >> frameRate >> animationCount; + if (!stream.atEnd()) + stream >> threadId; + + animationFrame(time, frameRate, animationCount, threadId); + } else if (type == QQmlProfilerDefinitions::StartTrace) { + int engineId = -1; + if (!stream.atEnd()) + stream >> engineId; + traceStarted(time, engineId); + } else if (eventType == QQmlProfilerDefinitions::Key || + eventType == QQmlProfilerDefinitions::Mouse) { + + if (!(d->features & one << QQmlProfilerDefinitions::ProfileInputEvents)) + return; + + int type; + if (!stream.atEnd()) { + stream >> type; + } else { + type = (eventType == QQmlProfilerDefinitions::Key) ? + QQmlProfilerDefinitions::InputKeyUnknown : + QQmlProfilerDefinitions::InputMouseUnknown; + } + + int a = 0; + if (!stream.atEnd()) + stream >> a; + + int b = 0; + if (!stream.atEnd()) + stream >> b; + + inputEvent(static_cast<QQmlProfilerDefinitions::InputEventType>(type), time, a, b); + } else { + unknownEvent(QQmlProfilerDefinitions::Event, time, type); + } + } else if (messageType == QQmlProfilerDefinitions::Complete) { + complete(); + } else if (messageType == QQmlProfilerDefinitions::SceneGraphFrame) { + if (!(d->features & one << QQmlProfilerDefinitions::ProfileSceneGraph)) + return; + + int type; + int count = 0; + qint64 params[5]; + + stream >> type; + while (!stream.atEnd()) + stream >> params[count++]; + + while (count < 5) + params[count++] = 0; + + sceneGraphEvent(static_cast<QQmlProfilerDefinitions::SceneGraphFrameType>(type), time, + params[0], params[1], params[2], params[3], params[4]); + } else if (messageType == QQmlProfilerDefinitions::PixmapCacheEvent) { + if (!(d->features & one << QQmlProfilerDefinitions::ProfilePixmapCache)) + return; + + int type, param1 = 0, param2 = 0; + QString pixUrl; + stream >> type >> pixUrl; + + QQmlProfilerDefinitions::PixmapEventType pixmapEventType = + static_cast<QQmlProfilerDefinitions::PixmapEventType>(type); + + if (pixmapEventType == QQmlProfilerDefinitions::PixmapReferenceCountChanged || + pixmapEventType == QQmlProfilerDefinitions::PixmapCacheCountChanged) { + stream >> param1; + } else if (pixmapEventType == QQmlProfilerDefinitions::PixmapSizeKnown) { + stream >> param1 >> param2; + } + + pixmapCacheEvent(pixmapEventType, time, pixUrl, param1, param2); + } else if (messageType == QQmlProfilerDefinitions::MemoryAllocation) { + if (!(d->features & one << QQmlProfilerDefinitions::ProfileMemory)) + return; + int type; + qint64 delta; + stream >> type >> delta; + memoryAllocation((QQmlProfilerDefinitions::MemoryType)type, time, delta); + } else { + int range; + stream >> range; + + QQmlProfilerDefinitions::RangeType rangeType = + static_cast<QQmlProfilerDefinitions::RangeType>(range); + + if (range >= QQmlProfilerDefinitions::MaximumRangeType || + !(d->features & one << featureFromRangeType(rangeType))) + return; + + if (messageType == QQmlProfilerDefinitions::RangeStart) { + rangeStart(rangeType, time); + } else if (messageType == QQmlProfilerDefinitions::RangeData) { + QString data; + stream >> data; + rangeData(rangeType, time, data); + } else if (messageType == QQmlProfilerDefinitions::RangeLocation) { + QQmlEventLocation location; + stream >> location.filename >> location.line; + + if (!stream.atEnd()) + stream >> location.column; + + rangeLocation(rangeType, time, location); + } else if (messageType == QQmlProfilerDefinitions::RangeEnd) { + rangeEnd(rangeType, time); + } else { + unknownEvent(static_cast<QQmlProfilerDefinitions::Message>(messageType), time, range); + } + } + + if (!stream.atEnd()) + unknownData(stream); +} +QT_END_NAMESPACE diff --git a/src/qmldebug/qqmlprofilerclient_p.h b/src/qmldebug/qqmlprofilerclient_p.h new file mode 100644 index 0000000000..f00fbd873a --- /dev/null +++ b/src/qmldebug/qqmlprofilerclient_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** 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. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQMLPROFILERCLIENT_P_H +#define QQMLPROFILERCLIENT_P_H + +#include "qqmldebugclient_p.h" +#include "qqmleventlocation_p.h" +#include <private/qqmlprofilerdefinitions_p.h> + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QQmlProfilerClientPrivate; +class QQmlProfilerClient : public QQmlDebugClient +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QQmlProfilerClient) + +public: + QQmlProfilerClient(QQmlDebugConnection *connection); + void setFeatures(quint64 features); + +public slots: + void sendRecordingStatus(bool record, int engineId = -1, quint32 flushInterval = 0); + +protected: + QQmlProfilerClient(QQmlProfilerClientPrivate &dd); + +private: + virtual void messageReceived(const QByteArray &message); + + virtual void traceStarted(qint64 time, int engineId); + virtual void traceFinished(qint64 time, int engineId); + + virtual void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime); + virtual void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QString &data); + virtual void rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QQmlEventLocation &location); + virtual void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime); + + virtual void animationFrame(qint64 time, int frameRate, int animationCount, int threadId); + + virtual void sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time, + qint64 numericData1, qint64 numericData2, qint64 numericData3, + qint64 numericData4, qint64 numericData5); + + virtual void pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time, + const QString &url, int numericData1, int numericData2); + + virtual void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, + qint64 amount); + + virtual void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, + int b); + + virtual void complete(); + + virtual void unknownEvent(QQmlProfilerDefinitions::Message messageType, qint64 time, + int detailType); + virtual void unknownData(QDataStream &stream); +}; + +QT_END_NAMESPACE + +#endif // QQMLPROFILERCLIENT_P_H diff --git a/tools/qmlprofiler/qmlprofilereventlocation.h b/src/qmldebug/qqmlprofilerclient_p_p.h index ebf9f2eed6..c522eb7f52 100644 --- a/tools/qmlprofiler/qmlprofilereventlocation.h +++ b/src/qmldebug/qqmlprofilerclient_p_p.h @@ -31,23 +31,34 @@ ** ****************************************************************************/ -#ifndef QMLPROFILEREVENTLOCATION_H -#define QMLPROFILEREVENTLOCATION_H +#ifndef QQMLPROFILERCLIENT_P_P_H +#define QQMLPROFILERCLIENT_P_P_H -#include <QString> +#include "qqmlprofilerclient_p.h" +#include "qqmldebugclient_p_p.h" -struct QmlEventLocation +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QQmlProfilerClientPrivate : public QQmlDebugClientPrivate { - QmlEventLocation() : line(-1), column(-1) {} - QmlEventLocation(const QString &file, int lineNumber, int columnNumber) - : filename(file), line(lineNumber), column(columnNumber) {} - QString filename; - int line; - int column; + Q_DECLARE_PUBLIC(QQmlProfilerClient) +public: + QQmlProfilerClientPrivate(QQmlDebugConnection *connection); + quint64 features; }; -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(QmlEventLocation, Q_MOVABLE_TYPE); QT_END_NAMESPACE -#endif // QMLPROFILEREVENTLOCATION_H +#endif // QQMLPROFILERCLIENT_P_P_H + diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index 86926e59ec..199da00e0c 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -34,7 +34,7 @@ #include "debugutil_p.h" #include "../../../shared/util.h" -#include <private/qqmldebugclient_p.h> +#include <private/qqmlprofilerclient_p.h> #include <private/qqmldebugconnection_p.h> #include <QtTest/qtest.h> @@ -45,8 +45,11 @@ struct QQmlProfilerData { - QQmlProfilerData(int messageType = 0, int detailType = 0, const QString &detailData = QString()) - : messageType(messageType), detailType(detailType), detailData(detailData) {} + QQmlProfilerData(qint64 time = -2, int messageType = -1, int detailType = -1, + const QString &detailData = QString()) : + time(time), messageType(messageType), detailType(detailType), detailData(detailData), + line(-1), column(-1), framerate(-1), animationcount(-1), amount(-1) + {} qint64 time; int messageType; @@ -59,109 +62,184 @@ struct QQmlProfilerData int framerate; //used by animation events int animationcount; //used by animation events qint64 amount; //used by heap events - - QByteArray toByteArray() const; }; -class QQmlProfilerClient : public QQmlDebugClient +class QQmlProfilerTestClient : public QQmlProfilerClient { Q_OBJECT public: - enum Message { - Event, - RangeStart, - RangeData, - RangeLocation, - RangeEnd, - Complete, // end of transmission - PixmapCacheEvent, - SceneGraphFrame, - MemoryAllocation, - - MaximumMessage - }; + QQmlProfilerTestClient(QQmlDebugConnection *connection) : QQmlProfilerClient(connection) {} - enum EventType { - FramePaint, - Mouse, - Key, - AnimationFrame, - EndTrace, - StartTrace, + QVector<QQmlProfilerData> qmlMessages; + QVector<QQmlProfilerData> javascriptMessages; + QVector<QQmlProfilerData> jsHeapMessages; + QVector<QQmlProfilerData> asynchronousMessages; + QVector<QQmlProfilerData> pixmapMessages; - MaximumEventType - }; +signals: + void recordingFinished(); - enum RangeType { - Painting, - Compiling, - Creating, - Binding, //running a binding - HandlingSignal, //running a signal handler - Javascript, +private: + void traceStarted(qint64 time, int engineId); + void traceFinished(qint64 time, int engineId); + void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime); + void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, const QString &data); + void rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QQmlEventLocation &location); + void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime); + void animationFrame(qint64 time, int frameRate, int animationCount, int threadId); + void sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time, + qint64 numericData1, qint64 numericData2, qint64 numericData3, + qint64 numericData4, qint64 numericData5); + void pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time, + const QString &url, int numericData1, int numericData2); + void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount); + void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b); + void complete(); - MaximumRangeType - }; + void unknownEvent(QQmlProfilerDefinitions::Message messageType, qint64 time, int detailType); + void unknownData(QDataStream &stream); +}; - enum PixmapEventType { - PixmapSizeKnown, - PixmapReferenceCountChanged, - PixmapCacheCountChanged, - PixmapLoadingStarted, - PixmapLoadingFinished, - PixmapLoadingError, +void QQmlProfilerTestClient::traceStarted(qint64 time, int engineId) +{ + asynchronousMessages.append(QQmlProfilerData(time, QQmlProfilerDefinitions::Event, + QQmlProfilerDefinitions::StartTrace, + QString::number(engineId))); +} - MaximumPixmapEventType - }; +void QQmlProfilerTestClient::traceFinished(qint64 time, int engineId) +{ + asynchronousMessages.append(QQmlProfilerData(time, QQmlProfilerDefinitions::Event, + QQmlProfilerDefinitions::EndTrace, + QString::number(engineId))); +} - enum SceneGraphFrameType { - SceneGraphRendererFrame, - SceneGraphAdaptationLayerFrame, - SceneGraphContextFrame, - SceneGraphRenderLoopFrame, - SceneGraphTexturePrepare, - SceneGraphTextureDeletion, - SceneGraphPolishAndSync, - SceneGraphWindowsRenderShow, - SceneGraphWindowsAnimations, - SceneGraphWindowsPolishFrame, - - MaximumSceneGraphFrameType - }; +void QQmlProfilerTestClient::rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime) +{ + QVERIFY(type >= 0 && type < QQmlProfilerDefinitions::MaximumRangeType); + QQmlProfilerData data(startTime, QQmlProfilerDefinitions::RangeStart, type); + if (type == QQmlProfilerDefinitions::Javascript) + javascriptMessages.append(data); + else + qmlMessages.append(data); +} - enum MemoryType { - HeapPage, - LargeItem, - SmallItem - }; +void QQmlProfilerTestClient::rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QString &string) +{ + QVERIFY(type >= 0 && type < QQmlProfilerDefinitions::MaximumRangeType); + QQmlProfilerData data(time, QQmlProfilerDefinitions::RangeData, type, string); + if (type == QQmlProfilerDefinitions::Javascript) + javascriptMessages.append(data); + else + qmlMessages.append(data); +} - QQmlProfilerClient(QQmlDebugConnection *connection) - : QQmlDebugClient(QLatin1String("CanvasFrameRate"), connection) - { - } +void QQmlProfilerTestClient::rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QQmlEventLocation &location) +{ + QVERIFY(type >= 0 && type < QQmlProfilerDefinitions::MaximumRangeType); + QVERIFY(location.line >= -2); + QQmlProfilerData data(time, QQmlProfilerDefinitions::RangeLocation, type, location.filename); + data.line = location.line; + data.column = location.column; + if (type == QQmlProfilerDefinitions::Javascript) + javascriptMessages.append(data); + else + qmlMessages.append(data); +} - QVector<QQmlProfilerData> qmlMessages; - QVector<QQmlProfilerData> javascriptMessages; - QVector<QQmlProfilerData> jsHeapMessages; - QVector<QQmlProfilerData> asynchronousMessages; - QVector<QQmlProfilerData> pixmapMessages; +void QQmlProfilerTestClient::rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime) +{ + QVERIFY(type >= 0 && type < QQmlProfilerDefinitions::MaximumRangeType); + QQmlProfilerData data(endTime, QQmlProfilerDefinitions::RangeEnd, type); + if (type == QQmlProfilerDefinitions::Javascript) + javascriptMessages.append(data); + else + qmlMessages.append(data); +} + +void QQmlProfilerTestClient::animationFrame(qint64 time, int frameRate, int animationCount, int threadId) +{ + QVERIFY(threadId >= 0); + QVERIFY(frameRate != -1); + QVERIFY(animationCount != -1); + QQmlProfilerData data(time, QQmlProfilerDefinitions::Event, + QQmlProfilerDefinitions::AnimationFrame); + data.framerate = frameRate; + data.animationcount = animationCount; + asynchronousMessages.append(data); +} + +void QQmlProfilerTestClient::sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, + qint64 time, qint64 numericData1, qint64 numericData2, + qint64 numericData3, qint64 numericData4, + qint64 numericData5) +{ + Q_UNUSED(numericData1); + Q_UNUSED(numericData2); + Q_UNUSED(numericData3); + Q_UNUSED(numericData4); + Q_UNUSED(numericData5); + asynchronousMessages.append(QQmlProfilerData(time, QQmlProfilerDefinitions::SceneGraphFrame, + type)); +} - void setTraceState(bool enabled, quint32 flushInterval = 0) { - QByteArray message; - QDataStream stream(&message, QIODevice::WriteOnly); - stream << enabled; - if (enabled && flushInterval) - stream << -1 << std::numeric_limits<quint64>::max() << flushInterval; - sendMessage(message); +void QQmlProfilerTestClient::pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, + qint64 time, const QString &url, int numericData1, + int numericData2) +{ + QQmlProfilerData data(time, QQmlProfilerDefinitions::PixmapCacheEvent, type, url); + switch (type) { + case QQmlProfilerDefinitions::PixmapSizeKnown: + data.line = numericData1; + data.column = numericData2; + break; + case QQmlProfilerDefinitions::PixmapReferenceCountChanged: + case QQmlProfilerDefinitions::PixmapCacheCountChanged: + data.animationcount = numericData1; + break; + default: + break; } + pixmapMessages.append(data); +} -signals: - void complete(); +void QQmlProfilerTestClient::memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, + qint64 amount) +{ + QQmlProfilerData data(time, QQmlProfilerDefinitions::MemoryAllocation, type); + data.amount = amount; + jsHeapMessages.append(data); +} -protected: - void messageReceived(const QByteArray &message); -}; +void QQmlProfilerTestClient::inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, + int a, int b) +{ + qmlMessages.append(QQmlProfilerData(time, QQmlProfilerDefinitions::Event, type, + QString::number(a) + QLatin1Char('x') + + QString::number(b))); +} + +void QQmlProfilerTestClient::unknownEvent(QQmlProfilerDefinitions::Message messageType, qint64 time, + int detailType) +{ + QFAIL(qPrintable(QString::fromLatin1("Unknown event %1 with detail type %2 received at %3.") + .arg(messageType).arg(detailType).arg(time))); +} + +void QQmlProfilerTestClient::unknownData(QDataStream &stream) +{ + QFAIL(qPrintable(QString::fromLatin1("%1 bytes of extra data after receiving message.") + .arg(stream.device()->bytesAvailable()))); +} + +void QQmlProfilerTestClient::complete() +{ + emit recordingFinished(); +} class tst_QQmlProfilerService : public QQmlDataTest { @@ -179,7 +257,7 @@ public: private: QQmlDebugProcess *m_process; QQmlDebugConnection *m_connection; - QQmlProfilerClient *m_client; + QQmlProfilerTestClient *m_client; enum MessageListType { MessageListQML, @@ -221,143 +299,6 @@ private slots: #define VERIFY(type, position, expected, checks) QVERIFY(verify(type, position, expected, checks)) -void QQmlProfilerClient::messageReceived(const QByteArray &message) -{ - QByteArray msg = message; - QDataStream stream(&msg, QIODevice::ReadOnly); - - - QQmlProfilerData data; - data.time = -2; - data.messageType = -1; - data.detailType = -1; - data.line = -1; - data.framerate = -1; - data.animationcount = -1; - - stream >> data.time >> data.messageType; - - switch (data.messageType) { - case (QQmlProfilerClient::Event): { - stream >> data.detailType; - - switch (data.detailType) { - case QQmlProfilerClient::AnimationFrame: { - int threadId; - stream >> data.framerate >> data.animationcount >> threadId; - QVERIFY(threadId >= 0); - QVERIFY(data.framerate != -1); - QVERIFY(data.animationcount != -1); - break; - } - case QQmlProfilerClient::FramePaint: - case QQmlProfilerClient::Mouse: - case QQmlProfilerClient::Key: - break; - case QQmlProfilerClient::EndTrace: - case QQmlProfilerClient::StartTrace: { - int engineId = -1; - if (!stream.atEnd()) { - stream >> engineId; - QVERIFY(engineId >= 0); - } - break; - } - default: { - QString failMsg = QString("Unknown event type:") + data.detailType; - QFAIL(qPrintable(failMsg)); - break; - } - } - break; - } - case QQmlProfilerClient::Complete: { - emit complete(); - return; - } - case QQmlProfilerClient::RangeStart: { - stream >> data.detailType; - QVERIFY(data.detailType >= 0 && data.detailType < QQmlProfilerClient::MaximumRangeType); - break; - } - case QQmlProfilerClient::RangeEnd: { - stream >> data.detailType; - QVERIFY(data.detailType >= 0 && data.detailType < QQmlProfilerClient::MaximumRangeType); - break; - } - case QQmlProfilerClient::RangeData: { - stream >> data.detailType >> data.detailData; - QVERIFY(data.detailType >= 0 && data.detailType < QQmlProfilerClient::MaximumRangeType); - break; - } - case QQmlProfilerClient::RangeLocation: { - stream >> data.detailType >> data.detailData >> data.line >> data.column; - QVERIFY(data.detailType >= 0 && data.detailType < QQmlProfilerClient::MaximumRangeType); - QVERIFY(data.line >= -2); - break; - } - case QQmlProfilerClient::PixmapCacheEvent: { - stream >> data.detailType >> data.detailData; - if (data.detailType == QQmlProfilerClient::PixmapSizeKnown) - stream >> data.line >> data.column; - if (data.detailType == QQmlProfilerClient::PixmapReferenceCountChanged) - stream >> data.animationcount; - if (data.detailType == QQmlProfilerClient::PixmapCacheCountChanged) - stream >> data.animationcount; - break; - } - case QQmlProfilerClient::SceneGraphFrame: { - stream >> data.detailType; - qint64 subtime_1, subtime_2, subtime_3, subtime_4, subtime_5; - int glyphCount; - switch (data.detailType) { - // RendererFrame: preprocessTime, updateTime, bindingTime, renderTime - case QQmlProfilerClient::SceneGraphRendererFrame: stream >> subtime_1 >> subtime_2 >> subtime_3 >> subtime_4; break; - // AdaptationLayerFrame: glyphCount, glyphRenderTime, glyphStoreTime - case QQmlProfilerClient::SceneGraphAdaptationLayerFrame: stream >> glyphCount >> subtime_2 >> subtime_3; break; - // ContextFrame: compiling material time - case QQmlProfilerClient::SceneGraphContextFrame: stream >> subtime_1; break; - // RenderLoop: syncTime, renderTime, swapTime - case QQmlProfilerClient::SceneGraphRenderLoopFrame: stream >> subtime_1 >> subtime_2 >> subtime_3; break; - // TexturePrepare: bind, convert, swizzle, upload, mipmap - case QQmlProfilerClient::SceneGraphTexturePrepare: stream >> subtime_1 >> subtime_2 >> subtime_3 >> subtime_4 >> subtime_5; break; - // TextureDeletion: deletionTime - case QQmlProfilerClient::SceneGraphTextureDeletion: stream >> subtime_1; break; - // PolishAndSync: polishTime, waitTime, syncTime, animationsTime, - case QQmlProfilerClient::SceneGraphPolishAndSync: stream >> subtime_1 >> subtime_2 >> subtime_3 >> subtime_4; break; - // WindowsRenderLoop: GL time, make current time, SceneGraph time - case QQmlProfilerClient::SceneGraphWindowsRenderShow: stream >> subtime_1 >> subtime_2 >> subtime_3; break; - // WindowsAnimations: update time - case QQmlProfilerClient::SceneGraphWindowsAnimations: stream >> subtime_1; break; - // WindowsRenderWindow: polish time - case QQmlProfilerClient::SceneGraphWindowsPolishFrame: stream >> subtime_1; break; - } - break; - } - case QQmlProfilerClient::MemoryAllocation: { - stream >> data.detailType; - stream >> data.amount; - break; - } - default: - QString failMsg = QString("Unknown message type:") + data.messageType; - QFAIL(qPrintable(failMsg)); - break; - } - QVERIFY(stream.atEnd()); - if (data.messageType == QQmlProfilerClient::PixmapCacheEvent) - pixmapMessages.append(data); - else if (data.messageType == QQmlProfilerClient::SceneGraphFrame || - data.messageType == QQmlProfilerClient::Event) - asynchronousMessages.append(data); - else if (data.messageType == QQmlProfilerClient::MemoryAllocation) - jsHeapMessages.append(data); - else if (data.detailType == QQmlProfilerClient::Javascript) - javascriptMessages.append(data); - else - qmlMessages.append(data); -} - void tst_QQmlProfilerService::connect(bool block, const QString &testFile, bool restrictServices) { // ### Still using qmlscene due to QTBUG-33377 @@ -374,7 +315,7 @@ void tst_QQmlProfilerService::connect(bool block, const QString &testFile, bool QVERIFY2(m_process->waitForSessionStart(), "Could not launch application, or did not get 'Waiting for connection'."); m_connection = new QQmlDebugConnection(); - m_client = new QQmlProfilerClient(m_connection); + m_client = new QQmlProfilerTestClient(m_connection); QList<QQmlDebugClient *> others = QQmlDebugTest::createOtherClients(m_connection); const int port = m_process->debugPort(); @@ -390,14 +331,16 @@ void tst_QQmlProfilerService::connect(bool block, const QString &testFile, bool void tst_QQmlProfilerService::checkTraceReceived() { - QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time."); + QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(recordingFinished())), + "No trace received in time."); // must start with "StartTrace" - QQmlProfilerData expected(QQmlProfilerClient::Event, QQmlProfilerClient::StartTrace); + QQmlProfilerData expected(0, QQmlProfilerDefinitions::Event, + QQmlProfilerDefinitions::StartTrace); VERIFY(MessageListAsynchronous, 0, expected, CheckMessageType | CheckDetailType); // must end with "EndTrace" - expected.detailType = QQmlProfilerClient::EndTrace; + expected.detailType = QQmlProfilerDefinitions::EndTrace; VERIFY(MessageListAsynchronous, m_client->asynchronousMessages.length() - 1, expected, CheckMessageType | CheckDetailType); } @@ -414,15 +357,15 @@ void tst_QQmlProfilerService::checkJsHeap() qint64 lastTimestamp = -1; foreach (const QQmlProfilerData &message, m_client->jsHeapMessages) { switch (message.detailType) { - case QQmlProfilerClient::HeapPage: + case QV4::Profiling::HeapPage: allocated += message.amount; seen_alloc = true; break; - case QQmlProfilerClient::SmallItem: + case QV4::Profiling::SmallItem: used += message.amount; seen_small = true; break; - case QQmlProfilerClient::LargeItem: + case QV4::Profiling::LargeItem: allocated += message.amount; used += message.amount; seen_large = true; @@ -593,9 +536,9 @@ void tst_QQmlProfilerService::connect() // if the engine is waiting, then the first message determines if it starts with trace enabled if (!traceEnabled) - m_client->setTraceState(false); - m_client->setTraceState(true); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); + m_client->sendRecordingStatus(true); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); } @@ -604,36 +547,36 @@ void tst_QQmlProfilerService::pixmapCacheData() { connect(true, "pixmapCacheTest.qml"); - m_client->setTraceState(true); + m_client->sendRecordingStatus(true); QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); while (m_process->output().indexOf(QLatin1String("image loaded")) == -1 && m_process->output().indexOf(QLatin1String("image error")) == -1) QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); - QQmlProfilerData expected(QQmlProfilerClient::PixmapCacheEvent); + QQmlProfilerData expected(0, QQmlProfilerDefinitions::PixmapCacheEvent); // image starting to load - expected.detailType = QQmlProfilerClient::PixmapLoadingStarted; + expected.detailType = QQmlProfilerDefinitions::PixmapLoadingStarted; VERIFY(MessageListPixmap, 0, expected, CheckMessageType | CheckDetailType); // image size - expected.detailType = QQmlProfilerClient::PixmapSizeKnown; + expected.detailType = QQmlProfilerDefinitions::PixmapSizeKnown; expected.line = expected.column = 2; // width and height, in fact VERIFY(MessageListPixmap, 1, expected, CheckMessageType | CheckDetailType | CheckLine | CheckColumn); // image loaded - expected.detailType = QQmlProfilerClient::PixmapLoadingFinished; + expected.detailType = QQmlProfilerDefinitions::PixmapLoadingFinished; VERIFY(MessageListPixmap, 2, expected, CheckMessageType | CheckDetailType); // cache size - expected.detailType = QQmlProfilerClient::PixmapCacheCountChanged; + expected.detailType = QQmlProfilerDefinitions::PixmapCacheCountChanged; VERIFY(MessageListPixmap, 3, expected, CheckMessageType | CheckDetailType); } @@ -641,11 +584,11 @@ void tst_QQmlProfilerService::scenegraphData() { connect(true, "scenegraphTest.qml"); - m_client->setTraceState(true); + m_client->sendRecordingStatus(true); while (!m_process->output().contains(QLatin1String("tick"))) QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); @@ -661,8 +604,8 @@ void tst_QQmlProfilerService::scenegraphData() qint64 renderFrameTime = -1; foreach (const QQmlProfilerData &msg, m_client->asynchronousMessages) { - if (msg.messageType == QQmlProfilerClient::SceneGraphFrame) { - if (msg.detailType == QQmlProfilerClient::SceneGraphContextFrame) { + if (msg.messageType == QQmlProfilerDefinitions::SceneGraphFrame) { + if (msg.detailType == QQmlProfilerDefinitions::SceneGraphContextFrame) { contextFrameTime = msg.time; break; } @@ -672,7 +615,7 @@ void tst_QQmlProfilerService::scenegraphData() QVERIFY(contextFrameTime != -1); foreach (const QQmlProfilerData &msg, m_client->asynchronousMessages) { - if (msg.detailType == QQmlProfilerClient::SceneGraphRendererFrame) { + if (msg.detailType == QQmlProfilerDefinitions::SceneGraphRendererFrame) { QVERIFY(msg.time >= contextFrameTime); renderFrameTime = msg.time; break; @@ -682,7 +625,7 @@ void tst_QQmlProfilerService::scenegraphData() QVERIFY(renderFrameTime != -1); foreach (const QQmlProfilerData &msg, m_client->asynchronousMessages) { - if (msg.detailType == QQmlProfilerClient::SceneGraphRenderLoopFrame) { + if (msg.detailType == QQmlProfilerDefinitions::SceneGraphRenderLoopFrame) { QVERIFY(msg.time >= renderFrameTime); break; } @@ -693,7 +636,7 @@ void tst_QQmlProfilerService::profileOnExit() { connect(true, "exit.qml"); - m_client->setTraceState(true); + m_client->sendRecordingStatus(true); checkTraceReceived(); checkJsHeap(); @@ -703,7 +646,7 @@ void tst_QQmlProfilerService::controlFromJS() { connect(true, "controlFromJS.qml"); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); } @@ -712,15 +655,15 @@ void tst_QQmlProfilerService::signalSourceLocation() { connect(true, "signalSourceLocation.qml"); - m_client->setTraceState(true); + m_client->sendRecordingStatus(true); while (!(m_process->output().contains(QLatin1String("500")))) QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); - QQmlProfilerData expected(QQmlProfilerClient::RangeLocation, - QQmlProfilerClient::HandlingSignal, + QQmlProfilerData expected(0, QQmlProfilerDefinitions::RangeLocation, + QQmlProfilerDefinitions::HandlingSignal, QLatin1String("signalSourceLocation.qml")); expected.line = 8; expected.column = 28; @@ -735,28 +678,29 @@ void tst_QQmlProfilerService::javascript() { connect(true, "javascript.qml"); - m_client->setTraceState(true); + m_client->sendRecordingStatus(true); while (!(m_process->output().contains(QLatin1String("done")))) QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); - QQmlProfilerData expected(QQmlProfilerClient::RangeStart, QQmlProfilerClient::Javascript); + QQmlProfilerData expected(0, QQmlProfilerDefinitions::RangeStart, + QQmlProfilerDefinitions::Javascript); VERIFY(MessageListJavaScript, 6, expected, CheckMessageType | CheckDetailType); - expected.messageType = QQmlProfilerClient::RangeLocation; + expected.messageType = QQmlProfilerDefinitions::RangeLocation; expected.detailData = QLatin1String("javascript.qml"); expected.line = 4; expected.column = 5; VERIFY(MessageListJavaScript, 7, expected, CheckAll); - expected.messageType = QQmlProfilerClient::RangeData; + expected.messageType = QQmlProfilerDefinitions::RangeData; expected.detailData = QLatin1String("something"); VERIFY(MessageListJavaScript, 8, expected, CheckMessageType | CheckDetailType | CheckDataEndsWith); - expected.messageType = QQmlProfilerClient::RangeEnd; + expected.messageType = QQmlProfilerDefinitions::RangeEnd; VERIFY(MessageListJavaScript, 21, expected, CheckMessageType | CheckDetailType); } @@ -764,14 +708,14 @@ void tst_QQmlProfilerService::flushInterval() { connect(true, "timer.qml"); - m_client->setTraceState(true, 1); + m_client->sendRecordingStatus(true, -1, 1); // Make sure we get multiple messages QTRY_VERIFY(m_client->qmlMessages.length() > 0); QVERIFY(m_client->qmlMessages.length() < 100); QTRY_VERIFY(m_client->qmlMessages.length() > 100); - m_client->setTraceState(false); + m_client->sendRecordingStatus(false); checkTraceReceived(); checkJsHeap(); } diff --git a/tools/qmlprofiler/qmlprofiler.pro b/tools/qmlprofiler/qmlprofiler.pro index 84e298fe9b..a65e25c657 100644 --- a/tools/qmlprofiler/qmlprofiler.pro +++ b/tools/qmlprofiler/qmlprofiler.pro @@ -12,7 +12,6 @@ HEADERS += \ commandlistener.h \ constants.h \ qmlprofilerdata.h \ - qmlprofilerclient.h \ - qmlprofilereventlocation.h + qmlprofilerclient.h load(qt_tool) diff --git a/tools/qmlprofiler/qmlprofilerapplication.cpp b/tools/qmlprofiler/qmlprofilerapplication.cpp index 04d0ede54a..cd34cd603f 100644 --- a/tools/qmlprofiler/qmlprofilerapplication.cpp +++ b/tools/qmlprofiler/qmlprofilerapplication.cpp @@ -84,7 +84,7 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) : m_verbose(false), m_recording(true), m_interactive(false), - m_qmlProfilerClient(&m_connection), + m_qmlProfilerClient(&m_connection, &m_profilerData), m_connectionAttempts(0) { m_connectTimer.setInterval(1000); @@ -94,30 +94,8 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) : connect(&m_qmlProfilerClient, SIGNAL(enabledChanged(bool)), this, SLOT(traceClientEnabledChanged(bool))); - connect(&m_qmlProfilerClient, SIGNAL(range(QQmlProfilerDefinitions::RangeType,QQmlProfilerDefinitions::BindingType,qint64,qint64,QStringList,QmlEventLocation)), - &m_profilerData, SLOT(addQmlEvent(QQmlProfilerDefinitions::RangeType,QQmlProfilerDefinitions::BindingType,qint64,qint64,QStringList,QmlEventLocation))); - connect(&m_qmlProfilerClient, SIGNAL(traceFinished(qint64)), &m_profilerData, SLOT(setTraceEndTime(qint64))); - connect(&m_qmlProfilerClient, SIGNAL(traceStarted(qint64)), &m_profilerData, SLOT(setTraceStartTime(qint64))); - connect(&m_qmlProfilerClient, SIGNAL(traceStarted(qint64)), this, SLOT(notifyTraceStarted())); - connect(&m_qmlProfilerClient, SIGNAL(frame(qint64,int,int,int)), &m_profilerData, SLOT(addFrameEvent(qint64,int,int,int))); - connect(&m_qmlProfilerClient, SIGNAL(sceneGraphFrame(QQmlProfilerDefinitions::SceneGraphFrameType, - qint64,qint64,qint64,qint64,qint64,qint64)), - &m_profilerData, SLOT(addSceneGraphFrameEvent(QQmlProfilerDefinitions::SceneGraphFrameType, - qint64,qint64,qint64,qint64,qint64,qint64))); - connect(&m_qmlProfilerClient, SIGNAL(pixmapCache(QQmlProfilerDefinitions::PixmapEventType,qint64, - QmlEventLocation,int,int,int)), - &m_profilerData, SLOT(addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType,qint64, - QmlEventLocation,int,int,int))); - connect(&m_qmlProfilerClient, SIGNAL(memoryAllocation(QQmlProfilerDefinitions::MemoryType,qint64, - qint64)), - &m_profilerData, SLOT(addMemoryEvent(QQmlProfilerDefinitions::MemoryType,qint64, - qint64))); - connect(&m_qmlProfilerClient, SIGNAL(inputEvent(QQmlProfilerDefinitions::InputEventType,qint64, - int,int)), - &m_profilerData, SLOT(addInputEvent(QQmlProfilerDefinitions::InputEventType,qint64,int, - int))); - - connect(&m_qmlProfilerClient, SIGNAL(complete()), &m_profilerData, SLOT(complete())); + connect(&m_qmlProfilerClient, SIGNAL(recordingStarted()), this, SLOT(notifyTraceStarted())); + connect(&m_qmlProfilerClient, SIGNAL(error(QString)), this, SLOT(logError(QString))); connect(&m_profilerData, SIGNAL(error(QString)), this, SLOT(logError(QString))); connect(&m_profilerData, SIGNAL(dataReady()), this, SLOT(traceFinished())); @@ -557,7 +535,7 @@ void QmlProfilerApplication::processFinished() if (!m_interactive) exit(exitCode); else - m_qmlProfilerClient.clearData(); + m_qmlProfilerClient.clearPendingData(); } void QmlProfilerApplication::traceClientEnabledChanged(bool enabled) @@ -583,7 +561,7 @@ void QmlProfilerApplication::traceFinished() prompt(tr("Application stopped recording."), false); } - m_qmlProfilerClient.clearData(); + m_qmlProfilerClient.clearPendingData(); } void QmlProfilerApplication::prompt(const QString &line, bool ready) diff --git a/tools/qmlprofiler/qmlprofilerclient.cpp b/tools/qmlprofiler/qmlprofilerclient.cpp index 5e63529d35..018f1ec803 100644 --- a/tools/qmlprofiler/qmlprofilerclient.cpp +++ b/tools/qmlprofiler/qmlprofilerclient.cpp @@ -32,6 +32,9 @@ ****************************************************************************/ #include "qmlprofilerclient.h" +#include "qmlprofilerdata.h" + +#include <private/qqmlprofilerclient_p_p.h> #include <QtCore/QStack> #include <QtCore/QStringList> @@ -39,43 +42,38 @@ #include <limits> -class QmlProfilerClientPrivate +class QmlProfilerClientPrivate : public QQmlProfilerClientPrivate { + Q_DECLARE_PUBLIC(QmlProfilerClient) public: - QmlProfilerClientPrivate() - : inProgressRanges(0) , features(std::numeric_limits<quint64>::max()), enabled(false) - { - ::memset(rangeCount, 0, QQmlProfilerDefinitions::MaximumRangeType * sizeof(int)); - } + QmlProfilerClientPrivate(QQmlDebugConnection *connection, QmlProfilerData *data); + + QmlProfilerData *data; qint64 inProgressRanges; QStack<qint64> rangeStartTimes[QQmlProfilerDefinitions::MaximumRangeType]; QStack<QStringList> rangeDatas[QQmlProfilerDefinitions::MaximumRangeType]; - QStack<QmlEventLocation> rangeLocations[QQmlProfilerDefinitions::MaximumRangeType]; + QStack<QQmlEventLocation> rangeLocations[QQmlProfilerDefinitions::MaximumRangeType]; int rangeCount[QQmlProfilerDefinitions::MaximumRangeType]; - quint64 features; bool enabled; }; -QmlProfilerClient::QmlProfilerClient(QQmlDebugConnection *client) - : QQmlDebugClient(QStringLiteral("CanvasFrameRate"), client), - d(new QmlProfilerClientPrivate) +QmlProfilerClientPrivate::QmlProfilerClientPrivate(QQmlDebugConnection *connection, + QmlProfilerData *data) : + QQmlProfilerClientPrivate(connection), data(data), inProgressRanges(0), enabled(false) { + ::memset(rangeCount, 0, QQmlProfilerDefinitions::MaximumRangeType * sizeof(int)); } -QmlProfilerClient::~QmlProfilerClient() +QmlProfilerClient::QmlProfilerClient(QQmlDebugConnection *connection, QmlProfilerData *data) : + QQmlProfilerClient(*(new QmlProfilerClientPrivate(connection, data))) { - delete d; } -void QmlProfilerClient::setFeatures(quint64 features) -{ - d->features = features; -} - -void QmlProfilerClient::clearData() +void QmlProfilerClient::clearPendingData() { + Q_D(QmlProfilerClient); for (int i = 0; i < QQmlProfilerDefinitions::MaximumRangeType; ++i) { d->rangeCount[i] = 0; d->rangeDatas[i].clear(); @@ -83,202 +81,126 @@ void QmlProfilerClient::clearData() } } -void QmlProfilerClient::sendRecordingStatus(bool record) -{ - QByteArray ba; - QDataStream stream(&ba, QIODevice::WriteOnly); - stream << record << -1 << d->features; - sendMessage(ba); -} - -inline QQmlProfilerDefinitions::ProfileFeature featureFromRangeType( - QQmlProfilerDefinitions::RangeType range) -{ - switch (range) { - case QQmlProfilerDefinitions::Painting: - return QQmlProfilerDefinitions::ProfilePainting; - case QQmlProfilerDefinitions::Compiling: - return QQmlProfilerDefinitions::ProfileCompiling; - case QQmlProfilerDefinitions::Creating: - return QQmlProfilerDefinitions::ProfileCreating; - case QQmlProfilerDefinitions::Binding: - return QQmlProfilerDefinitions::ProfileBinding; - case QQmlProfilerDefinitions::HandlingSignal: - return QQmlProfilerDefinitions::ProfileHandlingSignal; - case QQmlProfilerDefinitions::Javascript: - return QQmlProfilerDefinitions::ProfileJavaScript; - default: - return QQmlProfilerDefinitions::MaximumProfileFeature; - } -} - void QmlProfilerClient::stateChanged(State state) { + Q_D(QmlProfilerClient); if ((d->enabled && state != Enabled) || (!d->enabled && state == Enabled)) { d->enabled = (state == Enabled); emit enabledChanged(d->enabled); } } -void QmlProfilerClient::messageReceived(const QByteArray &data) +void QmlProfilerClient::traceStarted(qint64 time, int engineId) { - QByteArray rwData = data; - QDataStream stream(&rwData, QIODevice::ReadOnly); - - // Force all the 1 << <FLAG> expressions to be done in 64 bit, to silence some warnings - const quint64 one = static_cast<quint64>(1); - - qint64 time; - int messageType; - - stream >> time >> messageType; - - if (messageType >= QQmlProfilerDefinitions::MaximumMessage) - return; - - if (messageType == QQmlProfilerDefinitions::Event) { - int event; - stream >> event; - - if (event == QQmlProfilerDefinitions::EndTrace) { - emit this->traceFinished(time); - } else if (event == QQmlProfilerDefinitions::AnimationFrame) { - if (!(d->features & one << QQmlProfilerDefinitions::ProfileAnimations)) - return; - int frameRate, animationCount; - int threadId = 0; - stream >> frameRate >> animationCount; - if (!stream.atEnd()) - stream >> threadId; - emit this->frame(time, frameRate, animationCount, threadId); - } else if (event == QQmlProfilerDefinitions::StartTrace) { - emit this->traceStarted(time); - } else if (event == QQmlProfilerDefinitions::Key || - event == QQmlProfilerDefinitions::Mouse) { - if (!(d->features & one << QQmlProfilerDefinitions::ProfileInputEvents)) - return; - - int type; - if (!stream.atEnd()) { - stream >> type; - } else { - type = (event == QQmlProfilerDefinitions::Key) ? - QQmlProfilerDefinitions::InputKeyUnknown : - QQmlProfilerDefinitions::InputMouseUnknown; - } + Q_UNUSED(engineId); + Q_D(QmlProfilerClient); + d->data->setTraceStartTime(time); + emit recordingStarted(); +} - int a = 0; - if (!stream.atEnd()) - stream >> a; +void QmlProfilerClient::traceFinished(qint64 time, int engineId) +{ + Q_UNUSED(engineId); + Q_D(QmlProfilerClient); + d->data->setTraceEndTime(time); +} - int b = 0; - if (!stream.atEnd()) - stream >> b; +void QmlProfilerClient::rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime) +{ + Q_D(QmlProfilerClient); + d->rangeStartTimes[type].push(startTime); + d->inProgressRanges |= (static_cast<qint64>(1) << type); + ++d->rangeCount[type]; +} - emit inputEvent(static_cast<QQmlProfilerDefinitions::InputEventType>(type), time, a, b); - } - } else if (messageType == QQmlProfilerDefinitions::Complete) { - emit complete(); - } else if (messageType == QQmlProfilerDefinitions::SceneGraphFrame) { - if (!(d->features & one << QQmlProfilerDefinitions::ProfileSceneGraph)) - return; - int sgEventType; - int count = 0; - qint64 params[5]; +void QmlProfilerClient::rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QString &data) +{ + Q_UNUSED(time); + Q_D(QmlProfilerClient); + int count = d->rangeCount[type]; + if (count > 0) { + while (d->rangeDatas[type].count() < count) + d->rangeDatas[type].push(QStringList()); + d->rangeDatas[type][count - 1] << data; + } +} - stream >> sgEventType; - while (!stream.atEnd()) { - stream >> params[count++]; - } - while (count<5) - params[count++] = 0; - emit sceneGraphFrame((QQmlProfilerDefinitions::SceneGraphFrameType)sgEventType, time, - params[0], params[1], params[2], params[3], params[4]); - } else if (messageType == QQmlProfilerDefinitions::PixmapCacheEvent) { - if (!(d->features & one << QQmlProfilerDefinitions::ProfilePixmapCache)) - return; - int pixEvTy, width = 0, height = 0, refcount = 0; - QString pixUrl; - stream >> pixEvTy >> pixUrl; - if (pixEvTy == (int)QQmlProfilerDefinitions::PixmapReferenceCountChanged || - pixEvTy == (int)QQmlProfilerDefinitions::PixmapCacheCountChanged) { - stream >> refcount; - } else if (pixEvTy == (int)QQmlProfilerDefinitions::PixmapSizeKnown) { - stream >> width >> height; - refcount = 1; - } - emit pixmapCache((QQmlProfilerDefinitions::PixmapEventType)pixEvTy, time, - QmlEventLocation(pixUrl,0,0), width, height, refcount); - } else if (messageType == QQmlProfilerDefinitions::MemoryAllocation) { - if (!(d->features & one << QQmlProfilerDefinitions::ProfileMemory)) - return; - int type; - qint64 delta; - stream >> type >> delta; - emit memoryAllocation((QQmlProfilerDefinitions::MemoryType)type, time, delta); - } else { - int range; - stream >> range; +void QmlProfilerClient::rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QQmlEventLocation &location) +{ + Q_UNUSED(time); + Q_D(QmlProfilerClient); + if (d->rangeCount[type] > 0) + d->rangeLocations[type].push(location); +} - if (range >= QQmlProfilerDefinitions::MaximumRangeType) - return; +void QmlProfilerClient::rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime) +{ + Q_D(QmlProfilerClient); - if (!(d->features & one << featureFromRangeType( - static_cast<QQmlProfilerDefinitions::RangeType>(range)))) - return; + if (d->rangeCount[type] == 0) { + emit error(tr("Spurious range end detected.")); + return; + } - if (messageType == QQmlProfilerDefinitions::RangeStart) { - d->rangeStartTimes[range].push(time); - d->inProgressRanges |= (static_cast<qint64>(1) << range); - ++d->rangeCount[range]; + --d->rangeCount[type]; + if (d->inProgressRanges & (static_cast<qint64>(1) << type)) + d->inProgressRanges &= ~(static_cast<qint64>(1) << type); + QStringList data = d->rangeDatas[type].count() ? d->rangeDatas[type].pop() : QStringList(); + QQmlEventLocation location = d->rangeLocations[type].count() ? d->rangeLocations[type].pop() : + QQmlEventLocation(); + qint64 startTime = d->rangeStartTimes[type].pop(); + + if (d->rangeCount[type] == 0 && d->rangeDatas[type].count() + d->rangeStartTimes[type].count() + + d->rangeLocations[type].count() != 0) { + emit error(tr("Incorrectly nested range data")); + return; + } - } else if (messageType == QQmlProfilerDefinitions::RangeData) { - QString data; - stream >> data; + d->data->addQmlEvent(type, QQmlProfilerDefinitions::QmlBinding, startTime, endTime - startTime, + data, location); +} - 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; - } +void QmlProfilerClient::animationFrame(qint64 time, int frameRate, int animationCount, int threadId) +{ + Q_D(QmlProfilerClient); + d->data->addFrameEvent(time, frameRate, animationCount, threadId); +} - } else if (messageType == QQmlProfilerDefinitions::RangeLocation) { - QString fileName; - int line; - int column = -1; - stream >> fileName >> line; +void QmlProfilerClient::sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, + qint64 time, qint64 numericData1, qint64 numericData2, + qint64 numericData3, qint64 numericData4, + qint64 numericData5) +{ + Q_D(QmlProfilerClient); + d->data->addSceneGraphFrameEvent(type, time, numericData1, numericData2, numericData3, + numericData4, numericData5); +} - if (!stream.atEnd()) - stream >> column; +void QmlProfilerClient::pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time, + const QString &url, int numericData1, int numericData2) +{ + Q_D(QmlProfilerClient); + d->data->addPixmapCacheEvent(type, time, url, numericData1, numericData2); +} - if (d->rangeCount[range] > 0) { - d->rangeLocations[range].push(QmlEventLocation(fileName, line, - 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); +void QmlProfilerClient::memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, + qint64 amount) +{ + Q_D(QmlProfilerClient); + d->data->addMemoryEvent(type, time, amount); +} - QStringList data = d->rangeDatas[range].count() ? - d->rangeDatas[range].pop() : QStringList(); - QmlEventLocation location = d->rangeLocations[range].count() ? - d->rangeLocations[range].pop() : QmlEventLocation(); +void QmlProfilerClient::inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, + int a, int b) +{ + Q_D(QmlProfilerClient); + d->data->addInputEvent(type, time, a, b); +} - qint64 startTime = d->rangeStartTimes[range].pop(); - emit this->range((QQmlProfilerDefinitions::RangeType)range, - QQmlProfilerDefinitions::QmlBinding, startTime, time - startTime, - data, location); - 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"; - } - } - } - } +void QmlProfilerClient::complete() +{ + Q_D(QmlProfilerClient); + d->data->complete(); } diff --git a/tools/qmlprofiler/qmlprofilerclient.h b/tools/qmlprofiler/qmlprofilerclient.h index bc267c7c88..fc4dad639d 100644 --- a/tools/qmlprofiler/qmlprofilerclient.h +++ b/tools/qmlprofiler/qmlprofilerclient.h @@ -34,50 +34,45 @@ #ifndef QMLPROFILERCLIENT_H #define QMLPROFILERCLIENT_H -#include "qmlprofilereventlocation.h" - -#include <private/qqmldebugclient_p.h> +#include <private/qqmleventlocation_p.h> +#include <private/qqmlprofilerclient_p.h> #include <private/qqmlprofilerdefinitions_p.h> -class QmlProfilerClient : public QQmlDebugClient +class QmlProfilerData; +class QmlProfilerClientPrivate; +class QmlProfilerClient : public QQmlProfilerClient { Q_OBJECT + Q_DECLARE_PRIVATE(QmlProfilerClient) public: - QmlProfilerClient(QQmlDebugConnection *client); - ~QmlProfilerClient(); + QmlProfilerClient(QQmlDebugConnection *connection, QmlProfilerData *data); + void clearPendingData(); - void setFeatures(quint64 features); - void clearData(); +signals: + void enabledChanged(bool enabled); + void recordingStarted(); + void error(const QString &error); -public slots: - void sendRecordingStatus(bool record); +private: + virtual void stateChanged(State state); -signals: - void traceFinished( qint64 time ); - void traceStarted( qint64 time ); - void range(QQmlProfilerDefinitions::RangeType type, - QQmlProfilerDefinitions::BindingType bindingType, - qint64 startTime, qint64 length, - const QStringList &data, - const QmlEventLocation &location); - void frame(qint64 time, int frameRate, int animationCount, int threadId); - void sceneGraphFrame(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time, + void traceStarted(qint64 time, int engineId); + void traceFinished(qint64 time, int engineId); + void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime); + void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, const QString &data); + void rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time, + const QQmlEventLocation &location); + void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime); + void animationFrame(qint64 time, int frameRate, int animationCount, int threadId); + void sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time, qint64 numericData1, qint64 numericData2, qint64 numericData3, qint64 numericData4, qint64 numericData5); - void pixmapCache(QQmlProfilerDefinitions::PixmapEventType, qint64 time, - const QmlEventLocation &location, int width, int height, int refCount); + void pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time, + const QString &url, int numericData1, int numericData2); void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount); void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b); void complete(); - void enabledChanged(bool enabled); - -protected: - virtual void stateChanged(State state); - virtual void messageReceived(const QByteArray &); - -private: - class QmlProfilerClientPrivate *d; }; #endif // QMLPROFILERCLIENT_H diff --git a/tools/qmlprofiler/qmlprofilerdata.cpp b/tools/qmlprofiler/qmlprofilerdata.cpp index 4ed1a434a3..9465e4931d 100644 --- a/tools/qmlprofiler/qmlprofilerdata.cpp +++ b/tools/qmlprofiler/qmlprofilerdata.cpp @@ -73,14 +73,14 @@ Q_STATIC_ASSERT(sizeof(MESSAGE_STRINGS) == struct QmlRangeEventData { QmlRangeEventData() {} // never called QmlRangeEventData(const QString &_displayName, int _detailType, const QString &_eventHashStr, - const QmlEventLocation &_location, const QString &_details, + const QQmlEventLocation &_location, const QString &_details, QQmlProfilerDefinitions::Message _message, QQmlProfilerDefinitions::RangeType _rangeType) : displayName(_displayName), eventHashStr(_eventHashStr), location(_location), details(_details), message(_message), rangeType(_rangeType), detailType(_detailType) {} QString displayName; QString eventHashStr; - QmlEventLocation location; + QQmlEventLocation location; QString details; QQmlProfilerDefinitions::Message message; QQmlProfilerDefinitions::RangeType rangeType; @@ -175,7 +175,7 @@ void QmlProfilerData::clear() setState(Empty); } -QString QmlProfilerData::getHashStringForQmlEvent(const QmlEventLocation &location, int eventType) +QString QmlProfilerData::getHashStringForQmlEvent(const QQmlEventLocation &location, int eventType) { return QString(QStringLiteral("%1:%2:%3:%4")).arg( location.filename, @@ -227,7 +227,7 @@ void QmlProfilerData::addQmlEvent(QQmlProfilerDefinitions::RangeType type, qint64 startTime, qint64 duration, const QStringList &data, - const QmlEventLocation &location) + const QQmlEventLocation &location) { setState(AcquiringData); @@ -247,7 +247,7 @@ void QmlProfilerData::addQmlEvent(QQmlProfilerDefinitions::RangeType type, details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1); } - QmlEventLocation eventLocation = location; + QQmlEventLocation eventLocation = location; QString displayName, eventHashStr; // generate hash if (eventLocation.filename.isEmpty()) { @@ -289,7 +289,7 @@ void QmlProfilerData::addFrameEvent(qint64 time, int framerate, int animationcou } else { newEvent = new QmlRangeEventData(displayName, QQmlProfilerDefinitions::AnimationFrame, eventHashStr, - QmlEventLocation(), details, + QQmlEventLocation(), details, QQmlProfilerDefinitions::Event, QQmlProfilerDefinitions::MaximumRangeType); d->eventDescriptions.insert(eventHashStr, newEvent); @@ -314,7 +314,7 @@ void QmlProfilerData::addSceneGraphFrameEvent(QQmlProfilerDefinitions::SceneGrap newEvent = d->eventDescriptions[eventHashStr]; } else { newEvent = new QmlRangeEventData(QStringLiteral("<SceneGraph>"), type, eventHashStr, - QmlEventLocation(), QString(), + QQmlEventLocation(), QString(), QQmlProfilerDefinitions::SceneGraphFrame, QQmlProfilerDefinitions::MaximumRangeType); d->eventDescriptions.insert(eventHashStr, newEvent); @@ -327,12 +327,12 @@ void QmlProfilerData::addSceneGraphFrameEvent(QQmlProfilerDefinitions::SceneGrap } void QmlProfilerData::addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, - qint64 time, const QmlEventLocation &location, - int width, int height, int refcount) + qint64 time, const QString &location, + int numericData1, int numericData2) { setState(AcquiringData); - QString filePath = QUrl(location.filename).path(); + QString filePath = QUrl(location).path(); QString eventHashStr = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1) + QStringLiteral(":") + QString::number(type); @@ -340,13 +340,14 @@ void QmlProfilerData::addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventTy if (d->eventDescriptions.contains(eventHashStr)) { newEvent = d->eventDescriptions[eventHashStr]; } else { - newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr, location, QString(), + newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr, + QQmlEventLocation(location, -1, -1), QString(), QQmlProfilerDefinitions::PixmapCacheEvent, QQmlProfilerDefinitions::MaximumRangeType); d->eventDescriptions.insert(eventHashStr, newEvent); } - QmlRangeEventStartInstance rangeEventStartInstance(time, width, height, refcount, 0, 0, + QmlRangeEventStartInstance rangeEventStartInstance(time, numericData1, numericData2, 0, 0, 0, newEvent); d->startInstanceList.append(rangeEventStartInstance); } @@ -360,7 +361,7 @@ void QmlProfilerData::addMemoryEvent(QQmlProfilerDefinitions::MemoryType type, q if (d->eventDescriptions.contains(eventHashStr)) { newEvent = d->eventDescriptions[eventHashStr]; } else { - newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr, QmlEventLocation(), + newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr, QQmlEventLocation(), QString(), QQmlProfilerDefinitions::MemoryAllocation, QQmlProfilerDefinitions::MaximumRangeType); d->eventDescriptions.insert(eventHashStr, newEvent); @@ -392,7 +393,7 @@ void QmlProfilerData::addInputEvent(QQmlProfilerDefinitions::InputEventType type if (d->eventDescriptions.contains(eventHashStr)) { newEvent = d->eventDescriptions[eventHashStr]; } else { - newEvent = new QmlRangeEventData(QString(), eventType, eventHashStr, QmlEventLocation(), + newEvent = new QmlRangeEventData(QString(), eventType, eventHashStr, QQmlEventLocation(), QString(), QQmlProfilerDefinitions::Event, QQmlProfilerDefinitions::MaximumRangeType); d->eventDescriptions.insert(eventHashStr, newEvent); @@ -612,7 +613,7 @@ bool QmlProfilerData::save(const QString &filename) event.data->detailType == QQmlProfilerDefinitions::PixmapCacheCountChanged) { stream.writeAttribute(QStringLiteral("refCount"), - QString::number(event.numericData3)); + QString::number(event.numericData1)); } } else if (event.data->message == QQmlProfilerDefinitions::SceneGraphFrame) { // special: scenegraph frame events diff --git a/tools/qmlprofiler/qmlprofilerdata.h b/tools/qmlprofiler/qmlprofilerdata.h index b931409917..345f7f2d12 100644 --- a/tools/qmlprofiler/qmlprofilerdata.h +++ b/tools/qmlprofiler/qmlprofilerdata.h @@ -34,9 +34,9 @@ #ifndef QMLPROFILERDATA_H #define QMLPROFILERDATA_H -#include "qmlprofilereventlocation.h" +#include <private/qqmleventlocation_p.h> +#include <private/qqmlprofilerdefinitions_p.h> -#include <QtQml/private/qqmlprofilerdefinitions_p.h> #include <QObject> class QmlProfilerDataPrivate; @@ -54,7 +54,7 @@ public: explicit QmlProfilerData(QObject *parent = 0); ~QmlProfilerData(); - static QString getHashStringForQmlEvent(const QmlEventLocation &location, int eventType); + static QString getHashStringForQmlEvent(const QQmlEventLocation &location, int eventType); static QString qmlRangeTypeAsString(QQmlProfilerDefinitions::RangeType type); static QString qmlMessageAsString(QQmlProfilerDefinitions::Message type); @@ -75,13 +75,13 @@ public slots: void addQmlEvent(QQmlProfilerDefinitions::RangeType type, QQmlProfilerDefinitions::BindingType bindingType, qint64 startTime, qint64 duration, const QStringList &data, - const QmlEventLocation &location); + const QQmlEventLocation &location); void addFrameEvent(qint64 time, int framerate, int animationcount, int threadId); void addSceneGraphFrameEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time, qint64 numericData1, qint64 numericData2, qint64 numericData3, qint64 numericData4, qint64 numericData5); void addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time, - const QmlEventLocation &location, int width, int height, int refcount); + const QString &location, int numericData1, int numericData2); void addMemoryEvent(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 size); void addInputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b); |