From 5c2e73e74cb9aef92fdd90a91df44b417a036ebd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 4 Jun 2009 10:03:45 +0100 Subject: [PATCH] [perf] Enable traces to be interrupted Waiting for a long running benchmark can be very annoying, especially if you just want a rough-and-ready result. So hook into SIGINT and stop the current benchmark (after the end of the iteration) on the first ^C. A second ^C within the same iteration will kill the program as before. --- perf/cairo-perf-trace.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/perf/cairo-perf-trace.c b/perf/cairo-perf-trace.c index e8012cba5..7114ae0f7 100644 --- a/perf/cairo-perf-trace.c +++ b/perf/cairo-perf-trace.c @@ -44,6 +44,8 @@ #include #include +#include + #if HAVE_FCFINI #include #endif @@ -147,6 +149,19 @@ _similar_surface_create (void *closure, return cairo_surface_create_similar (closure, content, width, height); } +static int user_interrupt; + +static void +interrupt (int sig) +{ + if (user_interrupt) { + signal (sig, SIG_DFL); + raise (sig); + } + + user_interrupt = 1; +} + static void execute (cairo_perf_t *perf, cairo_surface_t *target, @@ -202,7 +217,7 @@ execute (cairo_perf_t *perf, } low_std_dev_count = 0; - for (i = 0; i < perf->iterations; i++) { + for (i = 0; i < perf->iterations && ! user_interrupt; i++) { cairo_script_interpreter_t *csi; csi = cairo_script_interpreter_create (); @@ -242,6 +257,7 @@ execute (cairo_perf_t *perf, } } } + user_interrupt = 0; if (perf->summary) { _cairo_stats_compute (&stats, times, i); @@ -473,6 +489,8 @@ main (int argc, char *argv[]) stderr); } + signal (SIGINT, interrupt); + if (getenv ("CAIRO_TRACE_DIR") != NULL) trace_dir = getenv ("CAIRO_TRACE_DIR");