From f41753f034343ef5c2daaa27a2b0961b98bef151 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Tue, 11 Oct 2011 11:10:41 +0200 Subject: [PATCH] More accurate timing for rendering thread To get a better overview of how much time we consumed rendering each frame, setting QElapsedTimer around each loop in the rendering thread. It can be turned on with QML_CANVAS_TIMING=1 environment variable. Change-Id: I81a231983e5f7d898589d5fe18782dd5c7e8e0dc Reviewed-on: http://codereview.qt-project.org/6420 Sanity-Review: Qt Sanity Bot Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/declarative/items/qsgcanvas.cpp | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 09a13f4..9efd17a 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -64,6 +64,15 @@ QT_BEGIN_NAMESPACE +#define QSG_CANVAS_TIMING +#ifdef QSG_CANVAS_TIMING +static bool qsg_canvas_timing = !qgetenv("QML_CANVAS_TIMING").isEmpty(); +static QTime threadTimer; +static int syncTime; +static int renderTime; +static int swapTime; +#endif + DEFINE_BOOL_CONFIG_OPTION(qmlFixedAnimationStep, QML_FIXED_ANIMATION_STEP) DEFINE_BOOL_CONFIG_OPTION(qmlNoThreadedRenderer, QML_BAD_GUI_RENDER_LOOP) @@ -1943,7 +1952,6 @@ void QSGCanvasRenderLoop::createGLContext() gl->create(); } - void QSGCanvasRenderThread::run() { #ifdef THREAD_DEBUG @@ -1995,6 +2003,10 @@ void QSGCanvasRenderThread::run() #ifdef THREAD_DEBUG printf(" RenderThread: Doing locked sync\n"); #endif +#ifdef QSG_CANVAS_TIMING + if (qsg_canvas_timing) + threadTimer.start(); +#endif inSync = true; syncSceneGraph(); inSync = false; @@ -2006,14 +2018,20 @@ void QSGCanvasRenderThread::run() #ifdef THREAD_DEBUG printf(" RenderThread: sync done\n"); #endif - - +#ifdef QSG_CANVAS_TIMING + if (qsg_canvas_timing) + syncTime = threadTimer.elapsed(); +#endif #ifdef THREAD_DEBUG printf(" RenderThread: rendering... %d x %d\n", windowSize.width(), windowSize.height()); #endif renderSceneGraph(windowSize); +#ifdef QSG_CANVAS_TIMING + if (qsg_canvas_timing) + renderTime = threadTimer.elapsed() - syncTime; +#endif // The content of the target buffer is undefined after swap() so grab needs // to happen before swap(); @@ -2033,6 +2051,14 @@ void QSGCanvasRenderThread::run() #ifdef THREAD_DEBUG printf(" RenderThread: swap complete...\n"); #endif +#ifdef QSG_CANVAS_TIMING + if (qsg_canvas_timing) { + swapTime = threadTimer.elapsed() - renderTime; + qDebug() << "- Breakdown of frame time: sync:" << syncTime + << "ms render:" << renderTime << "ms swap:" << swapTime + << "ms total:" << swapTime + renderTime << "ms"; + } +#endif lock(); isPaintCompleted = true; -- 1.7.2.5