summaryrefslogtreecommitdiff
path: root/src/core/perf_stats.h
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-02-26 17:51:15 -0800
committerGravatar GitHub2017-02-26 17:51:15 -0800
commitb250ce21b9a62cb573540fdb14f30c28fa66e6ad (patch)
treeef55a0cd4a531a097de2152f563d712551972c4b /src/core/perf_stats.h
parentMerge pull request #2595 from jroweboy/patch (diff)
parentPerfStats: Re-order and document members better (diff)
downloadyuzu-b250ce21b9a62cb573540fdb14f30c28fa66e6ad.tar.gz
yuzu-b250ce21b9a62cb573540fdb14f30c28fa66e6ad.tar.xz
yuzu-b250ce21b9a62cb573540fdb14f30c28fa66e6ad.zip
Merge pull request #2587 from yuriks/status-bar
Replace built-in Profiler with indicators in status bar
Diffstat (limited to 'src/core/perf_stats.h')
-rw-r--r--src/core/perf_stats.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h
new file mode 100644
index 000000000..362b205c8
--- /dev/null
+++ b/src/core/perf_stats.h
@@ -0,0 +1,83 @@
1// Copyright 2017 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <chrono>
8#include <mutex>
9#include "common/common_types.h"
10
11namespace Core {
12
13/**
14 * Class to manage and query performance/timing statistics. All public functions of this class are
15 * thread-safe unless stated otherwise.
16 */
17class PerfStats {
18public:
19 using Clock = std::chrono::high_resolution_clock;
20
21 struct Results {
22 /// System FPS (LCD VBlanks) in Hz
23 double system_fps;
24 /// Game FPS (GSP frame submissions) in Hz
25 double game_fps;
26 /// Walltime per system frame, in seconds, excluding any waits
27 double frametime;
28 /// Ratio of walltime / emulated time elapsed
29 double emulation_speed;
30 };
31
32 void BeginSystemFrame();
33 void EndSystemFrame();
34 void EndGameFrame();
35
36 Results GetAndResetStats(u64 current_system_time_us);
37
38 /**
39 * Gets the ratio between walltime and the emulated time of the previous system frame. This is
40 * useful for scaling inputs or outputs moving between the two time domains.
41 */
42 double GetLastFrameTimeScale();
43
44private:
45 std::mutex object_mutex;
46
47 /// Point when the cumulative counters were reset
48 Clock::time_point reset_point = Clock::now();
49 /// System time when the cumulative counters were reset
50 u64 reset_point_system_us = 0;
51
52 /// Cumulative duration (excluding v-sync/frame-limiting) of frames since last reset
53 Clock::duration accumulated_frametime = Clock::duration::zero();
54 /// Cumulative number of system frames (LCD VBlanks) presented since last reset
55 u32 system_frames = 0;
56 /// Cumulative number of game frames (GSP frame submissions) since last reset
57 u32 game_frames = 0;
58
59 /// Point when the previous system frame ended
60 Clock::time_point previous_frame_end = reset_point;
61 /// Point when the current system frame began
62 Clock::time_point frame_begin = reset_point;
63 /// Total visible duration (including frame-limiting, etc.) of the previous system frame
64 Clock::duration previous_frame_length = Clock::duration::zero();
65};
66
67class FrameLimiter {
68public:
69 using Clock = std::chrono::high_resolution_clock;
70
71 void DoFrameLimiting(u64 current_system_time_us);
72
73private:
74 /// Emulated system time (in microseconds) at the last limiter invocation
75 u64 previous_system_time_us = 0;
76 /// Walltime at the last limiter invocation
77 Clock::time_point previous_walltime = Clock::now();
78
79 /// Accumulated difference between walltime and emulated time
80 std::chrono::microseconds frame_limiting_delta_err{0};
81};
82
83} // namespace Core