From 0a3f75c25ff5a61dd210c320f163c6844a5d29fe Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sun, 22 Sep 2019 17:40:04 +0200 Subject: [PATCH] Backport changes from yuzu-emu/yuzu#2806 --- src/core/perf_stats.cpp | 12 +++++++----- src/core/perf_stats.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 8015ef731..94d6c17ca 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -33,13 +33,13 @@ PerfStats::~PerfStats() { return; } - std::time_t t = std::time(nullptr); + const std::time_t t = std::time(nullptr); std::ostringstream stream; std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index, std::ostream_iterator(stream, "\n")); - std::string path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); + const std::string& path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); // %F Date format expanded is "%Y-%m-%d" - std::string filename = + const 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()); @@ -74,11 +74,13 @@ void PerfStats::EndGameFrame() { } double PerfStats::GetMeanFrametime() { + std::lock_guard lock{object_mutex}; + if (current_index <= IgnoreFrames) { return 0; } - double sum = std::accumulate(perf_history.begin() + IgnoreFrames, - perf_history.begin() + current_index, 0); + const double sum = std::accumulate(perf_history.begin() + IgnoreFrames, + perf_history.begin() + current_index, 0); return sum / (current_index - IgnoreFrames); } diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h index e0b023059..0ef5168fa 100644 --- a/src/core/perf_stats.h +++ b/src/core/perf_stats.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "common/common_types.h" #include "common/thread.h"