Add timer macros
authorSøren Sandmann <sandmann@redhat.com>
Sun, 17 Jun 2007 22:55:37 +0000 (18:55 -0400)
committerSøren Sandmann <sandmann@redhat.com>
Sun, 17 Jun 2007 22:55:37 +0000 (18:55 -0400)
pixman/Makefile.am
pixman/pixman-pict.c
pixman/pixman-private.h
pixman/pixman-timer.c [new file with mode: 0644]
test/gradient-test.c

index a444fe7..90c6436 100644 (file)
@@ -11,7 +11,8 @@ libpixman_la_SOURCES =                \
        pixman-edge.c           \
        pixman-edge-imp.h       \
        pixman-trap.c           \
-       pixman-compute-region.c
+       pixman-compute-region.c \
+       pixman-timer.c
 
 libpixmanincludedir = $(includedir)/pixman
 libpixmaninclude_HEADERS = pixman.h
index afe44cc..3777515 100644 (file)
@@ -1089,6 +1089,8 @@ pixman_image_composite_rect  (pixman_op_t                   op,
     return_if_fail (src != NULL);
     return_if_fail (dest != NULL);
     
+    TIMER_BEGIN (pixman_image_composite);
+    
     if (width > SCANLINE_BUFFER_LENGTH)
     {
        scanline_buffer = (uint32_t *)malloc (width * 3 * sizeof (uint32_t));
@@ -1114,7 +1116,10 @@ pixman_image_composite_rect  (pixman_op_t                   op,
 
     if (scanline_buffer != _scanline_buffer)
        free (scanline_buffer);
-}
+
+    TIMER_END (pixman_image_composite);
+}    
+
 
 void
 pixman_image_composite (pixman_op_t      op,
@@ -1138,7 +1143,7 @@ pixman_image_composite (pixman_op_t      op,
     pixman_bool_t      maskAlphaMap = FALSE;
     pixman_bool_t      dstAlphaMap = pDst->common.alpha_map != NULL;
     CompositeFunc   func = NULL;
-    
+
 #ifdef USE_MMX
     static pixman_bool_t mmx_setup = FALSE;
     if (!mmx_setup)
index e29ef6d..af41d70 100644 (file)
@@ -6,6 +6,7 @@
 #define PIXMAN_PRIVATE_H
 
 #include "pixman.h"
+#include <time.h>
 
 #ifndef FALSE
 #define FALSE 0
@@ -768,4 +769,49 @@ pixman_rasterize_edges_accessors (pixman_image_t *image,
                                  pixman_fixed_t        t,
                                  pixman_fixed_t        b);
 
+
+/* Timing */
+static inline uint64_t
+oil_profile_stamp_rdtsc (void)
+{
+    uint64_t ts;
+    __asm__ __volatile__("rdtsc\n" : "=A" (ts));
+    return ts;
+}
+#define OIL_STAMP oil_profile_stamp_rdtsc
+
+typedef struct PixmanTimer PixmanTimer;
+
+struct PixmanTimer
+{
+    int initialized;
+    const char *name;
+    uint64_t n_times;
+    uint64_t total;
+    PixmanTimer *next;
+};
+
+extern int timer_defined;
+void pixman_timer_register (PixmanTimer *timer);
+
+#define TIMER_BEGIN(tname)                                             \
+    {                                                                  \
+       static PixmanTimer      timer##tname;                           \
+       uint64_t                begin##tname;                           \
+                                                                       \
+       if (!timer##tname.initialized)                                  \
+       {                                                               \
+           timer##tname.initialized = 1;                               \
+           timer##tname.name = #tname;                                 \
+           pixman_timer_register (&timer##tname);                      \
+       }                                                               \
+                                                                       \
+       timer##tname.n_times++;                                         \
+       begin##tname = OIL_STAMP();
+       
+#define TIMER_END(tname)                                               \
+        timer##tname.total += OIL_STAMP() - begin##tname;              \
+    }
+
+
 #endif /* PIXMAN_PRIVATE_H */
diff --git a/pixman/pixman-timer.c b/pixman/pixman-timer.c
new file mode 100644 (file)
index 0000000..c762644
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Red Hat not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  Red Hat makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "pixman-private.h"
+
+static PixmanTimer *timers;
+
+static void
+dump_timers (void)
+{
+    PixmanTimer *timer;
+
+    for (timer = timers; timer != NULL; timer = timer->next)
+    {
+       printf ("%s:   total: %llu     n: %llu      avg: %f\n",
+               timer->name,
+               timer->total,
+               timer->n_times,
+               timer->total / (double)timer->n_times);
+    }
+}
+
+void
+pixman_timer_register (PixmanTimer *timer)
+{
+    static int initialized;
+
+    int atexit(void (*function)(void));
+
+    if (!initialized)
+    {
+       atexit (dump_timers);
+       initialized = 1;
+    }
+    
+    timer->next = timers;
+    timers = timer;
+}
index f6e3ca3..8a99ff0 100644 (file)
@@ -59,6 +59,7 @@ show_window (uint32_t *bits, int w, int h, int stride)
     pixbuf = pixbuf_from_argb32 (bits, w, h, stride);
     
     g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
+    g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
     
     gtk_widget_show (window);