Measure frame times at frame granularity.

This commit is contained in:
Themaister 2013-02-10 01:42:56 +01:00
parent cb1c3b5943
commit 3b5eedeab5
3 changed files with 25 additions and 23 deletions

View File

@ -492,11 +492,13 @@ static void compute_audio_buffer_statistics(void)
static void compute_monitor_fps_statistics(void)
{
unsigned samples = min(g_extern.measure_data.frame_time_samples_count,
MEASURE_FRAME_TIME_SAMPLES_COUNT);
if (samples < 3)
if (g_extern.measure_data.frame_time_samples_count < 2 * MEASURE_FRAME_TIME_SAMPLES_COUNT)
{
RARCH_LOG("Does not have enough samples for monitor refresh rate estimation.\n");
return;
}
unsigned samples = MEASURE_FRAME_TIME_SAMPLES_COUNT;
// Measure statistics on frame time (microsecs), *not* FPS.
rarch_time_t accum = 0;
@ -515,20 +517,15 @@ static void compute_monitor_fps_statistics(void)
// Drop first measurement. It is likely to be bad.
for (unsigned i = 1; i < samples; i++)
{
rarch_time_t diff = avg - g_extern.measure_data.frame_time_samples[i];
rarch_time_t diff = g_extern.measure_data.frame_time_samples[i] - avg;
accum_var += diff * diff;
}
double stddev = sqrt((double)accum_var / (samples - 2));
double avg_fps = 1000000.0 / avg;
double max_stddev_fps = 1000000.0 / (avg - stddev);
double stddev_fps = max_stddev_fps - avg_fps;
double sigma_deviation = (g_settings.video.refresh_rate - avg_fps) / stddev_fps;
RARCH_LOG("Average monitor Hz: %.6f Hz. Standard deviation: %.6f Hz (%.3f %% deviation, based on %u last samples).\n",
avg_fps, stddev_fps, 100.0 * stddev_fps / avg_fps, samples);
RARCH_LOG("Configured monitor FPS %.6f Hz deviates %.3f sigma from average.\n",
g_settings.video.refresh_rate, sigma_deviation);
RARCH_LOG("Average monitor Hz: %.6f Hz. (%.3f %% frame time deviation, based on %u last samples).\n",
avg_fps, 100.0 * stddev / avg, samples - 1);
}
void uninit_audio(void)

View File

@ -422,7 +422,7 @@ struct global
unsigned buffer_free_samples[AUDIO_BUFFER_FREE_SAMPLES_COUNT];
uint64_t buffer_free_samples_count;
#define MEASURE_FRAME_TIME_SAMPLES_COUNT 256
#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024)
rarch_time_t frame_time_samples[MEASURE_FRAME_TIME_SAMPLES_COUNT];
uint64_t frame_time_samples_count;
} measure_data;

View File

@ -23,27 +23,32 @@ static float time_to_fps(rarch_time_t last_time, rarch_time_t new_time, int fram
return (1000000.0f * frames) / (new_time - last_time);
}
#define FPS_UPDATE_INTERVAL 256
bool gfx_get_fps(char *buf, size_t size, bool always_write)
{
static rarch_time_t time;
static rarch_time_t fps_time;
static float last_fps;
bool ret = false;
if (g_extern.frame_count == 0)
rarch_time_t new_time = rarch_get_time_usec();
if (g_extern.frame_count)
{
time = rarch_get_time_usec();
unsigned write_index = g_extern.measure_data.frame_time_samples_count++ &
(MEASURE_FRAME_TIME_SAMPLES_COUNT - 1);
g_extern.measure_data.frame_time_samples[write_index] = new_time - fps_time;
fps_time = new_time;
}
else
{
time = fps_time = new_time;
snprintf(buf, size, "%s", g_extern.title_buf);
ret = true;
}
else if ((g_extern.frame_count % 180) == 0)
if ((g_extern.frame_count % FPS_UPDATE_INTERVAL) == 0)
{
rarch_time_t new_time = rarch_get_time_usec();
last_fps = time_to_fps(time, new_time, 180);
unsigned write_index = g_extern.measure_data.frame_time_samples_count++ &
(MEASURE_FRAME_TIME_SAMPLES_COUNT - 1);
g_extern.measure_data.frame_time_samples[write_index] = (new_time - time) / 180;
last_fps = time_to_fps(time, new_time, FPS_UPDATE_INTERVAL);
time = new_time;
#ifdef RARCH_CONSOLE