More accurate timing for rendering thread
authorJiang Jiang <jiang.jiang@nokia.com>
Tue, 11 Oct 2011 09:10:41 +0000 (11:10 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 11 Oct 2011 12:21:53 +0000 (14:21 +0200)
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 <qt_sanity_bot@ovi.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>

src/declarative/items/qsgcanvas.cpp

index 09a13f4..9efd17a 100644 (file)
 
 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;