aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/debugger
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/debugger')
-rw-r--r--src/qml/debugger/qqmlprofilerservice.cpp224
-rw-r--r--src/qml/debugger/qqmlprofilerservice_p.h205
2 files changed, 153 insertions, 276 deletions
diff --git a/src/qml/debugger/qqmlprofilerservice.cpp b/src/qml/debugger/qqmlprofilerservice.cpp
index 03bf464542..b294e2e140 100644
--- a/src/qml/debugger/qqmlprofilerservice.cpp
+++ b/src/qml/debugger/qqmlprofilerservice.cpp
@@ -47,9 +47,6 @@
#include <QtCore/qthread.h>
#include <QtCore/qcoreapplication.h>
-// this contains QUnifiedTimer
-#include <private/qabstractanimation_p.h>
-
QT_BEGIN_NAMESPACE
// instance will be set, unset in constructor. Allows static methods to be inlined.
@@ -114,6 +111,11 @@ QByteArray QQmlProfilerData::toByteArray() const
return data;
}
+void QQmlProfilerService::animationTimerCallback(qint64 delta)
+{
+ Q_QML_PROFILE(animationFrame(delta));
+}
+
QQmlProfilerService::QQmlProfilerService()
: QQmlDebugService(QStringLiteral("CanvasFrameRate"), 1)
{
@@ -123,7 +125,7 @@ QQmlProfilerService::QQmlProfilerService()
QMutexLocker lock(&m_initializeMutex);
if (registerService() == Enabled) {
- QUnifiedTimer::instance()->registerProfilerCallback(&animationFrame);
+ QUnifiedTimer::instance()->registerProfilerCallback(&animationTimerCallback);
if (blockingMode())
m_initializeCondition.wait(&m_initializeMutex);
}
@@ -151,26 +153,6 @@ bool QQmlProfilerService::stopProfiling()
return profilerInstance()->stopProfilingImpl();
}
-void QQmlProfilerService::sendStartedProfilingMessage()
-{
- profilerInstance()->sendStartedProfilingMessageImpl();
-}
-
-void QQmlProfilerService::addEvent(EventType t)
-{
- profilerInstance()->addEventImpl(t);
-}
-
-void QQmlProfilerService::animationFrame(qint64 delta)
-{
- profilerInstance()->animationFrameImpl(delta);
-}
-
-void QQmlProfilerService::sceneGraphFrame(SceneGraphFrameType frameType, qint64 value1, qint64 value2, qint64 value3, qint64 value4, qint64 value5)
-{
- profilerInstance()->sceneGraphFrameImpl(frameType, value1, value2, value3, value4, value5);
-}
-
void QQmlProfilerService::sendProfilingData()
{
profilerInstance()->sendMessages();
@@ -178,193 +160,35 @@ void QQmlProfilerService::sendProfilingData()
bool QQmlProfilerService::startProfilingImpl()
{
- bool success = false;
- if (QQmlDebugService::isDebuggingEnabled() && !profilingEnabled()) {
- setProfilingEnabled(true);
- sendStartedProfilingMessageImpl();
- success = true;
+ if (QQmlDebugService::isDebuggingEnabled() && !enabled) {
+ enabled = true;
+ QQmlProfilerData ed = {m_timer.nsecsElapsed(), (int)Event, (int)StartTrace,
+ QString(), -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ QQmlDebugService::sendMessage(ed.toByteArray());
+ return true;
+ } else {
+ return false;
}
- return success;
}
bool QQmlProfilerService::stopProfilingImpl()
{
- bool success = false;
- if (profilingEnabled()) {
- addEventImpl(EndTrace);
- setProfilingEnabled(false);
- success = true;
- }
- return success;
-}
-
-void QQmlProfilerService::sendStartedProfilingMessageImpl()
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData ed = {m_timer.nsecsElapsed(), (int)Event, (int)StartTrace,
- QString(), -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0};
- QQmlDebugService::sendMessage(ed.toByteArray());
-}
-
-void QQmlProfilerService::addEventImpl(EventType event)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData ed = {m_timer.nsecsElapsed(), (int)Event, (int)event,
- QString(), -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0};
- processMessage(ed);
-}
-
-void QQmlProfilerService::startRange(RangeType range, BindingType bindingType)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)RangeStart, (int)range,
- QString(), -1, -1, 0, 0, (int)bindingType,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::rangeData(RangeType range, const QString &rData)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)RangeData, (int)range,
- rData, -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::rangeData(RangeType range, const QUrl &rData)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)RangeData, (int)range,
- rData.toString(), -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::rangeLocation(RangeType range, const QString &fileName, int line, int column)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)RangeLocation, (int)range,
- fileName, line, column, 0, 0, 0,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::rangeLocation(RangeType range, const QUrl &fileName, int line, int column)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)RangeLocation, (int)range,
- fileName.toString(), line, column, 0, 0, 0,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::endRange(RangeType range)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)RangeEnd, (int)range,
- QString(), -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::pixmapEventImpl(PixmapEventType eventType, const QUrl &url)
-{
- // assuming enabled checked by caller
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)PixmapCacheEvent, (int)eventType,
- url.toString(), -1, -1, -1, -1, -1,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int width, int height)
-{
- // assuming enabled checked by caller
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)PixmapCacheEvent, (int)eventType,
- url.toString(), width, height, -1, -1, -1,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int count)
-{
- // assuming enabled checked by caller
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)PixmapCacheEvent, (int)eventType,
- url.toString(), -1, -1, -1, count, -1,
- 0, 0, 0, 0, 0};
- processMessage(rd);
-}
-
-void QQmlProfilerService::sceneGraphFrameImpl(SceneGraphFrameType frameType, qint64 value1, qint64 value2, qint64 value3, qint64 value4, qint64 value5)
-{
- if (!QQmlDebugService::isDebuggingEnabled() || !enabled)
- return;
-
- // because I already have some space to store ints in the struct, I'll use it to store the frame data
- // even though the field names do not match
- QQmlProfilerData rd = {m_timer.nsecsElapsed(), (int)SceneGraphFrame, (int)frameType, QString(),
- -1, -1, -1, -1, -1,
- value1, value2, value3, value4, value5};
- processMessage(rd);
-}
-
-void QQmlProfilerService::animationFrameImpl(qint64 delta)
-{
- Q_ASSERT(QQmlDebugService::isDebuggingEnabled());
- if (!enabled)
- return;
-
- int animCount = QUnifiedTimer::instance()->runningAnimationCount();
-
- if (animCount > 0 && delta > 0) {
- // trim fps to integer
- int fps = 1000 / delta;
- QQmlProfilerData ed = {m_timer.nsecsElapsed(), (int)Event, (int)AnimationFrame,
- QString(), -1, -1, fps, animCount, 0,
+ if (enabled) {
+ enabled = false;
+ // We cannot use instance here as this is called from the debugger thread.
+ // It may be called before the QML engine (and the profiler) is ready.
+ QQmlProfilerData ed = {m_timer.nsecsElapsed(), (int)Event, (int)EndTrace,
+ QString(), -1, -1, 0, 0, 0,
0, 0, 0, 0, 0};
processMessage(ed);
+ return true;
+ } else {
+ return false;
}
}
/*
- Either send the message directly, or queue up
- a list of messages to send later (via sendMessages)
-*/
-void QQmlProfilerService::processMessage(const QQmlProfilerData &message)
-{
- QMutexLocker locker(&m_dataMutex);
- m_data.append(message);
-}
-
-bool QQmlProfilerService::profilingEnabled()
-{
- return enabled;
-}
-
-void QQmlProfilerService::setProfilingEnabled(bool enable)
-{
- enabled = enable;
-}
-
-/*
Send the messages queued up by processMessage
*/
void QQmlProfilerService::sendMessages()
diff --git a/src/qml/debugger/qqmlprofilerservice_p.h b/src/qml/debugger/qqmlprofilerservice_p.h
index 1261597f1e..6de24c188c 100644
--- a/src/qml/debugger/qqmlprofilerservice_p.h
+++ b/src/qml/debugger/qqmlprofilerservice_p.h
@@ -55,6 +55,8 @@
#include <private/qqmldebugservice_p.h>
#include <private/qqmlboundsignal_p.h>
+// this contains QUnifiedTimer
+#include <private/qabstractanimation_p.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qmetaobject.h>
@@ -63,6 +65,11 @@
#include <QtCore/qstringbuilder.h>
#include <QtCore/qwaitcondition.h>
+#define Q_QML_PROFILE(Method)\
+ if (QQmlProfilerService::enabled) {\
+ QQmlProfilerService::Method;\
+ } else\
+ (void)0
QT_BEGIN_NAMESPACE
@@ -170,13 +177,66 @@ public:
static bool startProfiling();
static bool stopProfiling();
- static void sendStartedProfilingMessage();
- static bool profilingEnabled();
- static void addEvent(EventType);
- static void animationFrame(qint64);
+ static void addEvent(EventType event)
+ {
+ QQmlProfilerData ed = {instance->m_timer.nsecsElapsed(), (int)Event, (int)event,
+ QString(), -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(ed);
+ }
+
+ static void animationFrame(qint64 delta)
+ {
+ int animCount = QUnifiedTimer::instance()->runningAnimationCount();
+
+ if (animCount > 0 && delta > 0) {
+ QQmlProfilerData ed = {instance->m_timer.nsecsElapsed(), (int)Event,
+ (int)AnimationFrame, QString(), -1, -1,
+ 1000 / (int)delta /* trim fps to integer */, animCount, 0, 0, 0,
+ 0, 0, 0};
+ instance->processMessage(ed);
+ }
+ }
+
+ static void sceneGraphFrame(SceneGraphFrameType frameType, qint64 value1, qint64 value2 = -1,
+ qint64 value3 = -1, qint64 value4 = -1, qint64 value5 = -1)
+ {
+ // because I already have some space to store ints in the struct, I'll use it to store the
+ // frame data even though the field names do not match
+ QQmlProfilerData ed = {instance->m_timer.nsecsElapsed(), (int)SceneGraphFrame,
+ (int)frameType, QString(), -1, -1, -1, -1, -1,
+ value1, value2, value3, value4, value5};
+ instance->processMessage(ed);
+ }
+
+ static void pixmapEvent(PixmapEventType eventType, const QUrl &url)
+ {
+ QQmlProfilerData ed = {instance->m_timer.nsecsElapsed(), (int)PixmapCacheEvent,
+ (int)eventType, url.toString(), -1, -1, -1, -1, -1,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(ed);
+ }
+
+ static void pixmapEvent(PixmapEventType eventType, const QUrl &url, int count)
+ {
+ QQmlProfilerData ed = {instance->m_timer.nsecsElapsed(), (int)PixmapCacheEvent,
+ (int)eventType, url.toString(), -1, -1, -1, count, -1,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(ed);
+ }
+
+ static void pixmapEvent(PixmapEventType eventType, const QUrl &url, const QSize &size)
+ {
+ if (size.width() > 0 && size.height() > 0) {
+ QQmlProfilerData ed = {instance->m_timer.nsecsElapsed(), (int)PixmapCacheEvent,
+ (int)eventType, url.toString(),
+ size.width(), size.height(), -1, -1, -1,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(ed);
+ }
+ }
- static void sceneGraphFrame(SceneGraphFrameType frameType, qint64 value1, qint64 value2 = -1, qint64 value3 = -1, qint64 value4 = -1, qint64 value5 = -1);
static void sendProfilingData();
QQmlProfilerService();
@@ -189,28 +249,64 @@ protected:
private:
bool startProfilingImpl();
bool stopProfilingImpl();
- void sendStartedProfilingMessageImpl();
- void addEventImpl(EventType);
- void animationFrameImpl(qint64);
- void startRange(RangeType, BindingType bindingType = QmlBinding);
- void rangeData(RangeType, const QString &);
- void rangeData(RangeType, const QUrl &);
- void rangeLocation(RangeType, const QString &, int, int);
- void rangeLocation(RangeType, const QUrl &, int, int);
- void endRange(RangeType);
+ static void startRange(RangeType range, BindingType bindingType = QmlBinding)
+ {
+ QQmlProfilerData rd = {instance->m_timer.nsecsElapsed(), (int)RangeStart, (int)range,
+ QString(), -1, -1, 0, 0, (int)bindingType,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(rd);
+ }
+
+ static void rangeData(RangeType range, const QString &rData)
+ {
+ QQmlProfilerData rd = {instance->m_timer.nsecsElapsed(), (int)RangeData, (int)range,
+ rData, -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(rd);
+ }
+
+ static void rangeData(RangeType range, const QUrl &rData)
+ {
+ QQmlProfilerData rd = {instance->m_timer.nsecsElapsed(), (int)RangeData, (int)range,
+ rData.toString(), -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(rd);
+ }
- // overloading depending on parameters
- void pixmapEventImpl(PixmapEventType eventType, const QUrl &url);
- void pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int width, int height);
- void pixmapEventImpl(PixmapEventType eventType, const QUrl &url, int count);
+ static void rangeLocation(RangeType range, const QString &fileName, int line, int column)
+ {
+ QQmlProfilerData rd = {instance->m_timer.nsecsElapsed(), (int)RangeLocation, (int)range,
+ fileName, line, column, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(rd);
+ }
- void sceneGraphFrameImpl(SceneGraphFrameType frameType, qint64 value1, qint64 value2, qint64 value3, qint64 value4, qint64 value5);
+ static void rangeLocation(RangeType range, const QUrl &fileName, int line, int column)
+ {
+ QQmlProfilerData rd = {instance->m_timer.nsecsElapsed(), (int)RangeLocation, (int)range,
+ fileName.toString(), line, column, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(rd);
+ }
+ static void endRange(RangeType range)
+ {
+ QQmlProfilerData rd = {instance->m_timer.nsecsElapsed(), (int)RangeEnd, (int)range,
+ QString(), -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0};
+ instance->processMessage(rd);
+ }
- void setProfilingEnabled(bool enable);
void sendMessages();
- void processMessage(const QQmlProfilerData &);
+
+ void processMessage(const QQmlProfilerData &message)
+ {
+ QMutexLocker locker(&m_dataMutex);
+ m_data.append(message);
+ }
+
+ static void animationTimerCallback(qint64 delta);
public:
static bool enabled;
@@ -227,7 +323,6 @@ private:
friend struct QQmlHandlingSignalProfiler;
friend struct QQmlVmeProfiler;
friend struct QQmlCompilingProfiler;
- friend struct QQmlPixmapProfiler;
};
//
@@ -237,51 +332,42 @@ private:
struct QQmlBindingProfiler {
QQmlBindingProfiler(const QString &url, int line, int column, QQmlProfilerService::BindingType bindingType)
{
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->startRange(QQmlProfilerService::Binding, bindingType);
- QQmlProfilerService::instance->rangeLocation(QQmlProfilerService::Binding, url, line, column);
- }
+ Q_QML_PROFILE(startRange(QQmlProfilerService::Binding, bindingType));
+ Q_QML_PROFILE(rangeLocation(QQmlProfilerService::Binding, url, line, column));
}
~QQmlBindingProfiler()
{
- if (QQmlProfilerService::enabled)
- QQmlProfilerService::instance->endRange(QQmlProfilerService::Binding);
+ Q_QML_PROFILE(endRange(QQmlProfilerService::Binding));
}
};
struct QQmlHandlingSignalProfiler {
QQmlHandlingSignalProfiler(QQmlBoundSignalExpression *expression)
{
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->startRange(QQmlProfilerService::HandlingSignal);
- QQmlProfilerService::instance->rangeLocation(QQmlProfilerService::HandlingSignal,
- expression->sourceFile(), expression->lineNumber(),
- expression->columnNumber());
- }
+ Q_QML_PROFILE(startRange(QQmlProfilerService::HandlingSignal));
+ Q_QML_PROFILE(rangeLocation(QQmlProfilerService::HandlingSignal,
+ expression->sourceFile(), expression->lineNumber(),
+ expression->columnNumber()));
}
~QQmlHandlingSignalProfiler()
{
- if (QQmlProfilerService::enabled)
- QQmlProfilerService::instance->endRange(QQmlProfilerService::HandlingSignal);
+ Q_QML_PROFILE(endRange(QQmlProfilerService::HandlingSignal));
}
};
struct QQmlCompilingProfiler {
QQmlCompilingProfiler(const QString &name)
{
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->startRange(QQmlProfilerService::Compiling);
- QQmlProfilerService::instance->rangeLocation(QQmlProfilerService::Compiling, name, 1, 1);
- QQmlProfilerService::instance->rangeData(QQmlProfilerService::Compiling, name);
- }
+ Q_QML_PROFILE(startRange(QQmlProfilerService::Compiling));
+ Q_QML_PROFILE(rangeLocation(QQmlProfilerService::Compiling, name, 1, 1));
+ Q_QML_PROFILE(rangeData(QQmlProfilerService::Compiling, name));
}
~QQmlCompilingProfiler()
{
- if (QQmlProfilerService::enabled)
- QQmlProfilerService::instance->endRange(QQmlProfilerService::Compiling);
+ Q_QML_PROFILE(endRange(QQmlProfilerService::Compiling));
}
};
@@ -414,39 +500,6 @@ private:
bool running;
};
-struct QQmlPixmapProfiler {
- void startLoading(const QUrl &pixmapUrl) {
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingStarted, pixmapUrl);
- }
- }
- void finishLoading(const QUrl &pixmapUrl) {
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingFinished, pixmapUrl);
- }
- }
- void errorLoading(const QUrl &pixmapUrl) {
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapLoadingError, pixmapUrl);
- }
- }
- void cacheCountChanged(const QUrl &pixmapUrl, int cacheCount) {
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapCacheCountChanged, pixmapUrl, cacheCount);
- }
- }
- void referenceCountChanged(const QUrl &pixmapUrl, int referenceCount) {
- if (QQmlProfilerService::enabled) {
- QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapReferenceCountChanged, pixmapUrl, referenceCount);
- }
- }
- void setSize(const QUrl &pixmapUrl, const QSize &size) {
- if (QQmlProfilerService::enabled && size.width() > 0) {
- QQmlProfilerService::instance->pixmapEventImpl(QQmlProfilerService::PixmapSizeKnown, pixmapUrl, size.width(), size.height());
- }
- }
-};
-
QT_END_NAMESPACE
#endif // QQMLPROFILERSERVICE_P_H