summaryrefslogtreecommitdiff
path: root/src/core/perf_stats.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-02-20 13:56:58 -0800
committerGravatar Yuri Kunde Schlesner2017-02-26 17:22:03 -0800
commitb285c2a4ed29a126b5bcfe46e2784bd1870bdf82 (patch)
treea671ac87427fb63a64f51be260928cb39b8d3737 /src/core/perf_stats.cpp
parentQt: Add tooltips to status bar displays (diff)
downloadyuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.gz
yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.xz
yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.zip
Core: Make PerfStats internally locked
More ergonomic to use and will be required for upcoming changes.
Diffstat (limited to 'src/core/perf_stats.cpp')
-rw-r--r--src/core/perf_stats.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index 8d9e521a3..06bc788bd 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <chrono> 5#include <chrono>
6#include <mutex>
6#include "core/hw/gpu.h" 7#include "core/hw/gpu.h"
7#include "core/perf_stats.h" 8#include "core/perf_stats.h"
8 9
@@ -12,10 +13,14 @@ using std::chrono::duration_cast;
12namespace Core { 13namespace Core {
13 14
14void PerfStats::BeginSystemFrame() { 15void PerfStats::BeginSystemFrame() {
16 std::lock_guard<std::mutex> lock(object_mutex);
17
15 frame_begin = Clock::now(); 18 frame_begin = Clock::now();
16} 19}
17 20
18void PerfStats::EndSystemFrame() { 21void PerfStats::EndSystemFrame() {
22 std::lock_guard<std::mutex> lock(object_mutex);
23
19 auto frame_end = Clock::now(); 24 auto frame_end = Clock::now();
20 accumulated_frametime += frame_end - frame_begin; 25 accumulated_frametime += frame_end - frame_begin;
21 system_frames += 1; 26 system_frames += 1;
@@ -25,10 +30,14 @@ void PerfStats::EndSystemFrame() {
25} 30}
26 31
27void PerfStats::EndGameFrame() { 32void PerfStats::EndGameFrame() {
33 std::lock_guard<std::mutex> lock(object_mutex);
34
28 game_frames += 1; 35 game_frames += 1;
29} 36}
30 37
31PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { 38PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
39 std::lock_guard<std::mutex> lock(object_mutex);
40
32 auto now = Clock::now(); 41 auto now = Clock::now();
33 // Walltime elapsed since stats were reset 42 // Walltime elapsed since stats were reset
34 auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); 43 auto interval = duration_cast<DoubleSecs>(now - reset_point).count();
@@ -54,6 +63,8 @@ PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
54} 63}
55 64
56double PerfStats::GetLastFrameTimeScale() { 65double PerfStats::GetLastFrameTimeScale() {
66 std::lock_guard<std::mutex> lock(object_mutex);
67
57 constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; 68 constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
58 return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; 69 return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
59} 70}