Add perf stat logging through ini setting
For better tracking of performance regressions on incoming changes, this change adds a way to dump frametime to file by changing an ini config option. This is intentionally hidden as its only useful to a small number of individuals, and not really applicable to the general userbase.
This commit is contained in:
parent
84b40f2da6
commit
62e6c147ae
11 changed files with 78 additions and 11 deletions
|
@ -4,8 +4,12 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iterator>
|
||||
#include <mutex>
|
||||
#include <numeric>
|
||||
#include <thread>
|
||||
#include <fmt/format.h>
|
||||
#include "common/file_util.h"
|
||||
#include "core/hw/gpu.h"
|
||||
#include "core/perf_stats.h"
|
||||
#include "core/settings.h"
|
||||
|
@ -15,8 +19,26 @@ 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 size_t IGNORE_FRAMES = 5;
|
||||
|
||||
namespace Core {
|
||||
|
||||
PerfStats::PerfStats(u64 title_id) : title_id(title_id) {}
|
||||
|
||||
PerfStats::~PerfStats() {
|
||||
if (Settings::values.record_frame_times && title_id != 0) {
|
||||
std::ostringstream stream;
|
||||
std::copy(perf_history.begin() + IGNORE_FRAMES, perf_history.begin() + current_index,
|
||||
std::ostream_iterator<double>(stream, "\n"));
|
||||
std::string path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
||||
std::string filename = fmt::format("{}/{:X}.csv", path, title_id);
|
||||
FileUtil::IOFile file(filename, "w");
|
||||
file.WriteString(stream.str());
|
||||
}
|
||||
}
|
||||
|
||||
void PerfStats::BeginSystemFrame() {
|
||||
std::lock_guard lock{object_mutex};
|
||||
|
||||
|
@ -27,7 +49,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 +67,15 @@ void PerfStats::EndGameFrame() {
|
|||
game_frames += 1;
|
||||
}
|
||||
|
||||
double PerfStats::GetMeanFrametime() {
|
||||
if (current_index < 2) {
|
||||
return 0;
|
||||
}
|
||||
double sum = std::accumulate(perf_history.begin() + IGNORE_FRAMES,
|
||||
perf_history.begin() + current_index, 0);
|
||||
return sum / (current_index - 1 - IGNORE_FRAMES);
|
||||
}
|
||||
|
||||
PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_us) {
|
||||
std::lock_guard lock(object_mutex);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue