From e180e7b4b984f1d3b53f346a80de17a154284862 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Thu, 22 Oct 2015 16:54:06 +0100 Subject: [PATCH] Extract out FPS Tracker & Update Status Logger from UpdateThread class Change-Id: If1a40c60d79b7d95c453fa91d412c21f1cb7794e --- adaptors/base/file.list | 2 + adaptors/base/fps-tracker.cpp | 100 +++++++++++++++++++++++++++++++++ adaptors/base/fps-tracker.h | 86 ++++++++++++++++++++++++++++ adaptors/base/update-status-logger.cpp | 97 ++++++++++++++++++++++++++++++++ adaptors/base/update-status-logger.h | 72 ++++++++++++++++++++++++ adaptors/base/update-thread.cpp | 99 ++------------------------------ adaptors/base/update-thread.h | 30 ++-------- 7 files changed, 367 insertions(+), 119 deletions(-) create mode 100644 adaptors/base/fps-tracker.cpp create mode 100644 adaptors/base/fps-tracker.h create mode 100644 adaptors/base/update-status-logger.cpp create mode 100644 adaptors/base/update-status-logger.h diff --git a/adaptors/base/file.list b/adaptors/base/file.list index 00a0181..284b7f3 100644 --- a/adaptors/base/file.list +++ b/adaptors/base/file.list @@ -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 index 0000000..7c68e47 --- /dev/null +++ b/adaptors/base/fps-tracker.cpp @@ -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 +#include + +// INTERNAL INCLUDES +#include + +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 index 0000000..cc9cc88 --- /dev/null +++ b/adaptors/base/fps-tracker.h @@ -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 index 0000000..8bf9469 --- /dev/null +++ b/adaptors/base/update-status-logger.cpp @@ -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 +#include + +// INTERNAL INCLUDES +#include + +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 += " "; + } + + if ( keepUpdatingStatus & Integration::KeepUpdating::ANIMATIONS_RUNNING ) + { + oss += " "; + } + + if ( keepUpdatingStatus & Integration::KeepUpdating::LOADING_RESOURCES ) + { + oss += " "; + } + + if ( keepUpdatingStatus & Integration::KeepUpdating::MONITORING_PERFORMANCE ) + { + oss += " "; + } + + if ( keepUpdatingStatus & Integration::KeepUpdating::RENDER_TASK_SYNC ) + { + oss += " "; + } + + 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 index 0000000..3c66002 --- /dev/null +++ b/adaptors/base/update-status-logger.h @@ -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__ diff --git a/adaptors/base/update-thread.cpp b/adaptors/base/update-thread.cpp index ce80037..d37528c 100644 --- a/adaptors/base/update-thread.cpp +++ b/adaptors/base/update-thread.cpp @@ -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 += " "; - } - - if ( keepUpdatingStatus & Integration::KeepUpdating::ANIMATIONS_RUNNING ) - { - oss += " "; - } - - if ( keepUpdatingStatus & Integration::KeepUpdating::LOADING_RESOURCES ) - { - oss += " "; - } - - if ( keepUpdatingStatus & Integration::KeepUpdating::MONITORING_PERFORMANCE ) - { - oss += " "; - } - - if ( keepUpdatingStatus & Integration::KeepUpdating::RENDER_TASK_SYNC ) - { - oss += " "; - } - - DALI_LOG_UPDATE_STATUS( "%s\n", oss.c_str()); - } -} - } // namespace Adaptor } // namespace Internal diff --git a/adaptors/base/update-thread.h b/adaptors/base/update-thread.h index 2043277..0f861a9 100644 --- a/adaptors/base/update-thread.h +++ b/adaptors/base/update-thread.h @@ -21,6 +21,10 @@ // EXTERNAL INCLUDES #include +// INTERNAL INCLUDES +#include +#include + 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 -- 2.7.4