[cairo-commit] perf/cairo-perf-trace.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Jun 4 02:06:53 PDT 2009


 perf/cairo-perf-trace.c |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

New commits:
commit 5c2e73e74cb9aef92fdd90a91df44b417a036ebd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jun 4 10:03:45 2009 +0100

    [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.

diff --git a/perf/cairo-perf-trace.c b/perf/cairo-perf-trace.c
index e8012cb..7114ae0 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");
 


More information about the cairo-commit mailing list