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 --- tools/qmlprofiler/qmlprofilerclient.cpp | 310 ++++++++++++-------------------- 1 file changed, 116 insertions(+), 194 deletions(-) (limited to 'tools/qmlprofiler/qmlprofilerclient.cpp') 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 #include #include @@ -39,43 +42,38 @@ #include -class QmlProfilerClientPrivate +class QmlProfilerClientPrivate : public QQmlProfilerClientPrivate { + Q_DECLARE_PUBLIC(QmlProfilerClient) public: - QmlProfilerClientPrivate() - : inProgressRanges(0) , features(std::numeric_limits::max()), enabled(false) - { - ::memset(rangeCount, 0, QQmlProfilerDefinitions::MaximumRangeType * sizeof(int)); - } + QmlProfilerClientPrivate(QQmlDebugConnection *connection, QmlProfilerData *data); + + QmlProfilerData *data; qint64 inProgressRanges; QStack rangeStartTimes[QQmlProfilerDefinitions::MaximumRangeType]; QStack rangeDatas[QQmlProfilerDefinitions::MaximumRangeType]; - QStack rangeLocations[QQmlProfilerDefinitions::MaximumRangeType]; + QStack 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 << 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) - 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(1) << type); + ++d->rangeCount[type]; +} - emit inputEvent(static_cast(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(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(1) << range); - ++d->rangeCount[range]; + --d->rangeCount[type]; + if (d->inProgressRanges & (static_cast(1) << type)) + d->inProgressRanges &= ~(static_cast(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(1) << range)) - d->inProgressRanges &= ~(static_cast(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(); } -- cgit v1.2.3