summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-02-19 18:18:26 -0800
committerGravatar Yuri Kunde Schlesner2017-02-26 17:22:03 -0800
commit92c8bd4b1f650438274e50303a6d3f668924d071 (patch)
tree0c9e162129dabd2424ee329b51f5765a73f6a494 /src
parentAdd performance statistics to status bar (diff)
downloadyuzu-92c8bd4b1f650438274e50303a6d3f668924d071.tar.gz
yuzu-92c8bd4b1f650438274e50303a6d3f668924d071.tar.xz
yuzu-92c8bd4b1f650438274e50303a6d3f668924d071.zip
PerfStats: Add method to get the instantaneous time ratio
Diffstat (limited to 'src')
-rw-r--r--src/core/frontend/emu_window.cpp5
-rw-r--r--src/core/perf_stats.cpp14
-rw-r--r--src/core/perf_stats.h10
3 files changed, 22 insertions, 7 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index 6b4637741..b65d6ff58 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -5,7 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6#include <cmath> 6#include <cmath>
7#include "common/assert.h" 7#include "common/assert.h"
8#include "common/profiler_reporting.h" 8#include "core/core.h"
9#include "core/frontend/emu_window.h" 9#include "core/frontend/emu_window.h"
10#include "core/frontend/key_map.h" 10#include "core/frontend/key_map.h"
11#include "video_core/video_core.h" 11#include "video_core/video_core.h"
@@ -104,8 +104,7 @@ void EmuWindow::AccelerometerChanged(float x, float y, float z) {
104void EmuWindow::GyroscopeChanged(float x, float y, float z) { 104void EmuWindow::GyroscopeChanged(float x, float y, float z) {
105 constexpr float FULL_FPS = 60; 105 constexpr float FULL_FPS = 60;
106 float coef = GetGyroscopeRawToDpsCoefficient(); 106 float coef = GetGyroscopeRawToDpsCoefficient();
107 float stretch = 107 float stretch = Core::System::GetInstance().perf_stats.Lock()->GetLastFrameTimeScale();
108 FULL_FPS / Common::Profiling::GetTimingResultsAggregator()->GetAggregatedResults().fps;
109 std::lock_guard<std::mutex> lock(gyro_mutex); 108 std::lock_guard<std::mutex> lock(gyro_mutex);
110 gyro_x = static_cast<s16>(x * coef * stretch); 109 gyro_x = static_cast<s16>(x * coef * stretch);
111 gyro_y = static_cast<s16>(y * coef * stretch); 110 gyro_y = static_cast<s16>(y * coef * stretch);
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index 6d9e603e4..8d9e521a3 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -6,6 +6,9 @@
6#include "core/hw/gpu.h" 6#include "core/hw/gpu.h"
7#include "core/perf_stats.h" 7#include "core/perf_stats.h"
8 8
9using DoubleSecs = std::chrono::duration<double, std::chrono::seconds::period>;
10using std::chrono::duration_cast;
11
9namespace Core { 12namespace Core {
10 13
11void PerfStats::BeginSystemFrame() { 14void PerfStats::BeginSystemFrame() {
@@ -16,6 +19,9 @@ void PerfStats::EndSystemFrame() {
16 auto frame_end = Clock::now(); 19 auto frame_end = Clock::now();
17 accumulated_frametime += frame_end - frame_begin; 20 accumulated_frametime += frame_end - frame_begin;
18 system_frames += 1; 21 system_frames += 1;
22
23 previous_frame_length = frame_end - previous_frame_end;
24 previous_frame_end = frame_end;
19} 25}
20 26
21void PerfStats::EndGameFrame() { 27void PerfStats::EndGameFrame() {
@@ -23,9 +29,6 @@ void PerfStats::EndGameFrame() {
23} 29}
24 30
25PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { 31PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
26 using DoubleSecs = std::chrono::duration<double, std::chrono::seconds::period>;
27 using std::chrono::duration_cast;
28
29 auto now = Clock::now(); 32 auto now = Clock::now();
30 // Walltime elapsed since stats were reset 33 // Walltime elapsed since stats were reset
31 auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); 34 auto interval = duration_cast<DoubleSecs>(now - reset_point).count();
@@ -50,4 +53,9 @@ PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
50 return results; 53 return results;
51} 54}
52 55
56double PerfStats::GetLastFrameTimeScale() {
57 constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
58 return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
59}
60
53} // namespace Core 61} // namespace Core
diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h
index 566a1419a..8a03c511a 100644
--- a/src/core/perf_stats.h
+++ b/src/core/perf_stats.h
@@ -30,11 +30,19 @@ public:
30 30
31 Results GetAndResetStats(u64 current_system_time_us); 31 Results GetAndResetStats(u64 current_system_time_us);
32 32
33 /**
34 * Gets the ratio between walltime and the emulated time of the previous system frame. This is
35 * useful for scaling inputs or outputs moving between the two time domains.
36 */
37 double GetLastFrameTimeScale();
38
33private: 39private:
34 Clock::time_point reset_point = Clock::now(); 40 Clock::time_point reset_point = Clock::now();
35 41
36 Clock::time_point frame_begin; 42 Clock::time_point frame_begin = reset_point;
43 Clock::time_point previous_frame_end = reset_point;
37 Clock::duration accumulated_frametime = Clock::duration::zero(); 44 Clock::duration accumulated_frametime = Clock::duration::zero();
45 Clock::duration previous_frame_length = Clock::duration::zero();
38 u64 reset_point_system_us = 0; 46 u64 reset_point_system_us = 0;
39 u32 system_frames = 0; 47 u32 system_frames = 0;
40 u32 game_frames = 0; 48 u32 game_frames = 0;