mirror of https://git.suyu.dev/suyu/suyu
Merge pull request #2587 from yuriks/status-bar
Replace built-in Profiler with indicators in status barmerge-requests/60/head
commit
b250ce21b9
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Profiler</class>
|
||||
<widget class="QDockWidget" name="Profiler">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Profiler</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeView">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -1,101 +0,0 @@
|
||||
// Copyright 2015 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include "common/assert.h"
|
||||
#include "common/profiler_reporting.h"
|
||||
#include "common/synchronized_wrapper.h"
|
||||
|
||||
namespace Common {
|
||||
namespace Profiling {
|
||||
|
||||
ProfilingManager::ProfilingManager()
|
||||
: last_frame_end(Clock::now()), this_frame_start(Clock::now()) {}
|
||||
|
||||
void ProfilingManager::BeginFrame() {
|
||||
this_frame_start = Clock::now();
|
||||
}
|
||||
|
||||
void ProfilingManager::FinishFrame() {
|
||||
Clock::time_point now = Clock::now();
|
||||
|
||||
results.interframe_time = now - last_frame_end;
|
||||
results.frame_time = now - this_frame_start;
|
||||
|
||||
last_frame_end = now;
|
||||
}
|
||||
|
||||
TimingResultsAggregator::TimingResultsAggregator(size_t window_size)
|
||||
: max_window_size(window_size), window_size(0) {
|
||||
interframe_times.resize(window_size, Duration::zero());
|
||||
frame_times.resize(window_size, Duration::zero());
|
||||
}
|
||||
|
||||
void TimingResultsAggregator::Clear() {
|
||||
window_size = cursor = 0;
|
||||
}
|
||||
|
||||
void TimingResultsAggregator::AddFrame(const ProfilingFrameResult& frame_result) {
|
||||
interframe_times[cursor] = frame_result.interframe_time;
|
||||
frame_times[cursor] = frame_result.frame_time;
|
||||
|
||||
++cursor;
|
||||
if (cursor == max_window_size)
|
||||
cursor = 0;
|
||||
if (window_size < max_window_size)
|
||||
++window_size;
|
||||
}
|
||||
|
||||
static AggregatedDuration AggregateField(const std::vector<Duration>& v, size_t len) {
|
||||
AggregatedDuration result;
|
||||
result.avg = Duration::zero();
|
||||
result.min = result.max = (len == 0 ? Duration::zero() : v[0]);
|
||||
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
Duration value = v[i];
|
||||
result.avg += value;
|
||||
result.min = std::min(result.min, value);
|
||||
result.max = std::max(result.max, value);
|
||||
}
|
||||
if (len != 0)
|
||||
result.avg /= len;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static float tof(Common::Profiling::Duration dur) {
|
||||
using FloatMs = std::chrono::duration<float, std::chrono::milliseconds::period>;
|
||||
return std::chrono::duration_cast<FloatMs>(dur).count();
|
||||
}
|
||||
|
||||
AggregatedFrameResult TimingResultsAggregator::GetAggregatedResults() const {
|
||||
AggregatedFrameResult result;
|
||||
|
||||
result.interframe_time = AggregateField(interframe_times, window_size);
|
||||
result.frame_time = AggregateField(frame_times, window_size);
|
||||
|
||||
if (result.interframe_time.avg != Duration::zero()) {
|
||||
result.fps = 1000.0f / tof(result.interframe_time.avg);
|
||||
} else {
|
||||
result.fps = 0.0f;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ProfilingManager& GetProfilingManager() {
|
||||
// Takes advantage of "magic" static initialization for race-free initialization.
|
||||
static ProfilingManager manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator() {
|
||||
static SynchronizedWrapper<TimingResultsAggregator> aggregator(30);
|
||||
return SynchronizedRef<TimingResultsAggregator>(aggregator);
|
||||
}
|
||||
|
||||
} // namespace Profiling
|
||||
} // namespace Common
|
@ -1,83 +0,0 @@
|
||||
// Copyright 2015 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include "common/synchronized_wrapper.h"
|
||||
|
||||
namespace Common {
|
||||
namespace Profiling {
|
||||
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
using Duration = Clock::duration;
|
||||
|
||||
struct ProfilingFrameResult {
|
||||
/// Time since the last delivered frame
|
||||
Duration interframe_time;
|
||||
|
||||
/// Time spent processing a frame, excluding VSync
|
||||
Duration frame_time;
|
||||
};
|
||||
|
||||
class ProfilingManager final {
|
||||
public:
|
||||
ProfilingManager();
|
||||
|
||||
/// This should be called after swapping screen buffers.
|
||||
void BeginFrame();
|
||||
/// This should be called before swapping screen buffers.
|
||||
void FinishFrame();
|
||||
|
||||
/// Get the timing results from the previous frame. This is updated when you call FinishFrame().
|
||||
const ProfilingFrameResult& GetPreviousFrameResults() const {
|
||||
return results;
|
||||
}
|
||||
|
||||
private:
|
||||
Clock::time_point last_frame_end;
|
||||
Clock::time_point this_frame_start;
|
||||
|
||||
ProfilingFrameResult results;
|
||||
};
|
||||
|
||||
struct AggregatedDuration {
|
||||
Duration avg, min, max;
|
||||
};
|
||||
|
||||
struct AggregatedFrameResult {
|
||||
/// Time since the last delivered frame
|
||||
AggregatedDuration interframe_time;
|
||||
|
||||
/// Time spent processing a frame, excluding VSync
|
||||
AggregatedDuration frame_time;
|
||||
|
||||
float fps;
|
||||
};
|
||||
|
||||
class TimingResultsAggregator final {
|
||||
public:
|
||||
TimingResultsAggregator(size_t window_size);
|
||||
|
||||
void Clear();
|
||||
|
||||
void AddFrame(const ProfilingFrameResult& frame_result);
|
||||
|
||||
AggregatedFrameResult GetAggregatedResults() const;
|
||||
|
||||
size_t max_window_size;
|
||||
size_t window_size;
|
||||
size_t cursor;
|
||||
|
||||
std::vector<Duration> interframe_times;
|
||||
std::vector<Duration> frame_times;
|
||||
};
|
||||
|
||||
ProfilingManager& GetProfilingManager();
|
||||
SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator();
|
||||
|
||||
} // namespace Profiling
|
||||
} // namespace Common
|
@ -0,0 +1,105 @@
|
||||
// Copyright 2017 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "common/math_util.h"
|
||||
#include "core/hw/gpu.h"
|
||||
#include "core/perf_stats.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using DoubleSecs = std::chrono::duration<double, std::chrono::seconds::period>;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::microseconds;
|
||||
|
||||
namespace Core {
|
||||
|
||||
void PerfStats::BeginSystemFrame() {
|
||||
std::lock_guard<std::mutex> lock(object_mutex);
|
||||
|
||||
frame_begin = Clock::now();
|
||||
}
|
||||
|
||||
void PerfStats::EndSystemFrame() {
|
||||
std::lock_guard<std::mutex> lock(object_mutex);
|
||||
|
||||
auto frame_end = Clock::now();
|
||||
accumulated_frametime += frame_end - frame_begin;
|
||||
system_frames += 1;
|
||||
|
||||
previous_frame_length = frame_end - previous_frame_end;
|
||||
previous_frame_end = frame_end;
|
||||
}
|
||||
|
||||
void PerfStats::EndGameFrame() {
|
||||
std::lock_guard<std::mutex> lock(object_mutex);
|
||||
|
||||
game_frames += 1;
|
||||
}
|
||||
|
||||
PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
|
||||
std::lock_guard<std::mutex> lock(object_mutex);
|
||||
|
||||
auto now = Clock::now();
|
||||
// Walltime elapsed since stats were reset
|
||||
auto interval = duration_cast<DoubleSecs>(now - reset_point).count();
|
||||
|
||||
auto system_us_per_second =
|
||||
static_cast<double>(current_system_time_us - reset_point_system_us) / interval;
|
||||
|
||||
Results results{};
|
||||
results.system_fps = static_cast<double>(system_frames) / interval;
|
||||
results.game_fps = static_cast<double>(game_frames) / interval;
|
||||
results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() /
|
||||
static_cast<double>(system_frames);
|
||||
results.emulation_speed = system_us_per_second / 1'000'000.0;
|
||||
|
||||
// Reset counters
|
||||
reset_point = now;
|
||||
reset_point_system_us = current_system_time_us;
|
||||
accumulated_frametime = Clock::duration::zero();
|
||||
system_frames = 0;
|
||||
game_frames = 0;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
double PerfStats::GetLastFrameTimeScale() {
|
||||
std::lock_guard<std::mutex> lock(object_mutex);
|
||||
|
||||
constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
|
||||
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
|
||||
}
|
||||
|
||||
void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) {
|
||||
// Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher
|
||||
// values increase the time needed to recover and limit framerate again after spikes.
|
||||
constexpr microseconds MAX_LAG_TIME_US = 25ms;
|
||||
|
||||
if (!Settings::values.toggle_framelimit) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto now = Clock::now();
|
||||
|
||||
frame_limiting_delta_err += microseconds(current_system_time_us - previous_system_time_us);
|
||||
frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime);
|
||||
frame_limiting_delta_err =
|
||||
MathUtil::Clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US);
|
||||
|
||||
if (frame_limiting_delta_err > microseconds::zero()) {
|
||||
std::this_thread::sleep_for(frame_limiting_delta_err);
|
||||
|
||||
auto now_after_sleep = Clock::now();
|
||||
frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now);
|
||||
now = now_after_sleep;
|
||||
}
|
||||
|
||||
previous_system_time_us = current_system_time_us;
|
||||
previous_walltime = now;
|
||||
}
|
||||
|
||||
} // namespace Core
|
@ -0,0 +1,83 @@
|
||||
// Copyright 2017 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
/**
|
||||
* Class to manage and query performance/timing statistics. All public functions of this class are
|
||||
* thread-safe unless stated otherwise.
|
||||
*/
|
||||
class PerfStats {
|
||||
public:
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
|
||||
struct Results {
|
||||
/// System FPS (LCD VBlanks) in Hz
|
||||
double system_fps;
|
||||
/// Game FPS (GSP frame submissions) in Hz
|
||||
double game_fps;
|
||||
/// Walltime per system frame, in seconds, excluding any waits
|
||||
double frametime;
|
||||
/// Ratio of walltime / emulated time elapsed
|
||||
double emulation_speed;
|
||||
};
|
||||
|
||||
void BeginSystemFrame();
|
||||
void EndSystemFrame();
|
||||
void EndGameFrame();
|
||||
|
||||
Results GetAndResetStats(u64 current_system_time_us);
|
||||
|
||||
/**
|
||||
* Gets the ratio between walltime and the emulated time of the previous system frame. This is
|
||||
* useful for scaling inputs or outputs moving between the two time domains.
|
||||
*/
|
||||
double GetLastFrameTimeScale();
|
||||
|
||||
private:
|
||||
std::mutex object_mutex;
|
||||
|
||||
/// Point when the cumulative counters were reset
|
||||
Clock::time_point reset_point = Clock::now();
|
||||
/// System time when the cumulative counters were reset
|
||||
u64 reset_point_system_us = 0;
|
||||
|
||||
/// Cumulative duration (excluding v-sync/frame-limiting) of frames since last reset
|
||||
Clock::duration accumulated_frametime = Clock::duration::zero();
|
||||
/// Cumulative number of system frames (LCD VBlanks) presented since last reset
|
||||
u32 system_frames = 0;
|
||||
/// Cumulative number of game frames (GSP frame submissions) since last reset
|
||||
u32 game_frames = 0;
|
||||
|
||||
/// Point when the previous system frame ended
|
||||
Clock::time_point previous_frame_end = reset_point;
|
||||
/// Point when the current system frame began
|
||||
Clock::time_point frame_begin = reset_point;
|
||||
/// Total visible duration (including frame-limiting, etc.) of the previous system frame
|
||||
Clock::duration previous_frame_length = Clock::duration::zero();
|
||||
};
|
||||
|
||||
class FrameLimiter {
|
||||
public:
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
|
||||
void DoFrameLimiting(u64 current_system_time_us);
|
||||
|
||||
private:
|
||||
/// Emulated system time (in microseconds) at the last limiter invocation
|
||||
u64 previous_system_time_us = 0;
|
||||
/// Walltime at the last limiter invocation
|
||||
Clock::time_point previous_walltime = Clock::now();
|
||||
|
||||
/// Accumulated difference between walltime and emulated time
|
||||
std::chrono::microseconds frame_limiting_delta_err{0};
|
||||
};
|
||||
|
||||
} // namespace Core
|
Loading…
Reference in New Issue