VideoCommon: Improve precision of FPS counter

This commit is contained in:
Stenzek 2017-06-30 17:25:32 +10:00
parent 1fccbd5be3
commit 621287e7eb
3 changed files with 24 additions and 26 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <fstream>
#include <iomanip>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
@ -10,12 +11,11 @@
#include "VideoCommon/FPSCounter.h"
#include "VideoCommon/VideoConfig.h"
static constexpr u64 FPS_REFRESH_INTERVAL = 1000;
static constexpr u64 FPS_REFRESH_INTERVAL = 250000;
FPSCounter::FPSCounter()
{
m_update_time.Update();
m_render_time.Update();
m_last_time = Common::Timer::GetTimeUs();
}
void FPSCounter::LogRenderTimeToFile(u64 val)
@ -23,24 +23,24 @@ void FPSCounter::LogRenderTimeToFile(u64 val)
if (!m_bench_file.is_open())
m_bench_file.open(File::GetUserPath(D_LOGS_IDX) + "render_time.txt");
m_bench_file << val << std::endl;
m_bench_file << std::fixed << std::setprecision(8) << (val / 1000.0) << std::endl;
}
void FPSCounter::Update()
{
if (m_update_time.GetTimeDifference() >= FPS_REFRESH_INTERVAL)
{
m_update_time.Update();
m_fps = m_counter - m_fps_last_counter;
m_fps_last_counter = m_counter;
m_bench_file.flush();
}
u64 time = Common::Timer::GetTimeUs();
u64 diff = time - m_last_time;
if (g_ActiveConfig.bLogRenderTimeToFile)
{
LogRenderTimeToFile(m_render_time.GetTimeDifference());
m_render_time.Update();
}
LogRenderTimeToFile(diff);
m_counter++;
m_frame_counter++;
m_time_since_update += diff;
m_last_time = time;
if (m_time_since_update >= FPS_REFRESH_INTERVAL)
{
m_fps = m_frame_counter / (m_time_since_update / 1000000.0);
m_frame_counter = 0;
m_time_since_update = 0;
}
}

View File

@ -6,7 +6,7 @@
#include <fstream>
#include "Common/Timer.h"
#include "Common/CommonTypes.h"
class FPSCounter
{
@ -17,14 +17,12 @@ public:
// Called when a frame is rendered (updated every second).
void Update();
unsigned int GetFPS() const { return m_fps; }
float GetFPS() const { return m_fps; }
private:
unsigned int m_fps = 0;
unsigned int m_counter = 0;
unsigned int m_fps_last_counter = 0;
Common::Timer m_update_time;
Common::Timer m_render_time;
u64 m_last_time = 0;
u64 m_time_since_update = 0;
u32 m_frame_counter = 0;
float m_fps = 0;
std::ofstream m_bench_file;
void LogRenderTimeToFile(u64 val);

View File

@ -337,7 +337,7 @@ void Renderer::DrawDebugText()
if (g_ActiveConfig.bShowFPS || SConfig::GetInstance().m_ShowFrameCount)
{
if (g_ActiveConfig.bShowFPS)
final_cyan += StringFromFormat("FPS: %u", m_fps_counter.GetFPS());
final_cyan += StringFromFormat("FPS: %.2f", m_fps_counter.GetFPS());
if (g_ActiveConfig.bShowFPS && SConfig::GetInstance().m_ShowFrameCount)
final_cyan += " - ";