diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-06-04 10:03:45 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-06-04 10:03:45 +0100 |
commit | 5c2e73e74cb9aef92fdd90a91df44b417a036ebd (patch) | |
tree | 3534e6be45be62ccf71a5737c41840693cadf811 /perf | |
parent | 2eaced24475622e73fbf6e3307ab46e3fe37eaef (diff) |
[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.
Diffstat (limited to 'perf')
-rw-r--r-- | perf/cairo-perf-trace.c | 20 |
1 files changed, 19 insertions, 1 deletions
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 <sys/types.h> #include <dirent.h> +#include <signal.h> + #if HAVE_FCFINI #include <fontconfig/fontconfig.h> #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"); |