OSDN Git Service

drm_hwcomposer: Implement Dump() for DrmCompositor
authorSean Paul <seanpaul@chromium.org>
Wed, 10 Jun 2015 21:29:05 +0000 (17:29 -0400)
committerSean Paul <seanpaul@chromium.org>
Wed, 10 Jun 2015 21:33:00 +0000 (17:33 -0400)
Output simple fps information from the DrmCompositor on Dump().

Change-Id: Ic1f4f922fa2cd15e1fc7c6fdb412baa33611676f
Signed-off-by: Sean Paul <seanpaul@chromium.org>
drmcompositor.cpp
drmcompositor.h

index ffca4df..bf95601 100644 (file)
@@ -22,7 +22,9 @@
 #include "drmresources.h"
 
 #include <pthread.h>
+#include <sstream>
 #include <stdlib.h>
+#include <time.h>
 
 #include <cutils/log.h>
 #include <sync/sync.h>
@@ -34,7 +36,13 @@ DrmCompositor::DrmCompositor(DrmResources *drm)
       worker_(this),
       active_composition_(NULL),
       frame_no_(0),
-      initialized_(false) {
+      initialized_(false),
+      dump_frames_composited_(0),
+      dump_last_timestamp_ns_(0) {
+  struct timespec ts;
+  if (clock_gettime(CLOCK_MONOTONIC, &ts))
+    return;
+  dump_last_timestamp_ns_ = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
 }
 
 DrmCompositor::~DrmCompositor() {
@@ -218,6 +226,7 @@ int DrmCompositor::Composite() {
 
   DrmComposition *composition = composite_queue_.front();
   composite_queue_.pop();
+  ++dump_frames_composited_;
 
   ret = pthread_mutex_unlock(&lock_);
   if (ret) {
@@ -267,4 +276,31 @@ bool DrmCompositor::HaveQueuedComposites() const {
 
   return empty_ret;
 }
+
+void DrmCompositor::Dump(std::ostringstream *out) const {
+  uint64_t cur_ts;
+
+  int ret = pthread_mutex_lock(&lock_);
+  if (ret)
+    return;
+
+  uint64_t num_frames = dump_frames_composited_;
+  dump_frames_composited_ = 0;
+
+  struct timespec ts;
+  ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+
+  ret |= pthread_mutex_unlock(&lock_);
+  if (ret)
+    return;
+
+  cur_ts = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
+  uint64_t num_ms = (cur_ts - dump_last_timestamp_ns_) / (1000 * 1000);
+  unsigned fps = num_ms ? (num_frames * 1000) / (num_ms) : 0;
+
+  *out << "DrmCompositor: num_frames=" << num_frames << " num_ms=" << num_ms <<
+          " fps=" << fps << "\n";
+
+  dump_last_timestamp_ns_ = cur_ts;
+}
 }
index 6b92a22..ad1316c 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <pthread.h>
 #include <queue>
+#include <sstream>
 
 #include <hardware/hardware.h>
 #include <hardware/hwcomposer.h>
@@ -49,6 +50,7 @@ class DrmCompositor : public Compositor {
 
   virtual int QueueComposition(Composition *composition);
   virtual int Composite();
+  virtual void Dump(std::ostringstream *out) const;
 
   bool HaveQueuedComposites() const;
 
@@ -73,6 +75,11 @@ class DrmCompositor : public Compositor {
 
   // mutable since we need to acquire in HaveQueuedComposites
   mutable pthread_mutex_t lock_;
+
+  // State tracking progress since our last Dump(). These are mutable since
+  // we need to reset them on every Dump() call.
+  mutable uint64_t dump_frames_composited_;
+  mutable uint64_t dump_last_timestamp_ns_;
 };
 }