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 \
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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__
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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__
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
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 )
{
UpdateThread::~UpdateThread()
{
- if( mFpsTrackingSeconds > 0.f )
- {
- OutputFPSRecord();
- }
Stop();
}
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
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
// EXTERNAL INCLUDES
#include <pthread.h>
+// INTERNAL INCLUDES
+#include <base/fps-tracker.h>
+#include <base/update-status-logger.h>
+
namespace Dali
{
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
*/
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