2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2012-10-03 21:41:02 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/Timer.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/FPSCounter.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2012-10-03 21:41:02 -06:00
|
|
|
|
|
|
|
#define FPS_REFRESH_INTERVAL 1000
|
|
|
|
|
|
|
|
static unsigned int s_counter = 0;
|
|
|
|
static unsigned int s_fps = 0;
|
|
|
|
static unsigned int s_fps_last_counter = 0;
|
|
|
|
static unsigned long s_last_update_time = 0;
|
|
|
|
static File::IOFile s_bench_file;
|
|
|
|
|
|
|
|
void InitFPSCounter()
|
|
|
|
{
|
|
|
|
s_counter = s_fps_last_counter = 0;
|
|
|
|
s_fps = 0;
|
|
|
|
s_last_update_time = Common::Timer::GetTimeMs();
|
|
|
|
|
|
|
|
if (s_bench_file.IsOpen())
|
|
|
|
s_bench_file.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LogFPSToFile(unsigned long val)
|
|
|
|
{
|
|
|
|
if (!s_bench_file.IsOpen())
|
|
|
|
s_bench_file.Open(File::GetUserPath(D_LOGS_IDX) + "fps.txt", "w");
|
|
|
|
|
|
|
|
char buffer[256];
|
2014-02-23 15:03:39 -07:00
|
|
|
snprintf(buffer, 256, "%lu\n", val);
|
2012-10-03 21:41:02 -06:00
|
|
|
s_bench_file.WriteArray(buffer, strlen(buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
int UpdateFPSCounter()
|
|
|
|
{
|
|
|
|
if (Common::Timer::GetTimeMs() - s_last_update_time >= FPS_REFRESH_INTERVAL)
|
|
|
|
{
|
|
|
|
s_last_update_time = Common::Timer::GetTimeMs();
|
|
|
|
s_fps = s_counter - s_fps_last_counter;
|
|
|
|
s_fps_last_counter = s_counter;
|
|
|
|
if (g_ActiveConfig.bLogFPSToFile)
|
|
|
|
LogFPSToFile(s_fps);
|
|
|
|
}
|
|
|
|
|
|
|
|
s_counter++;
|
|
|
|
return s_fps;
|
|
|
|
}
|