From 44fe91d5ddc7c015dae12c6cc1504b56a4a0e778 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Thu, 19 Mar 2015 15:44:11 -0400 Subject: [PATCH] implement fps log display within ShmRenderer You need to uncomment the #define DEBUG_FPS line in shmrenderer code to enable logging. Refs #68901 --- src/private/shmrenderer.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/private/shmrenderer.cpp b/src/private/shmrenderer.cpp index f8737d12..d35243f7 100644 --- a/src/private/shmrenderer.cpp +++ b/src/private/shmrenderer.cpp @@ -40,6 +40,11 @@ #include "video/resolution.h" #include "private/videorenderer_p.h" +//#define DEBUG_FPS +#ifdef DEBUG_FPS +#include <chrono> +#endif + ///Shared memory object struct SHMHeader { sem_t notification; @@ -75,6 +80,11 @@ public: int m_Fps ; QTime m_CurrentTime; +#ifdef DEBUG_FPS + unsigned m_frameCount; + std::chrono::time_point<std::chrono::system_clock> m_lastFrameDebug; +#endif + //Constants static const int TIMEOUT_SEC = 1; // 1 second @@ -97,6 +107,10 @@ Video::ShmRendererPrivate::ShmRendererPrivate(Video::ShmRenderer* parent) : QObj fd(-1),m_fpsC(0),m_Fps(0), m_pShmArea((SHMHeader*)MAP_FAILED), m_ShmAreaLen(0), m_BufferGen(0), m_pTimer(nullptr) +#ifdef DEBUG_FPS + , m_frameCount(0) + , m_lastFrameDebug(std::chrono::system_clock::now()) +#endif { } @@ -163,6 +177,17 @@ bool Video::ShmRendererPrivate::renderToBitmap() static_cast<Video::Renderer*>(q_ptr)->d_ptr->updateFrameIndex(); shmUnlock(); +#ifdef DEBUG_FPS + auto currentTime = std::chrono::system_clock::now(); + const std::chrono::duration<double> seconds = currentTime - m_lastFrameDebug; + ++m_frameCount; + if (seconds.count() > 1) { + qDebug() << this << ": FPS " << (m_frameCount / seconds.count()); + m_frameCount = 0; + m_lastFrameDebug = currentTime; + } +#endif + return true; #else return false; -- GitLab