Change profiling code to use median instead of average
This commit is contained in:
101
src/tint.c
101
src/tint.c
@@ -60,6 +60,82 @@ Atom dnd_atom;
|
|||||||
int dnd_sent_request;
|
int dnd_sent_request;
|
||||||
char *dnd_launcher_exec;
|
char *dnd_launcher_exec;
|
||||||
gboolean debug_fps = FALSE;
|
gboolean debug_fps = FALSE;
|
||||||
|
float *fps_distribution = NULL;
|
||||||
|
|
||||||
|
void create_fps_distribution()
|
||||||
|
{
|
||||||
|
// measure FPS with resolution:
|
||||||
|
// 0-59: 1 (60 samples)
|
||||||
|
// 60-199: 10 (14)
|
||||||
|
// 200-1,999: 25 (72)
|
||||||
|
// 1k-19,999: 1000 (19)
|
||||||
|
// 20x+: inf (1)
|
||||||
|
// => 166 samples
|
||||||
|
if (fps_distribution)
|
||||||
|
return;
|
||||||
|
fps_distribution = calloc(170, sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanup_fps_distribution()
|
||||||
|
{
|
||||||
|
free(fps_distribution);
|
||||||
|
fps_distribution = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sample_fps(double fps)
|
||||||
|
{
|
||||||
|
int fps_rounded = (int)(fps + 0.5);
|
||||||
|
int i = 1;
|
||||||
|
if (fps_rounded < 60) {
|
||||||
|
i += fps_rounded;
|
||||||
|
} else {
|
||||||
|
i += 60;
|
||||||
|
if (fps_rounded < 200) {
|
||||||
|
i += (fps_rounded - 60) / 10;
|
||||||
|
} else {
|
||||||
|
i += 14;
|
||||||
|
if (fps_rounded < 2000) {
|
||||||
|
i += (fps_rounded - 200) / 25;
|
||||||
|
} else {
|
||||||
|
i += 72;
|
||||||
|
if (fps_rounded < 20000) {
|
||||||
|
i += (fps_rounded - 2000) / 1000;
|
||||||
|
} else {
|
||||||
|
i += 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fprintf(stderr, "fps = %.0f => i = %d\n", fps, i);
|
||||||
|
fps_distribution[i] += 1.;
|
||||||
|
fps_distribution[0] += 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fps_compute_stats(double *low, double *median, double *high, double *samples)
|
||||||
|
{
|
||||||
|
*median = *low = *high = *samples = -1;
|
||||||
|
if (!fps_distribution || fps_distribution[0] < 1)
|
||||||
|
return;
|
||||||
|
float total = fps_distribution[0];
|
||||||
|
*samples = (double) fps_distribution[0];
|
||||||
|
float cum_low = 0.05f * total;
|
||||||
|
float cum_median = 0.5f * total;
|
||||||
|
float cum_high = 0.95f * total;
|
||||||
|
float cum = 0;
|
||||||
|
for (int i = 1; i <= 166; i++) {
|
||||||
|
double value =
|
||||||
|
(i < 60) ? i : (i < 74) ? (60 + (i - 60) * 10) : (i < 146) ? (200 + (i - 74) * 25)
|
||||||
|
: (i < 165) ? (2000 + (i - 146) * 1000) : 20000;
|
||||||
|
// fprintf(stderr, "%6.0f (i = %3d) : %.0f | ", value, i, (double)fps_distribution[i]);
|
||||||
|
cum += fps_distribution[i];
|
||||||
|
if (*low < 0 && cum >= cum_low)
|
||||||
|
*low = value;
|
||||||
|
if (*median < 0 && cum >= cum_median)
|
||||||
|
*median = value;
|
||||||
|
if (*high < 0 && cum >= cum_high)
|
||||||
|
*high = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void signal_handler(int sig)
|
void signal_handler(int sig)
|
||||||
{
|
{
|
||||||
@@ -127,6 +203,8 @@ void init (int argc, char *argv[])
|
|||||||
// sigaddset(&block_mask, SIGUSR1);
|
// sigaddset(&block_mask, SIGUSR1);
|
||||||
// sigprocmask(SIG_BLOCK, &block_mask, 0);
|
// sigprocmask(SIG_BLOCK, &block_mask, 0);
|
||||||
debug_fps = getenv("DEBUG_FPS") != NULL;
|
debug_fps = getenv("DEBUG_FPS") != NULL;
|
||||||
|
if (debug_fps)
|
||||||
|
create_fps_distribution();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SN
|
#ifdef HAVE_SN
|
||||||
@@ -258,6 +336,7 @@ void cleanup()
|
|||||||
cleanup_server();
|
cleanup_server();
|
||||||
cleanup_timeout();
|
cleanup_timeout();
|
||||||
if (server.dsp) XCloseDisplay(server.dsp);
|
if (server.dsp) XCloseDisplay(server.dsp);
|
||||||
|
cleanup_fps_distribution();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1082,7 +1161,6 @@ start:
|
|||||||
double ts_event_processed = 0;
|
double ts_event_processed = 0;
|
||||||
double ts_render_finished = 0;
|
double ts_render_finished = 0;
|
||||||
double ts_flush_finished = 0;
|
double ts_flush_finished = 0;
|
||||||
double fps_sum = 0, fps_count = 0;
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (panel_refresh) {
|
if (panel_refresh) {
|
||||||
if (debug_fps)
|
if (debug_fps)
|
||||||
@@ -1120,18 +1198,23 @@ start:
|
|||||||
ts_flush_finished = get_time();
|
ts_flush_finished = get_time();
|
||||||
double period = ts_flush_finished - ts_event_read;
|
double period = ts_flush_finished - ts_event_read;
|
||||||
double fps = 1.0 / period;
|
double fps = 1.0 / period;
|
||||||
|
sample_fps(fps);
|
||||||
double proc_ratio = (ts_event_processed - ts_event_read) / period;
|
double proc_ratio = (ts_event_processed - ts_event_read) / period;
|
||||||
double render_ratio = (ts_render_finished - ts_event_processed) / period;
|
double render_ratio = (ts_render_finished - ts_event_processed) / period;
|
||||||
double flush_ratio = (ts_flush_finished - ts_render_finished) / period;
|
double flush_ratio = (ts_flush_finished - ts_render_finished) / period;
|
||||||
fps_sum += fps;
|
double fps_low, fps_median, fps_high, fps_samples;
|
||||||
fps_count += 1;
|
fps_compute_stats(&fps_low, &fps_median, &fps_high, &fps_samples);
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
BLUE "fps = %.0f (avg %.0f) : processing %.0f%%, rendering %.0f%%, flushing %.0f%%" RESET "\n",
|
BLUE "fps = %.0f (low %.0f, med %.0f, high %.0f, samples %.0f) : processing %.0f%%, rendering %.0f%%, "
|
||||||
fps,
|
"flushing %.0f%%" RESET "\n",
|
||||||
fps_sum / fps_count,
|
fps,
|
||||||
proc_ratio * 100,
|
fps_low,
|
||||||
render_ratio * 100,
|
fps_median,
|
||||||
flush_ratio * 100);
|
fps_high,
|
||||||
|
fps_samples,
|
||||||
|
proc_ratio * 100,
|
||||||
|
render_ratio * 100,
|
||||||
|
flush_ratio * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user