Add frametime logging for tracking performance over time
Co-Authored-By: jroweboy <jroweboy@gmail.com>
This commit is contained in:
parent
07a0242535
commit
684b616f0d
7 changed files with 90 additions and 10 deletions
|
@ -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};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue