diff options
author | fearlessTobi <thm.frey@gmail.com> | 2019-08-26 17:29:08 +0200 |
---|---|---|
committer | FearlessTobi <thm.frey@gmail.com> | 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 yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.gz yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.bz2 yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.lz yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.xz yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.tar.zst yuzu-684b616f0d6445b753dded31554e0b006b6d2c3e.zip |
Diffstat (limited to '')
-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 @@ #include <algorithm> #include <chrono> +#include <iterator> #include <mutex> +#include <numeric> +#include <sstream> #include <thread> +#include <fmt/format.h> +#include <fmt/time.h> +#include "common/file_util.h" #include "common/math_util.h" #include "core/perf_stats.h" #include "core/settings.h" @@ -15,8 +21,31 @@ using DoubleSecs = std::chrono::duration<double, std::chrono::seconds::period>; using std::chrono::duration_cast; using std::chrono::microseconds; +// Purposefully ignore the first five frames, as there's a significant amount of overhead in +// booting that we shouldn't account for +constexpr std::size_t IgnoreFrames = 5; + namespace Core { +PerfStats::PerfStats(u64 title_id) : title_id(title_id) {} + +PerfStats::~PerfStats() { + if (!Settings::values.record_frame_times || title_id == 0) { + return; + } + + std::time_t t = std::time(nullptr); + std::ostringstream stream; + std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index, + std::ostream_iterator<double>(stream, "\n")); + std::string path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); + // %F Date format expanded is "%Y-%m-%d" + std::string filename = + fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id); + FileUtil::IOFile file(filename, "w"); + file.WriteString(stream.str()); +} + void PerfStats::BeginSystemFrame() { std::lock_guard lock{object_mutex}; @@ -27,7 +56,12 @@ void PerfStats::EndSystemFrame() { std::lock_guard lock{object_mutex}; auto frame_end = Clock::now(); - accumulated_frametime += frame_end - frame_begin; + const auto frame_time = frame_end - frame_begin; + if (current_index < perf_history.size()) { + perf_history[current_index++] = + std::chrono::duration<double, std::milli>(frame_time).count(); + } + accumulated_frametime += frame_time; system_frames += 1; previous_frame_length = frame_end - previous_frame_end; @@ -40,6 +74,15 @@ void PerfStats::EndGameFrame() { game_frames += 1; } +double PerfStats::GetMeanFrametime() { + if (current_index <= IgnoreFrames) { + return 0; + } + double sum = std::accumulate(perf_history.begin() + IgnoreFrames, + perf_history.begin() + current_index, 0); + return sum / (current_index - IgnoreFrames); +} + PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { std::lock_guard lock{object_mutex}; |