Revert "[Tizen] Disable shader bin cache in TV profile"
[platform/core/uifw/dali-adaptor.git] / adaptors / base / fps-tracker.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "fps-tracker.h"
20
21 // EXTERNAL INCLUDES
22 #include <cstdio>
23 #include <cmath>
24
25 // INTERNAL INCLUDES
26 #include <base/environment-options.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 namespace
38 {
39 const char* DALI_TEMP_UPDATE_FPS_FILE( "/tmp/dalifps.txt" );
40 } // unnamed namespace
41
42 FpsTracker::FpsTracker( const EnvironmentOptions& environmentOptions )
43 : mFpsTrackingSeconds( fabsf( environmentOptions.GetFrameRateLoggingFrequency() ) ),
44   mFrameCount( 0.0f ),
45   mElapsedTime( 0.0f )
46 {
47 }
48
49 FpsTracker::~FpsTracker()
50 {
51   if( mFpsTrackingSeconds > 0.f )
52   {
53     OutputFPSRecord();
54   }
55 }
56
57 void FpsTracker::Track( float secondsFromLastFrame )
58 {
59   if( mFpsTrackingSeconds > 0.f )
60   {
61     if ( mElapsedTime < mFpsTrackingSeconds )
62     {
63       mElapsedTime += secondsFromLastFrame;
64       mFrameCount += 1.f;
65     }
66     else
67     {
68       OutputFPSRecord();
69       mFrameCount = 0.f;
70       mElapsedTime = 0.f;
71     }
72   }
73 }
74
75 bool FpsTracker::Enabled() const
76 {
77   return mFpsTrackingSeconds > 0.0f;
78 }
79
80 void FpsTracker::OutputFPSRecord()
81 {
82   float fps = mFrameCount / mElapsedTime;
83   DALI_LOG_FPS("Frame count %.0f, elapsed time %.1fs, FPS: %.2f\n", mFrameCount, mElapsedTime, fps );
84
85   // Dumps out the frame rate.
86   FILE* outfile = fopen( DALI_TEMP_UPDATE_FPS_FILE, "w" );
87   if( outfile )
88   {
89     char fpsString[10];
90     snprintf(fpsString,sizeof(fpsString),"%.2f \n", fps );
91     fputs( fpsString, outfile ); // ignore the error on purpose
92     fclose( outfile );
93   }
94 }
95
96 } // namespace Adaptor
97
98 } // namespace Internal
99
100 } // namespace Dali