2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "fps-tracker.h"
27 #include <base/environment-options.h>
40 const char* DALI_TEMP_UPDATE_FPS_FILE( "/tmp/dalifps.txt" );
41 } // unnamed namespace
43 FpsTracker::FpsTracker( const EnvironmentOptions& environmentOptions )
44 : mFpsTrackingSeconds( fabsf( environmentOptions.GetFrameRateLoggingFrequency() ) ),
50 FpsTracker::~FpsTracker()
52 if( mFpsTrackingSeconds > 0.f )
58 void FpsTracker::Track( float secondsFromLastFrame )
60 if( mFpsTrackingSeconds > 0.f )
62 if ( mElapsedTime < mFpsTrackingSeconds )
64 mElapsedTime += secondsFromLastFrame;
76 bool FpsTracker::Enabled() const
78 return mFpsTrackingSeconds > 0.0f;
81 void FpsTracker::OutputFPSRecord()
83 float fps = mFrameCount / mElapsedTime;
84 DALI_LOG_FPS("Frame count %.0f, elapsed time %.1fs, FPS: %.2f\n", mFrameCount, mElapsedTime, fps );
89 if( lstat( DALI_TEMP_UPDATE_FPS_FILE, &fileStat ) != 0 )
94 if( !S_ISREG( fileStat.st_mode ) )
99 // Dumps out the frame rate.
100 FILE* outfile = fopen( DALI_TEMP_UPDATE_FPS_FILE, "w" );
104 snprintf(fpsString,sizeof(fpsString),"%.2f \n", fps );
105 fputs( fpsString, outfile ); // ignore the error on purpose
110 } // namespace Adaptor
112 } // namespace Internal