|
|
@ -3,6 +3,7 @@ |
|
|
// Refer to the license.txt file included.
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
#include <chrono>
|
|
|
|
|
|
#include <mutex>
|
|
|
#include "core/hw/gpu.h"
|
|
|
#include "core/hw/gpu.h"
|
|
|
#include "core/perf_stats.h"
|
|
|
#include "core/perf_stats.h"
|
|
|
|
|
|
|
|
|
@ -12,10 +13,14 @@ using std::chrono::duration_cast; |
|
|
namespace Core { |
|
|
namespace Core { |
|
|
|
|
|
|
|
|
void PerfStats::BeginSystemFrame() { |
|
|
void PerfStats::BeginSystemFrame() { |
|
|
|
|
|
std::lock_guard<std::mutex> lock(object_mutex); |
|
|
|
|
|
|
|
|
frame_begin = Clock::now(); |
|
|
frame_begin = Clock::now(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void PerfStats::EndSystemFrame() { |
|
|
void PerfStats::EndSystemFrame() { |
|
|
|
|
|
std::lock_guard<std::mutex> lock(object_mutex); |
|
|
|
|
|
|
|
|
auto frame_end = Clock::now(); |
|
|
auto frame_end = Clock::now(); |
|
|
accumulated_frametime += frame_end - frame_begin; |
|
|
accumulated_frametime += frame_end - frame_begin; |
|
|
system_frames += 1; |
|
|
system_frames += 1; |
|
|
@ -25,10 +30,14 @@ void PerfStats::EndSystemFrame() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void PerfStats::EndGameFrame() { |
|
|
void PerfStats::EndGameFrame() { |
|
|
|
|
|
std::lock_guard<std::mutex> lock(object_mutex); |
|
|
|
|
|
|
|
|
game_frames += 1; |
|
|
game_frames += 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { |
|
|
PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { |
|
|
|
|
|
std::lock_guard<std::mutex> lock(object_mutex); |
|
|
|
|
|
|
|
|
auto now = Clock::now(); |
|
|
auto now = Clock::now(); |
|
|
// Walltime elapsed since stats were reset
|
|
|
// Walltime elapsed since stats were reset
|
|
|
auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); |
|
|
auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); |
|
|
@ -54,6 +63,8 @@ PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double PerfStats::GetLastFrameTimeScale() { |
|
|
double PerfStats::GetLastFrameTimeScale() { |
|
|
|
|
|
std::lock_guard<std::mutex> lock(object_mutex); |
|
|
|
|
|
|
|
|
constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; |
|
|
constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; |
|
|
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; |
|
|
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; |
|
|
} |
|
|
} |
|
|
|