From 57430b2bdad32150e0ed8ceb6893430363ee6670 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 17 Sep 2015 13:39:00 +0200 Subject: Move QML profiler client to qmldebug Change-Id: I506909b68be6cbad631d1645673c2d38460aed33 Reviewed-by: Simon Hausmann --- src/qmldebug/qmldebug.pro | 10 +- src/qmldebug/qqmleventlocation_p.h | 67 +++++++ src/qmldebug/qqmlprofilerclient.cpp | 356 ++++++++++++++++++++++++++++++++++ src/qmldebug/qqmlprofilerclient_p.h | 107 ++++++++++ src/qmldebug/qqmlprofilerclient_p_p.h | 64 ++++++ 5 files changed, 601 insertions(+), 3 deletions(-) create mode 100644 src/qmldebug/qqmleventlocation_p.h create mode 100644 src/qmldebug/qqmlprofilerclient.cpp create mode 100644 src/qmldebug/qqmlprofilerclient_p.h create mode 100644 src/qmldebug/qqmlprofilerclient_p_p.h (limited to 'src/qmldebug') 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 + +// +// 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 + +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::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 << expressions to be done in 64 bit, to silence some warnings + const quint64 one = static_cast(1); + + qint64 time; + int messageType; + + stream >> time >> messageType; + + if (messageType >= QQmlProfilerDefinitions::MaximumMessage) { + unknownEvent(static_cast(messageType), time, -1); + return; + } + + if (messageType == QQmlProfilerDefinitions::Event) { + int type; + stream >> type; + + QQmlProfilerDefinitions::EventType eventType = + static_cast(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(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(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(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(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(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 + +// +// 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/src/qmldebug/qqmlprofilerclient_p_p.h b/src/qmldebug/qqmlprofilerclient_p_p.h new file mode 100644 index 0000000000..c522eb7f52 --- /dev/null +++ b/src/qmldebug/qqmlprofilerclient_p_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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_P_H +#define QQMLPROFILERCLIENT_P_P_H + +#include "qqmlprofilerclient_p.h" +#include "qqmldebugclient_p_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 : public QQmlDebugClientPrivate +{ + Q_DECLARE_PUBLIC(QQmlProfilerClient) +public: + QQmlProfilerClientPrivate(QQmlDebugConnection *connection); + quint64 features; +}; + +QT_END_NAMESPACE + +#endif // QQMLPROFILERCLIENT_P_P_H + -- cgit v1.2.3