summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/perf_stats.cpp14
-rw-r--r--src/core/perf_stats.h1
2 files changed, 9 insertions, 6 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index bfab77abb..d2c69d1a0 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -9,8 +9,8 @@
9#include <numeric> 9#include <numeric>
10#include <sstream> 10#include <sstream>
11#include <thread> 11#include <thread>
12#include <fmt/chrono.h>
12#include <fmt/format.h> 13#include <fmt/format.h>
13#include <fmt/time.h>
14#include "common/file_util.h" 14#include "common/file_util.h"
15#include "common/math_util.h" 15#include "common/math_util.h"
16#include "core/perf_stats.h" 16#include "core/perf_stats.h"
@@ -34,13 +34,13 @@ PerfStats::~PerfStats() {
34 return; 34 return;
35 } 35 }
36 36
37 std::time_t t = std::time(nullptr); 37 const std::time_t t = std::time(nullptr);
38 std::ostringstream stream; 38 std::ostringstream stream;
39 std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index, 39 std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index,
40 std::ostream_iterator<double>(stream, "\n")); 40 std::ostream_iterator<double>(stream, "\n"));
41 std::string path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); 41 const std::string& path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
42 // %F Date format expanded is "%Y-%m-%d" 42 // %F Date format expanded is "%Y-%m-%d"
43 std::string filename = 43 const std::string filename =
44 fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id); 44 fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id);
45 FileUtil::IOFile file(filename, "w"); 45 FileUtil::IOFile file(filename, "w");
46 file.WriteString(stream.str()); 46 file.WriteString(stream.str());
@@ -75,11 +75,13 @@ void PerfStats::EndGameFrame() {
75} 75}
76 76
77double PerfStats::GetMeanFrametime() { 77double PerfStats::GetMeanFrametime() {
78 std::lock_guard lock{object_mutex};
79
78 if (current_index <= IgnoreFrames) { 80 if (current_index <= IgnoreFrames) {
79 return 0; 81 return 0;
80 } 82 }
81 double sum = std::accumulate(perf_history.begin() + IgnoreFrames, 83 const double sum = std::accumulate(perf_history.begin() + IgnoreFrames,
82 perf_history.begin() + current_index, 0); 84 perf_history.begin() + current_index, 0);
83 return sum / (current_index - IgnoreFrames); 85 return sum / (current_index - IgnoreFrames);
84} 86}
85 87
diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h
index 2db290c09..d9a64f072 100644
--- a/src/core/perf_stats.h
+++ b/src/core/perf_stats.h
@@ -6,6 +6,7 @@
6 6
7#include <array> 7#include <array>
8#include <chrono> 8#include <chrono>
9#include <cstddef>
9#include <mutex> 10#include <mutex>
10#include "common/common_types.h" 11#include "common/common_types.h"
11 12