From a32bed7047469273cc8513cad7b2923d60f8d590 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 2 Jan 2014 18:07:32 +0100 Subject: [PATCH] Unify calls to profiler service event methods. Don't needlessly duplicate information about the profiler being available and allow inlining. Use macros to check availability of the profiler in calling code and generally simplify the code. Task-number: QTBUG-35315 Change-Id: I0a9daec4a95f74b9db795ef2918a01fb772ea107 Reviewed-by: Michael Brasser Reviewed-by: Simon Hausmann Reviewed-by: Kai Koehne --- src/qml/debugger/qqmlprofilerservice.cpp | 224 ++---------------- src/qml/debugger/qqmlprofilerservice_p.h | 205 ++++++++++------ src/quick/items/qquickview.cpp | 10 +- .../scenegraph/coreapi/qsgbatchrenderer.cpp | 16 +- src/quick/scenegraph/coreapi/qsgrenderer.cpp | 14 +- src/quick/scenegraph/qsgadaptationlayer.cpp | 12 +- src/quick/scenegraph/qsgrenderloop.cpp | 12 +- .../scenegraph/qsgthreadedrenderloop.cpp | 26 +- src/quick/scenegraph/qsgwindowsrenderloop.cpp | 39 ++- src/quick/scenegraph/util/qsgatlastexture.cpp | 16 +- src/quick/scenegraph/util/qsgtexture.cpp | 26 +- src/quick/util/qquickpixmapcache.cpp | 32 +-- 12 files changed, 238 insertions(+), 394 deletions(-) diff --git a/src/qml/debugger/qqmlprofilerservice.cpp b/src/qml/debugger/qqmlprofilerservice.cpp index 03bf46454..b294e2e14 100644 --- a/src/qml/debugger/qqmlprofilerservice.cpp +++ b/src/qml/debugger/qqmlprofilerservice.cpp @@ -47,9 +47,6 @@ #include #include -// this contains QUnifiedTimer -#include - 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,192 +160,34 @@ 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 */ diff --git a/src/qml/debugger/qqmlprofilerservice_p.h b/src/qml/debugger/qqmlprofilerservice_p.h index 1261597f1..6de24c188 100644 --- a/src/qml/debugger/qqmlprofilerservice_p.h +++ b/src/qml/debugger/qqmlprofilerservice_p.h @@ -55,6 +55,8 @@ #include #include +// this contains QUnifiedTimer +#include #include #include @@ -63,6 +65,11 @@ #include #include +#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 diff --git a/src/quick/items/qquickview.cpp b/src/quick/items/qquickview.cpp index 96146ec55..f78ba3520 100644 --- a/src/quick/items/qquickview.cpp +++ b/src/quick/items/qquickview.cpp @@ -603,7 +603,7 @@ void QQuickView::resizeEvent(QResizeEvent *e) /*! \reimp */ void QQuickView::keyPressEvent(QKeyEvent *e) { - QQmlProfilerService::addEvent(QQmlProfilerService::Key); + Q_QML_PROFILE(addEvent(QQmlProfilerService::Key)); QQuickWindow::keyPressEvent(e); } @@ -611,7 +611,7 @@ void QQuickView::keyPressEvent(QKeyEvent *e) /*! \reimp */ void QQuickView::keyReleaseEvent(QKeyEvent *e) { - QQmlProfilerService::addEvent(QQmlProfilerService::Key); + Q_QML_PROFILE(addEvent(QQmlProfilerService::Key)); QQuickWindow::keyReleaseEvent(e); } @@ -619,7 +619,7 @@ void QQuickView::keyReleaseEvent(QKeyEvent *e) /*! \reimp */ void QQuickView::mouseMoveEvent(QMouseEvent *e) { - QQmlProfilerService::addEvent(QQmlProfilerService::Mouse); + Q_QML_PROFILE(addEvent(QQmlProfilerService::Mouse)); QQuickWindow::mouseMoveEvent(e); } @@ -627,7 +627,7 @@ void QQuickView::mouseMoveEvent(QMouseEvent *e) /*! \reimp */ void QQuickView::mousePressEvent(QMouseEvent *e) { - QQmlProfilerService::addEvent(QQmlProfilerService::Mouse); + Q_QML_PROFILE(addEvent(QQmlProfilerService::Mouse)); QQuickWindow::mousePressEvent(e); } @@ -635,7 +635,7 @@ void QQuickView::mousePressEvent(QMouseEvent *e) /*! \reimp */ void QQuickView::mouseReleaseEvent(QMouseEvent *e) { - QQmlProfilerService::addEvent(QQmlProfilerService::Mouse); + Q_QML_PROFILE(addEvent(QQmlProfilerService::Mouse)); QQuickWindow::mouseReleaseEvent(e); } diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index eff815833..297bea6e6 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -171,11 +171,9 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material) if (qsg_render_timing) qDebug(" - compiling material: %dms", (int) qsg_renderer_timer.elapsed()); - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphContextFrame, - qsg_renderer_timer.nsecsElapsed()); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphContextFrame, + qsg_renderer_timer.nsecsElapsed())); #endif rewrittenShaders[type] = shader; @@ -210,11 +208,9 @@ ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *mate if (qsg_render_timing) qDebug(" - compiling material: %dms", (int) qsg_renderer_timer.elapsed()); - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphContextFrame, - qsg_renderer_timer.nsecsElapsed()); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphContextFrame, + qsg_renderer_timer.nsecsElapsed())); #endif return shader; diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp index e35bfe549..44b80df15 100644 --- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp @@ -287,14 +287,12 @@ void QSGRenderer::renderScene(const QSGBindable &bindable) int(renderTime / 1000000)); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphRendererFrame, - preprocessTime, - updatePassTime - preprocessTime, - bindTime - updatePassTime, - renderTime - bindTime); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphRendererFrame, + preprocessTime, + updatePassTime - preprocessTime, + bindTime - updatePassTime, + renderTime - bindTime)); #endif } diff --git a/src/quick/scenegraph/qsgadaptationlayer.cpp b/src/quick/scenegraph/qsgadaptationlayer.cpp index cb9e4bdf8..8798208ea 100644 --- a/src/quick/scenegraph/qsgadaptationlayer.cpp +++ b/src/quick/scenegraph/qsgadaptationlayer.cpp @@ -196,13 +196,11 @@ void QSGDistanceFieldGlyphCache::update() (int) qsg_render_timer.elapsed()); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphAdaptationLayerFrame, - count, - renderTime, - qsg_render_timer.nsecsElapsed() - renderTime); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphAdaptationLayerFrame, + count, + renderTime, + qsg_render_timer.nsecsElapsed() - renderTime)); #endif } diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp index ac1bdb784..facb11d27 100644 --- a/src/quick/scenegraph/qsgrenderloop.cpp +++ b/src/quick/scenegraph/qsgrenderloop.cpp @@ -342,13 +342,11 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window) lastFrameTime = QTime::currentTime(); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphRenderLoopFrame, - syncTime, - renderTime, - swapTime); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphRenderLoopFrame, + syncTime, + renderTime, + swapTime)); // Might have been set during syncSceneGraph() if (data.updatePending) diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index d8fe94712..98a88a854 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -609,13 +609,11 @@ void QSGRenderThread::syncAndRender() int((renderTime - syncTime)/1000000), int(threadTimer.elapsed() - renderTime/1000000)); - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphRenderLoopFrame, - syncTime, - renderTime - syncTime, - threadTimer.nsecsElapsed() - renderTime); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphRenderLoopFrame, + syncTime, + renderTime - syncTime, + threadTimer.nsecsElapsed() - renderTime)); #endif } @@ -1143,14 +1141,12 @@ void QSGThreadedRenderLoop::polishAndSync(Window *w) int((syncTime - waitTime)/1000000), int((timer.nsecsElapsed() - syncTime)/1000000)); - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphPolishAndSync, - polishTime, - waitTime - polishTime, - syncTime - waitTime, - timer.nsecsElapsed() - syncTime); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphPolishAndSync, + polishTime, + waitTime - polishTime, + syncTime - waitTime, + timer.nsecsElapsed() - syncTime)); #endif } diff --git a/src/quick/scenegraph/qsgwindowsrenderloop.cpp b/src/quick/scenegraph/qsgwindowsrenderloop.cpp index 5d9583caf..14569788b 100644 --- a/src/quick/scenegraph/qsgwindowsrenderloop.cpp +++ b/src/quick/scenegraph/qsgwindowsrenderloop.cpp @@ -202,13 +202,11 @@ void QSGWindowsRenderLoop::show(QQuickWindow *window) int((time_current - time_created)/1000000), int((qsg_render_timer.nsecsElapsed() - time_current)/1000000)); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphWindowsRenderShow, - time_created - time_start, - time_current - time_created, - qsg_render_timer.nsecsElapsed() - time_current); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphWindowsRenderShow, + time_created - time_start, + time_current - time_created, + qsg_render_timer.nsecsElapsed() - time_current)); #endif } @@ -407,11 +405,9 @@ void QSGWindowsRenderLoop::render() qDebug("WindowsRenderLoop: animations=%d ms", int((qsg_render_timer.nsecsElapsed() - time_start)/1000000)); } - if (QQmlProfilerService::Enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphWindowsAnimations, - qsg_render_timer.nsecsElapsed() - time_start); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphWindowsAnimations, + qsg_render_timer.nsecsElapsed() - time_start)); #endif // It is not given that animations triggered another maybeUpdate() @@ -473,19 +469,12 @@ void QSGWindowsRenderLoop::renderWindow(QQuickWindow *window) int((time_rendered - time_synced)/1000000), int((time_swapped - time_rendered)/1000000)); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphWindowsPolishFrame, - time_polished - time_start - ); - - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphRenderLoopFrame, - time_synced - time_polished, - time_rendered - time_synced, - time_swapped - time_rendered - ); - } + Q_QML_PROFILE(sceneGraphFrame(QQmlProfilerService::SceneGraphWindowsPolishFrame, + time_polished - time_start)); + Q_QML_PROFILE(sceneGraphFrame(QQmlProfilerService::SceneGraphRenderLoopFrame, + time_synced - time_polished, + time_rendered - time_synced, + time_swapped - time_rendered)); #endif } diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp index 389945849..0fce410b6 100644 --- a/src/quick/scenegraph/util/qsgatlastexture.cpp +++ b/src/quick/scenegraph/util/qsgatlastexture.cpp @@ -381,15 +381,13 @@ bool Atlas::bind(QSGTexture::Filtering filtering) (int) (qsg_renderer_timer.elapsed())); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphTexturePrepare, - 0, // bind (not relevant) - 0, // convert (not relevant) - 0, // swizzle (not relevant) - qsg_renderer_timer.nsecsElapsed(), // (upload all of the above) - 0); // mipmap (not used ever...) - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphTexturePrepare, + 0, // bind (not relevant) + 0, // convert (not relevant) + 0, // swizzle (not relevant) + qsg_renderer_timer.nsecsElapsed(), // (upload all of the above) + 0)); // mipmap (not used ever...) #endif } diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp index df724d8a0..4243e7184 100644 --- a/src/quick/scenegraph/util/qsgtexture.cpp +++ b/src/quick/scenegraph/util/qsgtexture.cpp @@ -634,11 +634,9 @@ void QSGPlainTexture::bind() m_texture_size.width(), m_texture_size.height()); } - if (QQmlProfilerService::enabled) { - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphTextureDeletion, - qsg_renderer_timer.nsecsElapsed()); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphTextureDeletion, + qsg_renderer_timer.nsecsElapsed())); #endif } m_texture_id = 0; @@ -738,17 +736,13 @@ void QSGPlainTexture::bind() } - if (QQmlProfilerService::enabled) { - mipmapTime = qsg_renderer_timer.nsecsElapsed(); - - QQmlProfilerService::sceneGraphFrame( - QQmlProfilerService::SceneGraphTexturePrepare, - bindTime, - convertTime - bindTime, - swizzleTime - convertTime, - uploadTime - swizzleTime, - mipmapTime - uploadTime); - } + Q_QML_PROFILE(sceneGraphFrame( + QQmlProfilerService::SceneGraphTexturePrepare, + bindTime, + convertTime - bindTime, + swizzleTime - convertTime, + uploadTime - swizzleTime, + qsg_renderer_timer.nsecsElapsed() - uploadTime)); #endif diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 055d6b7e2..0260bd168 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -519,8 +519,7 @@ void QQuickPixmapReader::processJobs() runningJob->loading = true; QUrl url = runningJob->url; - QQmlPixmapProfiler pixmapProfiler; - pixmapProfiler.startLoading(url); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapLoadingStarted, url)); QSize requestSize = runningJob->requestSize; locker.unlock(); @@ -895,14 +894,14 @@ bool QQuickPixmapReply::event(QEvent *event) if (data) { Event *de = static_cast(event); data->pixmapStatus = (de->error == NoError) ? QQuickPixmap::Ready : QQuickPixmap::Error; - QQmlPixmapProfiler pixmapProfiler; if (data->pixmapStatus == QQuickPixmap::Ready) { - pixmapProfiler.finishLoading(data->url); data->textureFactory = de->textureFactory; data->implicitSize = de->implicitSize; - pixmapProfiler.setSize(url, data->requestSize.width() > 0 ? data->requestSize : data->implicitSize); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapLoadingFinished, data->url)); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapSizeKnown, url, + data->requestSize.width() > 0 ? data->requestSize : data->implicitSize)); } else { - pixmapProfiler.errorLoading(data->url); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapLoadingError, data->url)); data->errorString = de->errorString; data->removeFromCache(); // We don't continue to cache error'd pixmaps } @@ -928,7 +927,7 @@ int QQuickPixmapData::cost() const void QQuickPixmapData::addref() { ++refCount; - QQmlPixmapProfiler().referenceCountChanged(url, refCount); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapReferenceCountChanged, url, refCount)); if (prevUnreferencedPtr) pixmapStore()->referencePixmap(this); } @@ -937,7 +936,7 @@ void QQuickPixmapData::release() { Q_ASSERT(refCount > 0); --refCount; - QQmlPixmapProfiler().referenceCountChanged(url, refCount); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapReferenceCountChanged, url, refCount)); if (refCount == 0) { if (reply) { QQuickPixmapReply *cancelReply = reply; @@ -968,8 +967,8 @@ void QQuickPixmapData::addToCache() QQuickPixmapKey key = { &url, &requestSize }; pixmapStore()->m_cache.insert(key, this); inCache = true; - QQmlPixmapProfiler pixmapProfiler; - pixmapProfiler.cacheCountChanged(url, pixmapStore()->m_cache.count()); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapCacheCountChanged, + url, pixmapStore()->m_cache.count())); } } @@ -977,7 +976,8 @@ void QQuickPixmapData::removeFromCache() { if (inCache) { QQuickPixmapKey key = { &url, &requestSize }; - QQmlPixmapProfiler().cacheCountChanged(url, pixmapStore()->m_cache.count()); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapCacheCountChanged, + url, pixmapStore()->m_cache.count())); pixmapStore()->m_cache.remove(key); inCache = false; } @@ -1240,18 +1240,18 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques if (!(options & QQuickPixmap::Asynchronous)) { bool ok = false; - QQmlPixmapProfiler pixmapProfiler; - pixmapProfiler.startLoading(url); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapLoadingStarted, url)); d = createPixmapDataSync(this, engine, url, requestSize, &ok); if (ok) { - pixmapProfiler.finishLoading(url); - pixmapProfiler.setSize(url, d->requestSize.width() > 0 ? d->requestSize : d->implicitSize); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapLoadingFinished, url)); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapSizeKnown, url, + d->requestSize.width() > 0 ? d->requestSize : d->implicitSize)); if (options & QQuickPixmap::Cache) d->addToCache(); return; } if (d) { // loadable, but encountered error while loading - pixmapProfiler.errorLoading(url); + Q_QML_PROFILE(pixmapEvent(QQmlProfilerService::PixmapLoadingError, url)); return; } } -- 2.34.1