2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2012-10-04 05:41:02 +02:00
|
|
|
|
2014-07-03 02:19:08 +02:00
|
|
|
#include <fstream>
|
2017-06-30 09:25:32 +02:00
|
|
|
#include <iomanip>
|
2014-07-03 02:19:08 +02:00
|
|
|
|
2016-01-17 22:54:31 +01:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/Timer.h"
|
|
|
|
#include "VideoCommon/FPSCounter.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2012-10-04 05:41:02 +02:00
|
|
|
|
2017-06-30 09:25:32 +02:00
|
|
|
static constexpr u64 FPS_REFRESH_INTERVAL = 250000;
|
2012-10-04 05:41:02 +02:00
|
|
|
|
2014-07-13 13:04:25 +02:00
|
|
|
FPSCounter::FPSCounter()
|
2012-10-04 05:41:02 +02:00
|
|
|
{
|
2017-06-30 09:25:32 +02:00
|
|
|
m_last_time = Common::Timer::GetTimeUs();
|
2012-10-04 05:41:02 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 13:04:25 +02:00
|
|
|
void FPSCounter::LogRenderTimeToFile(u64 val)
|
2012-10-04 05:41:02 +02:00
|
|
|
{
|
2014-07-13 13:04:25 +02:00
|
|
|
if (!m_bench_file.is_open())
|
2017-12-05 21:23:35 +01:00
|
|
|
{
|
|
|
|
File::OpenFStream(m_bench_file, File::GetUserPath(D_LOGS_IDX) + "render_time.txt",
|
|
|
|
std::ios_base::out);
|
|
|
|
}
|
2012-10-04 05:41:02 +02:00
|
|
|
|
2017-06-30 09:25:32 +02:00
|
|
|
m_bench_file << std::fixed << std::setprecision(8) << (val / 1000.0) << std::endl;
|
2012-10-04 05:41:02 +02:00
|
|
|
}
|
|
|
|
|
2015-09-29 15:57:54 +02:00
|
|
|
void FPSCounter::Update()
|
2012-10-04 05:41:02 +02:00
|
|
|
{
|
2017-06-30 09:25:32 +02:00
|
|
|
u64 time = Common::Timer::GetTimeUs();
|
|
|
|
u64 diff = time - m_last_time;
|
2014-07-09 17:03:17 +02:00
|
|
|
if (g_ActiveConfig.bLogRenderTimeToFile)
|
2017-06-30 09:25:32 +02:00
|
|
|
LogRenderTimeToFile(diff);
|
|
|
|
|
|
|
|
m_frame_counter++;
|
|
|
|
m_time_since_update += diff;
|
|
|
|
m_last_time = time;
|
|
|
|
|
|
|
|
if (m_time_since_update >= FPS_REFRESH_INTERVAL)
|
2014-07-09 17:03:17 +02:00
|
|
|
{
|
2017-06-30 09:25:32 +02:00
|
|
|
m_fps = m_frame_counter / (m_time_since_update / 1000000.0);
|
|
|
|
m_frame_counter = 0;
|
|
|
|
m_time_since_update = 0;
|
2014-07-09 17:03:17 +02:00
|
|
|
}
|
2014-07-03 02:19:08 +02:00
|
|
|
}
|