From 621287e7ebe7716f7b0d074e60953848a0ae86a7 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 30 Jun 2017 17:25:32 +1000 Subject: VideoCommon: Improve precision of FPS counter --- Source/Core/VideoCommon/FPSCounter.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'Source/Core/VideoCommon/FPSCounter.cpp') diff --git a/Source/Core/VideoCommon/FPSCounter.cpp b/Source/Core/VideoCommon/FPSCounter.cpp index 2d17d00a41..86b3ab5c85 100644 --- a/Source/Core/VideoCommon/FPSCounter.cpp +++ b/Source/Core/VideoCommon/FPSCounter.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #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(diff); + + m_frame_counter++; + m_time_since_update += diff; + m_last_time = time; + + if (m_time_since_update >= FPS_REFRESH_INTERVAL) { - LogRenderTimeToFile(m_render_time.GetTimeDifference()); - m_render_time.Update(); + m_fps = m_frame_counter / (m_time_since_update / 1000000.0); + m_frame_counter = 0; + m_time_since_update = 0; } - - m_counter++; } -- cgit v1.2.3