diff options
| author | 2019-09-21 20:09:55 +1000 | |
|---|---|---|
| committer | 2019-09-21 20:09:55 +1000 | |
| commit | 183c445c30ad9fa1f58660ff578ecf1b78e51b25 (patch) | |
| tree | 045c4a6945449d563ea420fbf5a4916cbde1f8b3 /src/core/perf_stats.cpp | |
| parent | Merge pull request #2872 from FernandoS27/mem-gpu-opt (diff) | |
| parent | Address review comments (diff) | |
| download | yuzu-183c445c30ad9fa1f58660ff578ecf1b78e51b25.tar.gz yuzu-183c445c30ad9fa1f58660ff578ecf1b78e51b25.tar.xz yuzu-183c445c30ad9fa1f58660ff578ecf1b78e51b25.zip | |
Merge pull request #2806 from FearlessTobi/port-4882
Port citra-emu/citra#4882: "Add frametime logging for tracking performance over time"
Diffstat (limited to 'src/core/perf_stats.cpp')
| -rw-r--r-- | src/core/perf_stats.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 4afd6c8a3..d2c69d1a0 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp | |||
| @@ -4,8 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <chrono> | 6 | #include <chrono> |
| 7 | #include <iterator> | ||
| 7 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <numeric> | ||
| 10 | #include <sstream> | ||
| 8 | #include <thread> | 11 | #include <thread> |
| 12 | #include <fmt/chrono.h> | ||
| 13 | #include <fmt/format.h> | ||
| 14 | #include "common/file_util.h" | ||
| 9 | #include "common/math_util.h" | 15 | #include "common/math_util.h" |
| 10 | #include "core/perf_stats.h" | 16 | #include "core/perf_stats.h" |
| 11 | #include "core/settings.h" | 17 | #include "core/settings.h" |
| @@ -15,8 +21,31 @@ using DoubleSecs = std::chrono::duration<double, std::chrono::seconds::period>; | |||
| 15 | using std::chrono::duration_cast; | 21 | using std::chrono::duration_cast; |
| 16 | using std::chrono::microseconds; | 22 | using std::chrono::microseconds; |
| 17 | 23 | ||
| 24 | // Purposefully ignore the first five frames, as there's a significant amount of overhead in | ||
| 25 | // booting that we shouldn't account for | ||
| 26 | constexpr std::size_t IgnoreFrames = 5; | ||
| 27 | |||
| 18 | namespace Core { | 28 | namespace Core { |
| 19 | 29 | ||
| 30 | PerfStats::PerfStats(u64 title_id) : title_id(title_id) {} | ||
| 31 | |||
| 32 | PerfStats::~PerfStats() { | ||
| 33 | if (!Settings::values.record_frame_times || title_id == 0) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | const std::time_t t = std::time(nullptr); | ||
| 38 | std::ostringstream stream; | ||
| 39 | std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index, | ||
| 40 | std::ostream_iterator<double>(stream, "\n")); | ||
| 41 | const std::string& path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); | ||
| 42 | // %F Date format expanded is "%Y-%m-%d" | ||
| 43 | const std::string filename = | ||
| 44 | fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id); | ||
| 45 | FileUtil::IOFile file(filename, "w"); | ||
| 46 | file.WriteString(stream.str()); | ||
| 47 | } | ||
| 48 | |||
| 20 | void PerfStats::BeginSystemFrame() { | 49 | void PerfStats::BeginSystemFrame() { |
| 21 | std::lock_guard lock{object_mutex}; | 50 | std::lock_guard lock{object_mutex}; |
| 22 | 51 | ||
| @@ -27,7 +56,12 @@ void PerfStats::EndSystemFrame() { | |||
| 27 | std::lock_guard lock{object_mutex}; | 56 | std::lock_guard lock{object_mutex}; |
| 28 | 57 | ||
| 29 | auto frame_end = Clock::now(); | 58 | auto frame_end = Clock::now(); |
| 30 | accumulated_frametime += frame_end - frame_begin; | 59 | const auto frame_time = frame_end - frame_begin; |
| 60 | if (current_index < perf_history.size()) { | ||
| 61 | perf_history[current_index++] = | ||
| 62 | std::chrono::duration<double, std::milli>(frame_time).count(); | ||
| 63 | } | ||
| 64 | accumulated_frametime += frame_time; | ||
| 31 | system_frames += 1; | 65 | system_frames += 1; |
| 32 | 66 | ||
| 33 | previous_frame_length = frame_end - previous_frame_end; | 67 | previous_frame_length = frame_end - previous_frame_end; |
| @@ -40,6 +74,17 @@ void PerfStats::EndGameFrame() { | |||
| 40 | game_frames += 1; | 74 | game_frames += 1; |
| 41 | } | 75 | } |
| 42 | 76 | ||
| 77 | double PerfStats::GetMeanFrametime() { | ||
| 78 | std::lock_guard lock{object_mutex}; | ||
| 79 | |||
| 80 | if (current_index <= IgnoreFrames) { | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | const double sum = std::accumulate(perf_history.begin() + IgnoreFrames, | ||
| 84 | perf_history.begin() + current_index, 0); | ||
| 85 | return sum / (current_index - IgnoreFrames); | ||
| 86 | } | ||
| 87 | |||
| 43 | PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { | 88 | PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { |
| 44 | std::lock_guard lock{object_mutex}; | 89 | std::lock_guard lock{object_mutex}; |
| 45 | 90 | ||