diff options
| author | 2017-02-20 13:56:58 -0800 | |
|---|---|---|
| committer | 2017-02-26 17:22:03 -0800 | |
| commit | b285c2a4ed29a126b5bcfe46e2784bd1870bdf82 (patch) | |
| tree | a671ac87427fb63a64f51be260928cb39b8d3737 /src/core/perf_stats.cpp | |
| parent | Qt: Add tooltips to status bar displays (diff) | |
| download | yuzu-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.cpp | 11 |
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; | |||
| 12 | namespace Core { | 13 | namespace Core { |
| 13 | 14 | ||
| 14 | void PerfStats::BeginSystemFrame() { | 15 | void 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 | ||
| 18 | void PerfStats::EndSystemFrame() { | 21 | void 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 | ||
| 27 | void PerfStats::EndGameFrame() { | 32 | void PerfStats::EndGameFrame() { |
| 33 | std::lock_guard<std::mutex> lock(object_mutex); | ||
| 34 | |||
| 28 | game_frames += 1; | 35 | game_frames += 1; |
| 29 | } | 36 | } |
| 30 | 37 | ||
| 31 | PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { | 38 | PerfStats::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 | ||
| 56 | double PerfStats::GetLastFrameTimeScale() { | 65 | double 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 | } |