Extract out FPS Tracker & Update Status Logger from UpdateThread class 09/50009/7
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 22 Oct 2015 15:54:06 +0000 (16:54 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 4 Nov 2015 11:22:58 +0000 (11:22 +0000)
Change-Id: If1a40c60d79b7d95c453fa91d412c21f1cb7794e

adaptors/base/file.list
adaptors/base/fps-tracker.cpp [new file with mode: 0644]
adaptors/base/fps-tracker.h [new file with mode: 0644]
adaptors/base/update-status-logger.cpp [new file with mode: 0644]
adaptors/base/update-status-logger.h [new file with mode: 0644]
adaptors/base/update-thread.cpp
adaptors/base/update-thread.h

index 00a0181..284b7f3 100644 (file)
@@ -3,10 +3,12 @@
 base_adaptor_src_files = \
   $(base_adaptor_src_dir)/display-connection.cpp \
   $(base_adaptor_src_dir)/environment-options.cpp \
+  $(base_adaptor_src_dir)/fps-tracker.cpp \
   $(base_adaptor_src_dir)/frame-time.cpp \
   $(base_adaptor_src_dir)/render-thread.cpp \
   $(base_adaptor_src_dir)/thread-controller.cpp \
   $(base_adaptor_src_dir)/thread-synchronization.cpp \
+  $(base_adaptor_src_dir)/update-status-logger.cpp \
   $(base_adaptor_src_dir)/update-thread.cpp \
   $(base_adaptor_src_dir)/vsync-notifier.cpp \
   $(base_adaptor_src_dir)/performance-logging/frame-time-stamp.cpp \
diff --git a/adaptors/base/fps-tracker.cpp b/adaptors/base/fps-tracker.cpp
new file mode 100644 (file)
index 0000000..7c68e47
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "fps-tracker.h"
+
+// EXTERNAL INCLUDES
+#include <cstdio>
+#include <cmath>
+
+// INTERNAL INCLUDES
+#include <base/environment-options.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+namespace
+{
+const char* DALI_TEMP_UPDATE_FPS_FILE( "/tmp/dalifps.txt" );
+} // unnamed namespace
+
+FpsTracker::FpsTracker( const EnvironmentOptions& environmentOptions )
+: mFpsTrackingSeconds( fabsf( environmentOptions.GetFrameRateLoggingFrequency() ) ),
+  mFrameCount( 0.0f ),
+  mElapsedTime( 0.0f )
+{
+}
+
+FpsTracker::~FpsTracker()
+{
+  if( mFpsTrackingSeconds > 0.f )
+  {
+    OutputFPSRecord();
+  }
+}
+
+void FpsTracker::Track( float secondsFromLastFrame )
+{
+  if( mFpsTrackingSeconds > 0.f )
+  {
+    if ( mElapsedTime < mFpsTrackingSeconds )
+    {
+      mElapsedTime += secondsFromLastFrame;
+      mFrameCount += 1.f;
+    }
+    else
+    {
+      OutputFPSRecord();
+      mFrameCount = 0.f;
+      mElapsedTime = 0.f;
+    }
+  }
+}
+
+bool FpsTracker::Enabled() const
+{
+  return mFpsTrackingSeconds > 0.0f;
+}
+
+void FpsTracker::OutputFPSRecord()
+{
+  float fps = mFrameCount / mElapsedTime;
+  DALI_LOG_FPS("Frame count %.0f, elapsed time %.1fs, FPS: %.2f\n", mFrameCount, mElapsedTime, fps );
+
+  // Dumps out the frame rate.
+  FILE* outfile = fopen( DALI_TEMP_UPDATE_FPS_FILE, "w" );
+  if( outfile )
+  {
+    char fpsString[10];
+    snprintf(fpsString,sizeof(fpsString),"%.2f \n", fps );
+    fputs( fpsString, outfile ); // ignore the error on purpose
+    fclose( outfile );
+  }
+}
+
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
diff --git a/adaptors/base/fps-tracker.h b/adaptors/base/fps-tracker.h
new file mode 100644 (file)
index 0000000..cc9cc88
--- /dev/null
@@ -0,0 +1,86 @@
+#ifndef __DALI_INTERNAL_FPS_TRACKER_H__
+#define __DALI_INTERNAL_FPS_TRACKER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+class EnvironmentOptions;
+
+/**
+ * Tracks the frames per second.
+ *
+ * Can also output the FPS to a file if required.
+ */
+class FpsTracker
+{
+public:
+
+  /**
+   * Create the FPS Tracker.
+   * @param[in] environmentOptions environment options
+   */
+  FpsTracker( const EnvironmentOptions& environmentOptions );
+
+  /**
+   * Non-virtual destructor; UpdateThread is not suitable as a base class.
+   */
+  ~FpsTracker();
+
+  /**
+   * When DALI_FPS_TRACKING is enabled, this method calculates the frame rates for the specified time period
+   *
+   * @param[in] secondsFromLastFrame The time (in seconds) that has elapsed since the last frame.
+   */
+  void Track(float secondsFromLastFrame);
+
+  /**
+   * @return Whether FPS tracking is enabled.
+   */
+  bool Enabled() const;
+
+private:
+
+  /**
+   * Output the FPS information
+   * when the FSP tracking is enabled,
+   * it is called when the specified tracking period is elapsed or in the destructor when the process finished beforehand
+   */
+  void OutputFPSRecord();
+
+private: // Data
+
+  float mFpsTrackingSeconds;  ///< fps tracking time length in seconds
+  float mFrameCount;          ///< how many frames occurred during tracking period
+  float mElapsedTime;         ///< time elapsed from previous fps tracking output
+};
+
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_FPS_TRACKER_H__
diff --git a/adaptors/base/update-status-logger.cpp b/adaptors/base/update-status-logger.cpp
new file mode 100644 (file)
index 0000000..8bf9469
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "update-status-logger.h"
+
+// EXTERNAL INCLUDES
+#include <string>
+#include <dali/integration-api/core.h>
+
+// INTERNAL INCLUDES
+#include <base/environment-options.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+UpdateStatusLogger::UpdateStatusLogger( const EnvironmentOptions& environmentOptions )
+: mStatusLogInterval( environmentOptions.GetUpdateStatusLoggingFrequency() ),
+  mStatusLogCount( 0u )
+{
+}
+
+UpdateStatusLogger::~UpdateStatusLogger()
+{
+}
+
+void UpdateStatusLogger::Log( unsigned int keepUpdatingStatus )
+{
+  if ( mStatusLogInterval )
+  {
+    std::string oss;
+
+    if ( !(++mStatusLogCount % mStatusLogInterval) )
+    {
+      oss = "UpdateStatusLogging keepUpdating: ";
+      oss += (keepUpdatingStatus ? "true":"false");
+
+      if ( keepUpdatingStatus )
+      {
+        oss += " because: ";
+      }
+
+      if ( keepUpdatingStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING )
+      {
+        oss += "<Stage::KeepRendering() used> ";
+      }
+
+      if ( keepUpdatingStatus & Integration::KeepUpdating::ANIMATIONS_RUNNING )
+      {
+        oss  +=  "<Animations running> ";
+      }
+
+      if ( keepUpdatingStatus & Integration::KeepUpdating::LOADING_RESOURCES )
+      {
+        oss  +=  "<Resources loading> ";
+      }
+
+      if ( keepUpdatingStatus & Integration::KeepUpdating::MONITORING_PERFORMANCE )
+      {
+        oss += "<Monitoring performance> ";
+      }
+
+      if ( keepUpdatingStatus & Integration::KeepUpdating::RENDER_TASK_SYNC )
+      {
+        oss += "<Render task waiting for completion> ";
+      }
+
+      DALI_LOG_UPDATE_STATUS( "%s\n", oss.c_str());
+    }
+  }
+}
+
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
diff --git a/adaptors/base/update-status-logger.h b/adaptors/base/update-status-logger.h
new file mode 100644 (file)
index 0000000..3c66002
--- /dev/null
@@ -0,0 +1,72 @@
+#ifndef __DALI_INTERNAL_UPDATE_STATUS_LOGGER_H__
+#define __DALI_INTERNAL_UPDATE_STATUS_LOGGER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+
+// INTERNAL INCLUDES
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+class EnvironmentOptions;
+
+/**
+ * This outputs the status of the update as required.
+ */
+class UpdateStatusLogger
+{
+public:
+
+  /**
+   * Create the update-status-logger.
+   * @param[in] environmentOptions environment options
+   */
+  UpdateStatusLogger( const EnvironmentOptions& environmentOptions );
+
+  /**
+   * Non-virtual destructor; UpdateThread is not suitable as a base class.
+   */
+  ~UpdateStatusLogger();
+
+  /**
+   * Optionally output the update thread status.
+   * @param[in] keepUpdatingStatus Whether the update-thread requested further updates.
+   */
+  void Log( unsigned int keepUpdatingStatus );
+
+private: // Data
+
+  unsigned int mStatusLogInterval;   ///< Interval in frames between status debug prints
+  unsigned int mStatusLogCount;      ///< Used to count frames between status debug prints
+};
+
+} // namespace Adaptor
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_UPDATE_STATUS_LOGGER_H__
index ce80037..d37528c 100644 (file)
@@ -38,8 +38,6 @@ namespace Adaptor
 
 namespace
 {
-const char* DALI_TEMP_UPDATE_FPS_FILE( "/tmp/dalifps.txt" );
-
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gUpdateLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_UPDATE_THREAD");
 #endif
@@ -50,11 +48,8 @@ UpdateThread::UpdateThread( ThreadSynchronization& sync,
                             const EnvironmentOptions& environmentOptions )
 : mThreadSynchronization( sync ),
   mCore( adaptorInterfaces.GetCore()),
-  mFpsTrackingSeconds( fabsf( environmentOptions.GetFrameRateLoggingFrequency() ) ),
-  mFrameCount( 0.0f ),
-  mElapsedTime( 0.0f ),
-  mStatusLogInterval( environmentOptions.GetUpdateStatusLoggingFrequency() ),
-  mStatusLogCount( 0u ),
+  mFpsTracker( environmentOptions ),
+  mUpdateStatusLogger( environmentOptions ),
   mThread( NULL ),
   mEnvironmentOptions( environmentOptions )
 {
@@ -62,10 +57,6 @@ UpdateThread::UpdateThread( ThreadSynchronization& sync,
 
 UpdateThread::~UpdateThread()
 {
-  if( mFpsTrackingSeconds > 0.f )
-  {
-    OutputFPSRecord();
-  }
   Stop();
 }
 
@@ -119,18 +110,12 @@ bool UpdateThread::Run()
     mCore.Update( lastFrameDelta, lastSyncTime, nextSyncTime, status );
     mThreadSynchronization.AddPerformanceMarker( PerformanceInterface::UPDATE_END );
 
-    if( mFpsTrackingSeconds > 0.f )
-    {
-      FPSTracking(status.SecondsFromLastFrame());
-    }
+    mFpsTracker.Track( status.SecondsFromLastFrame() );
 
     unsigned int keepUpdatingStatus = status.KeepUpdating();
 
     // Optional logging of update/render status
-    if ( mStatusLogInterval )
-    {
-      UpdateStatusLogging( keepUpdatingStatus );
-    }
+    mUpdateStatusLogger.Log( keepUpdatingStatus );
 
     //  2 things can keep update running.
     // - The status of the last update
@@ -151,82 +136,6 @@ bool UpdateThread::Run()
   return true;
 }
 
-void UpdateThread::FPSTracking( float secondsFromLastFrame )
-{
-  if ( mElapsedTime < mFpsTrackingSeconds )
-  {
-    mElapsedTime += secondsFromLastFrame;
-    mFrameCount += 1.f;
-  }
-  else
-  {
-    OutputFPSRecord();
-    mFrameCount = 0.f;
-    mElapsedTime = 0.f;
-  }
-}
-
-void UpdateThread::OutputFPSRecord()
-{
-  float fps = mFrameCount / mElapsedTime;
-  DALI_LOG_FPS("Frame count %.0f, elapsed time %.1fs, FPS: %.2f\n", mFrameCount, mElapsedTime, fps );
-
-  // Dumps out the frame rate.
-  FILE* outfile = fopen( DALI_TEMP_UPDATE_FPS_FILE, "w" );
-  if( outfile )
-  {
-    char fpsString[10];
-    snprintf(fpsString,sizeof(fpsString),"%.2f \n", fps );
-    fputs( fpsString, outfile ); // ignore the error on purpose
-    fclose( outfile );
-  }
-}
-
-void UpdateThread::UpdateStatusLogging( unsigned int keepUpdatingStatus )
-{
-  DALI_ASSERT_ALWAYS( mStatusLogInterval );
-
-  std::string oss;
-
-  if ( !(++mStatusLogCount % mStatusLogInterval) )
-  {
-    oss = "UpdateStatusLogging keepUpdating: ";
-    oss += (keepUpdatingStatus ? "true":"false");
-
-    if ( keepUpdatingStatus )
-    {
-      oss += " because: ";
-    }
-
-    if ( keepUpdatingStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING )
-    {
-      oss += "<Stage::KeepRendering() used> ";
-    }
-
-    if ( keepUpdatingStatus & Integration::KeepUpdating::ANIMATIONS_RUNNING )
-    {
-      oss  +=  "<Animations running> ";
-    }
-
-    if ( keepUpdatingStatus & Integration::KeepUpdating::LOADING_RESOURCES )
-    {
-      oss  +=  "<Resources loading> ";
-    }
-
-    if ( keepUpdatingStatus & Integration::KeepUpdating::MONITORING_PERFORMANCE )
-    {
-      oss += "<Monitoring performance> ";
-    }
-
-    if ( keepUpdatingStatus & Integration::KeepUpdating::RENDER_TASK_SYNC )
-    {
-      oss += "<Render task waiting for completion> ";
-    }
-
-    DALI_LOG_UPDATE_STATUS( "%s\n", oss.c_str());
-  }
-}
-
 } // namespace Adaptor
 
 } // namespace Internal
index 2043277..0f861a9 100644 (file)
 // EXTERNAL INCLUDES
 #include <pthread.h>
 
+// INTERNAL INCLUDES
+#include <base/fps-tracker.h>
+#include <base/update-status-logger.h>
+
 namespace Dali
 {
 
@@ -81,24 +85,6 @@ private:
   bool Run();
 
   /**
-   * When DALI_FPS_TRACKING is enabled, this method calculates the frame rates for the specified time period
-   */
-  void FPSTracking(float secondsFromLastFrame);
-
-  /**
-   * Output the FPS information
-   * when the FSP tracking is enabled,
-   * it is called when the specified tracking period is elapsed or in the destructor when the process finished beforehand
-   */
-  void OutputFPSRecord();
-
-  /**
-   * Optionally output the update thread status.
-   * @param[in] keepUpdatingStatus Whether the update-thread requested further updates.
-   */
-  void UpdateStatusLogging( unsigned int keepUpdatingStatus );
-
-  /**
    * Helper for the thread calling the entry function
    * @param[in] This A pointer to the current UpdateThread object
    */
@@ -114,12 +100,8 @@ private: // Data
 
   Dali::Integration::Core&            mCore;                ///< Dali core reference
 
-  float                               mFpsTrackingSeconds;  ///< fps tracking time length in seconds
-  float                               mFrameCount;          ///< how many frames occurred during tracking period
-  float                               mElapsedTime;         ///< time elapsed from previous fps tracking output
-
-  unsigned int                        mStatusLogInterval;   ///< Interval in frames between status debug prints
-  unsigned int                        mStatusLogCount;      ///< Used to count frames between status debug prints
+  FpsTracker                          mFpsTracker;          ///< Object that tracks the FPS
+  UpdateStatusLogger                  mUpdateStatusLogger;  ///< Object that logs the update-status as required.
 
   pthread_t*                          mThread;              ///< The actual update-thread.
   const EnvironmentOptions&           mEnvironmentOptions;  ///< environment options