diff options
Diffstat (limited to 'src/core/perf_stats.cpp')
| -rw-r--r-- | src/core/perf_stats.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp new file mode 100644 index 000000000..6d9e603e4 --- /dev/null +++ b/src/core/perf_stats.cpp | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <chrono> | ||
| 6 | #include "core/hw/gpu.h" | ||
| 7 | #include "core/perf_stats.h" | ||
| 8 | |||
| 9 | namespace Core { | ||
| 10 | |||
| 11 | void PerfStats::BeginSystemFrame() { | ||
| 12 | frame_begin = Clock::now(); | ||
| 13 | } | ||
| 14 | |||
| 15 | void PerfStats::EndSystemFrame() { | ||
| 16 | auto frame_end = Clock::now(); | ||
| 17 | accumulated_frametime += frame_end - frame_begin; | ||
| 18 | system_frames += 1; | ||
| 19 | } | ||
| 20 | |||
| 21 | void PerfStats::EndGameFrame() { | ||
| 22 | game_frames += 1; | ||
| 23 | } | ||
| 24 | |||
| 25 | PerfStats::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(); | ||
| 30 | // Walltime elapsed since stats were reset | ||
| 31 | auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); | ||
| 32 | |||
| 33 | auto system_us_per_second = | ||
| 34 | static_cast<double>(current_system_time_us - reset_point_system_us) / interval; | ||
| 35 | |||
| 36 | Results results{}; | ||
| 37 | results.system_fps = static_cast<double>(system_frames) / interval; | ||
| 38 | results.game_fps = static_cast<double>(game_frames) / interval; | ||
| 39 | results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / | ||
| 40 | static_cast<double>(system_frames); | ||
| 41 | results.emulation_speed = system_us_per_second / 1'000'000.0; | ||
| 42 | |||
| 43 | // Reset counters | ||
| 44 | reset_point = now; | ||
| 45 | reset_point_system_us = current_system_time_us; | ||
| 46 | accumulated_frametime = Clock::duration::zero(); | ||
| 47 | system_frames = 0; | ||
| 48 | game_frames = 0; | ||
| 49 | |||
| 50 | return results; | ||
| 51 | } | ||
| 52 | |||
| 53 | } // namespace Core | ||