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 <dali/internal/system/common/fps-tracker.h>
27 #include <dali/internal/system/common/environment-options.h>
37 const char* DALI_TEMP_UPDATE_FPS_FILE("/tmp/dalifps.txt");
38 } // unnamed namespace
40 FpsTracker::FpsTracker(const EnvironmentOptions& environmentOptions)
41 : mFpsTrackingSeconds(fabsf(environmentOptions.GetFrameRateLoggingFrequency())),
47 FpsTracker::~FpsTracker()
49 if(mFpsTrackingSeconds > 0.f)
55 void FpsTracker::Track(float secondsFromLastFrame)
57 if(mFpsTrackingSeconds > 0.f)
59 if(mElapsedTime < mFpsTrackingSeconds)
61 mElapsedTime += secondsFromLastFrame;
73 bool FpsTracker::Enabled() const
75 return mFpsTrackingSeconds > 0.0f;
78 void FpsTracker::OutputFPSRecord()
80 float fps = mFrameCount / mElapsedTime;
81 DALI_LOG_FPS("Frame count %.0f, elapsed time %.1fs, FPS: %.2f\n", mFrameCount, mElapsedTime, fps);
86 if(lstat(DALI_TEMP_UPDATE_FPS_FILE, &fileStat) != 0)
91 if(!S_ISREG(fileStat.st_mode))
96 // Dumps out the frame rate.
97 FILE* outfile = fopen(DALI_TEMP_UPDATE_FPS_FILE, "w");
101 snprintf(fpsString, sizeof(fpsString), "%.2f \n", fps);
102 fputs(fpsString, outfile); // ignore the error on purpose
107 } // namespace Adaptor
109 } // namespace Internal