aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlprofiler/qmlprofilerclient.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-09-17 13:39:00 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-10-30 20:07:53 +0000
commit57430b2bdad32150e0ed8ceb6893430363ee6670 (patch)
tree73820f2c3696577b23595f30e5d11588a944447c /tools/qmlprofiler/qmlprofilerclient.cpp
parentcdb0ddeffd1bab0afd4c763e44431b11c8e8e0b0 (diff)
Move QML profiler client to qmldebug
Change-Id: I506909b68be6cbad631d1645673c2d38460aed33 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tools/qmlprofiler/qmlprofilerclient.cpp')
-rw-r--r--tools/qmlprofiler/qmlprofilerclient.cpp310
1 files changed, 116 insertions, 194 deletions
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();
}