2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2012-10-04 03:41:02 +00:00
|
|
|
|
2014-07-03 00:19:08 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2014-07-03 00:19:08 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Timer.h"
|
|
|
|
#include "VideoCommon/FPSCounter.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2012-10-04 03:41:02 +00:00
|
|
|
|
2014-07-03 00:19:08 +00:00
|
|
|
namespace FPSCounter
|
|
|
|
{
|
2012-10-04 03:41:02 +00: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;
|
2014-07-09 15:15:41 +00:00
|
|
|
static Common::Timer s_update_time;
|
2012-10-04 03:41:02 +00:00
|
|
|
|
2014-07-09 15:03:17 +00:00
|
|
|
static Common::Timer s_render_time;
|
2014-07-09 15:56:11 +00:00
|
|
|
static std::ofstream s_bench_file;
|
2014-07-09 15:03:17 +00:00
|
|
|
|
2014-07-03 00:19:08 +00:00
|
|
|
void Initialize()
|
2012-10-04 03:41:02 +00:00
|
|
|
{
|
|
|
|
s_counter = s_fps_last_counter = 0;
|
|
|
|
s_fps = 0;
|
|
|
|
|
2014-07-09 15:15:41 +00:00
|
|
|
s_update_time.Update();
|
2014-07-09 15:03:17 +00:00
|
|
|
s_render_time.Update();
|
|
|
|
|
2014-07-03 00:19:08 +00:00
|
|
|
if (s_bench_file.is_open())
|
|
|
|
s_bench_file.close();
|
2012-10-04 03:41:02 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 20:30:34 +00:00
|
|
|
void Shutdown()
|
|
|
|
{
|
|
|
|
if (s_bench_file.is_open())
|
|
|
|
s_bench_file.close();
|
|
|
|
}
|
|
|
|
|
2014-07-09 15:56:11 +00:00
|
|
|
static void LogRenderTimeToFile(u64 val)
|
2012-10-04 03:41:02 +00:00
|
|
|
{
|
2014-07-03 00:19:08 +00:00
|
|
|
if (!s_bench_file.is_open())
|
2014-07-09 15:56:11 +00:00
|
|
|
s_bench_file.open(File::GetUserPath(D_LOGS_IDX) + "render_time.txt");
|
2012-10-04 03:41:02 +00:00
|
|
|
|
2014-07-09 16:22:16 +00:00
|
|
|
s_bench_file << val << std::endl;
|
2012-10-04 03:41:02 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 00:19:08 +00:00
|
|
|
int Update()
|
2012-10-04 03:41:02 +00:00
|
|
|
{
|
2014-07-09 15:15:41 +00:00
|
|
|
if (s_update_time.GetTimeDifference() >= FPS_REFRESH_INTERVAL)
|
2012-10-04 03:41:02 +00:00
|
|
|
{
|
2014-07-09 15:15:41 +00:00
|
|
|
s_update_time.Update();
|
2012-10-04 03:41:02 +00:00
|
|
|
s_fps = s_counter - s_fps_last_counter;
|
|
|
|
s_fps_last_counter = s_counter;
|
2014-07-09 20:30:34 +00:00
|
|
|
s_bench_file.flush();
|
2012-10-04 03:41:02 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 15:03:17 +00:00
|
|
|
if (g_ActiveConfig.bLogRenderTimeToFile)
|
|
|
|
{
|
|
|
|
LogRenderTimeToFile(s_render_time.GetTimeDifference());
|
|
|
|
s_render_time.Update();
|
|
|
|
}
|
|
|
|
|
2012-10-04 03:41:02 +00:00
|
|
|
s_counter++;
|
|
|
|
return s_fps;
|
2014-07-03 00:19:08 +00:00
|
|
|
}
|
2012-10-04 03:41:02 +00:00
|
|
|
}
|