diff options
| author | 2019-08-26 17:29:08 +0200 | |
|---|---|---|
| committer | 2019-09-10 12:44:19 +0200 | |
| commit | 684b616f0d6445b753dded31554e0b006b6d2c3e (patch) | |
| tree | 6caaae05a26149df5919a3876c1b0b4b4789614d /src/core/perf_stats.cpp | |
| parent | Merge pull request #2847 from VelocityRa/nro-nacp-fix (diff) | |
| download | yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.gz yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.xz yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.zip | |
Add frametime logging for tracking performance over time
Co-Authored-By: jroweboy <jroweboy@gmail.com>
Diffstat (limited to 'src/core/perf_stats.cpp')
| -rw-r--r-- | src/core/perf_stats.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 4afd6c8a3..bfab77abb 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/format.h> | ||
| 13 | #include <fmt/time.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 | 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 | std::string path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); | ||
| 42 | // %F Date format expanded is "%Y-%m-%d" | ||
| 43 | 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,15 @@ void PerfStats::EndGameFrame() { | |||
| 40 | game_frames += 1; | 74 | game_frames += 1; |
| 41 | } | 75 | } |
| 42 | 76 | ||
| 77 | double PerfStats::GetMeanFrametime() { | ||
| 78 | if (current_index <= IgnoreFrames) { | ||
| 79 | return 0; | ||
| 80 | } | ||
| 81 | double sum = std::accumulate(perf_history.begin() + IgnoreFrames, | ||
| 82 | perf_history.begin() + current_index, 0); | ||
| 83 | return sum / (current_index - IgnoreFrames); | ||
| 84 | } | ||
| 85 | |||
| 43 | PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { | 86 | PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { |
| 44 | std::lock_guard lock{object_mutex}; | 87 | std::lock_guard lock{object_mutex}; |
| 45 | 88 | ||