forked from suyu/suyu
Merge pull request #4472 from lioncash/const-get
perf_stats: Mark GetMeanFrametime() as const
This commit is contained in:
commit
ecbee11829
2 changed files with 16 additions and 15 deletions
|
@ -74,15 +74,16 @@ void PerfStats::EndGameFrame() {
|
||||||
game_frames += 1;
|
game_frames += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double PerfStats::GetMeanFrametime() {
|
double PerfStats::GetMeanFrametime() const {
|
||||||
std::lock_guard lock{object_mutex};
|
std::lock_guard lock{object_mutex};
|
||||||
|
|
||||||
if (current_index <= IgnoreFrames) {
|
if (current_index <= IgnoreFrames) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double sum = std::accumulate(perf_history.begin() + IgnoreFrames,
|
const double sum = std::accumulate(perf_history.begin() + IgnoreFrames,
|
||||||
perf_history.begin() + current_index, 0.0);
|
perf_history.begin() + current_index, 0.0);
|
||||||
return sum / (current_index - IgnoreFrames);
|
return sum / static_cast<double>(current_index - IgnoreFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) {
|
PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) {
|
||||||
|
@ -94,12 +95,13 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us
|
||||||
|
|
||||||
const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval;
|
const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval;
|
||||||
|
|
||||||
PerfStatsResults results{};
|
const PerfStatsResults results{
|
||||||
results.system_fps = static_cast<double>(system_frames) / interval;
|
.system_fps = static_cast<double>(system_frames) / interval,
|
||||||
results.game_fps = static_cast<double>(game_frames) / interval;
|
.game_fps = static_cast<double>(game_frames) / interval,
|
||||||
results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() /
|
.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() /
|
||||||
static_cast<double>(system_frames);
|
static_cast<double>(system_frames),
|
||||||
results.emulation_speed = system_us_per_second.count() / 1'000'000.0;
|
.emulation_speed = system_us_per_second.count() / 1'000'000.0,
|
||||||
|
};
|
||||||
|
|
||||||
// Reset counters
|
// Reset counters
|
||||||
reset_point = now;
|
reset_point = now;
|
||||||
|
@ -111,7 +113,7 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
double PerfStats::GetLastFrameTimeScale() {
|
double PerfStats::GetLastFrameTimeScale() const {
|
||||||
std::lock_guard lock{object_mutex};
|
std::lock_guard lock{object_mutex};
|
||||||
|
|
||||||
constexpr double FRAME_LENGTH = 1.0 / 60;
|
constexpr double FRAME_LENGTH = 1.0 / 60;
|
||||||
|
|
|
@ -30,7 +30,6 @@ struct PerfStatsResults {
|
||||||
class PerfStats {
|
class PerfStats {
|
||||||
public:
|
public:
|
||||||
explicit PerfStats(u64 title_id);
|
explicit PerfStats(u64 title_id);
|
||||||
|
|
||||||
~PerfStats();
|
~PerfStats();
|
||||||
|
|
||||||
using Clock = std::chrono::high_resolution_clock;
|
using Clock = std::chrono::high_resolution_clock;
|
||||||
|
@ -42,18 +41,18 @@ public:
|
||||||
PerfStatsResults GetAndResetStats(std::chrono::microseconds current_system_time_us);
|
PerfStatsResults GetAndResetStats(std::chrono::microseconds current_system_time_us);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Arthimetic Mean of all frametime values stored in the performance history.
|
* Returns the arithmetic mean of all frametime values stored in the performance history.
|
||||||
*/
|
*/
|
||||||
double GetMeanFrametime();
|
double GetMeanFrametime() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ratio between walltime and the emulated time of the previous system frame. This is
|
* 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.
|
* useful for scaling inputs or outputs moving between the two time domains.
|
||||||
*/
|
*/
|
||||||
double GetLastFrameTimeScale();
|
double GetLastFrameTimeScale() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex object_mutex{};
|
mutable std::mutex object_mutex;
|
||||||
|
|
||||||
/// Title ID for the game that is running. 0 if there is no game running yet
|
/// Title ID for the game that is running. 0 if there is no game running yet
|
||||||
u64 title_id{0};
|
u64 title_id{0};
|
||||||
|
@ -61,7 +60,7 @@ private:
|
||||||
std::size_t current_index{0};
|
std::size_t current_index{0};
|
||||||
/// Stores an hour of historical frametime data useful for processing and tracking performance
|
/// Stores an hour of historical frametime data useful for processing and tracking performance
|
||||||
/// regressions with code changes.
|
/// regressions with code changes.
|
||||||
std::array<double, 216000> perf_history = {};
|
std::array<double, 216000> perf_history{};
|
||||||
|
|
||||||
/// Point when the cumulative counters were reset
|
/// Point when the cumulative counters were reset
|
||||||
Clock::time_point reset_point = Clock::now();
|
Clock::time_point reset_point = Clock::now();
|
||||||
|
|
Loading…
Reference in a new issue