From 3b1729c4cc52cf4ac542f6b3096719baba02ea6b Mon Sep 17 00:00:00 2001
From: Eloi BAIL <eloi.bail@savoirfairelinux.com>
Date: Thu, 19 Mar 2015 12:38:40 -0400
Subject: [PATCH] daemon: re-implement fps display within logs

Refs #68874

Change-Id: Ic53407f183d79327972ecb9e490cb246023478a7
Signed-off-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 daemon/src/media/video/sinkclient.cpp | 15 +++++++++++++++
 daemon/src/media/video/sinkclient.h   |  5 +++++
 2 files changed, 20 insertions(+)

diff --git a/daemon/src/media/video/sinkclient.cpp b/daemon/src/media/video/sinkclient.cpp
index 68cb81fe7e..defbc5209d 100644
--- a/daemon/src/media/video/sinkclient.cpp
+++ b/daemon/src/media/video/sinkclient.cpp
@@ -284,6 +284,10 @@ SinkClient::stop() noexcept
 #endif // !HAVE_SHM
 
 SinkClient::SinkClient(const std::string& id) : id_ {id}
+#ifdef DEBUG_FPS
+    , frameCount_(0u)
+    , lastFrameDebug_(std::chrono::system_clock::now())
+#endif
 {}
 
 void
@@ -292,6 +296,17 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
 {
     auto f = frame_p; // keep a local reference during rendering
 
+#ifdef DEBUG_FPS
+    auto currentTime = std::chrono::system_clock::now();
+    const std::chrono::duration<double> seconds = currentTime - lastFrameDebug_;
+    ++frameCount_;
+    if (seconds.count() > 1) {
+        RING_DBG("%s: FPS %f", id_.c_str(), frameCount_ / seconds.count());
+        frameCount_ = 0;
+        lastFrameDebug_ = currentTime;
+    }
+#endif
+
 #if HAVE_SHM
     shm_->render_frame(*f.get());
 #endif
diff --git a/daemon/src/media/video/sinkclient.h b/daemon/src/media/video/sinkclient.h
index 24f6d0bfab..048945346b 100644
--- a/daemon/src/media/video/sinkclient.h
+++ b/daemon/src/media/video/sinkclient.h
@@ -80,6 +80,11 @@ class SinkClient : public VideoFramePassiveReader
         std::function<void(unsigned char*)> target_;
         std::vector<unsigned char> targetData_;
 
+#ifdef DEBUG_FPS
+        unsigned frameCount_;
+        std::chrono::time_point<std::chrono::system_clock> lastFrameDebug_;
+#endif
+
 #if HAVE_SHM
         // using shared_ptr and not unique_ptr as ShmHolder is forwared only
         std::shared_ptr<ShmHolder> shm_;
-- 
GitLab