[cairo-commit] 5 commits - boilerplate/cairo-boilerplate.c perf/Makefile.am perf/README test/Makefile.am test/Makefile.sources test/mask-glyphs.c test/mask-glyphs.ref.png

Chris Wilson ickle at kemper.freedesktop.org
Wed Jun 10 00:53:42 PDT 2009


 boilerplate/cairo-boilerplate.c |   15 +++
 perf/Makefile.am                |   16 +++
 perf/README                     |   37 +++++++-
 test/Makefile.am                |    1 
 test/Makefile.sources           |    1 
 test/mask-glyphs.c              |  175 ++++++++++++++++++++++++++++++++++++++++
 test/mask-glyphs.ref.png        |binary
 7 files changed, 239 insertions(+), 6 deletions(-)

New commits:
commit 81b5dc42b0e754d602506a8ccd231df9afd71593
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 10 08:49:39 2009 +0100

    [perf] Expand the section on cairo-perf-trace in the README
    
    Promote the information on how to use cairo-perf-trace and include it
    immediately after the details on cairo-perf. This should make it much
    clearer on how to replay the traces, and the difference between the two
    benchmarks.

diff --git a/perf/README b/perf/README
index abf0687..fd6eb30 100644
--- a/perf/README
+++ b/perf/README
@@ -9,8 +9,20 @@ more details on other options for running the suite below.
 
 Running the cairo performance suite
 -----------------------------------
-The lowest-level means of running the test suite is with the
-cairo-perf program, (which is what "make perf" executes). Some
+The performance suite is composed of two types of tests, micro- and
+macro-benchmarks. The micro-benchmarks are a series of hand-written,
+short, synthetic tests that measure the speed of doing a simple
+operation such as painting a surface or showing glyphs. These aim to
+give very good feedback on whether a performance related patch is
+successful without causing any performance degradations elsewhere. The
+second type of benchmark consists of replaying a cairo-trace from a
+large application during typical usage. These aim to give an overall
+feel as to whether cairo is faster for everyday use.
+
+Running the micro-benchmarks
+----------------------------
+The micro-benchmarks are compiled into a single executable called
+cairo-perf, which is what "make perf" executes. Some
 examples of running it:
 
     # Report on all tests with default number of iterations:
@@ -29,6 +41,25 @@ when using cairo-perf-diff to compare separate runs (see more
 below). The advantage of using the raw mode is that test runs can be
 generated incrementally and appended to existing reports.
 
+Running the macro-benchmarks
+----------------------------
+The macro-benchmarks are run by a single program called
+cairo-perf-trace, which is also executed by "make perf".
+cairo-perf-trace loops over the series of traces stored beneath
+cairo-traces/. cairo-perf-trace produces the same output and takes the
+same arguments as cairo-perf.  Some examples of running it:
+
+    # Report on all tests with default number of iterations:
+    ./cairo-perf-trace
+
+    # Report on 100 iterations of all firefox tests:
+    ./cairo-perf-trace -i 100 firefox
+
+    # Generate raw results for 10 iterations into cairo.perf
+    ./cairo-perf-trace -r -i 10 > cairo.perf
+    # Append 10 more iterations of the poppler tests
+    ./cairo-perf-trace -r -i 10 poppler >> cairo.perf
+
 Generating comparisons of separate runs
 ---------------------------------------
 It's often useful to generate a chart showing the comparison of two
@@ -180,7 +211,7 @@ added:
     64x64.
 
 
-How to benchmark traces
+How to record new traces
 -----------------------
 Using cairo-trace you can record the exact sequence of graphic operations
 made by an application and replay them later. These traces can then be
commit ec92e633edd377747155b60aa225b266c38bc498
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 10 08:34:57 2009 +0100

    [perf] Couple cairo-perf-traces into make perf
    
    Rather than complicating cairo-perf to extend it to perform both micro-
    and macro-benchmarks, simply run the two binaries in succession during
    make perf.
    
    For bonus points, consider whether we should hook cairo-perf-trace into
    cairo-perf-diff.

diff --git a/perf/Makefile.am b/perf/Makefile.am
index e06cde4..362fdac 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -132,8 +132,9 @@ TESTS_ENVIRONMENT = CAIRO_TEST_TARGET="$(TARGETS)" CAIRO_PERF_ITERATIONS="10"
 
 TESTS += cairo-perf$(EXEEXT)
 
-perf: cairo-perf$(EXEEXT)
-	$(CAIRO_PERF_ENVIRONMENT) ./cairo-perf$(EXEEXT)
+perf: cairo-perf$(EXEEXT) cairo-perf-trace$(EXEEXT)
+	-$(CAIRO_PERF_ENVIRONMENT) ./cairo-perf$(EXEEXT)
+	-$(CAIRO_PERF_ENVIRONMENT) ./cairo-perf-trace$(EXEEXT)
 
 html-local: index.html
 
commit 0db946cdd9fe601a060b62c5df7df3022ea5e2d6
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Jun 9 16:19:36 2009 +0100

    [perf] Add explicit dependences for the local libraries
    
    Update the build rules and add the dependences for the libraries built in
    other parts of cairo.

diff --git a/perf/Makefile.am b/perf/Makefile.am
index bb2ce2e..e06cde4 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -66,6 +66,9 @@ cairo_perf_SOURCES += cairo-perf-posix.c
 endif
 endif
 cairo_perf_LDADD = $(LDADD)
+cairo_perf_DEPENDENCIES = \
+        $(top_builddir)/boilerplate/libcairoboilerplate.la	\
+	$(top_builddir)/src/libcairo.la
 
 libcairoperf_la_SOURCES = \
 	cairo-perf-report.c	\
@@ -86,6 +89,10 @@ endif
 cairo_perf_trace_LDADD =		\
 	$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
 	$(LDADD)
+cairo_perf_trace_DEPENDENCIES = \
+	$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
+        $(top_builddir)/boilerplate/libcairoboilerplate.la	\
+	$(top_builddir)/src/libcairo.la
 
 cairo_perf_diff_files_SOURCES =	\
 	cairo-perf-diff-files.c
@@ -100,12 +107,16 @@ cairo_perf_graph_files_SOURCES = \
 cairo_perf_graph_files_CFLAGS = @gtk_CFLAGS@
 cairo_perf_graph_files_LDADD = @gtk_LIBS@ $(LDADD)
 
+# Install rules to rebuild the libraries and add explicit dependencies
 $(top_builddir)/boilerplate/libcairoboilerplate.la: $(top_builddir)/src/libcairo.la
 	cd $(top_builddir)/boilerplate && $(MAKE) $(AM_MAKEFLAGS) libcairoboilerplate.la
 
 $(top_builddir)/src/libcairo.la:
 	cd $(top_builddir)/src && $(MAKE) $(AM_MAKEFLAGS) libcairo.la
 
+$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la: $(top_builddir)/src/libcairo.la
+	cd $(top_builddir)/util/cairo-script && $(MAKE) $(AM_MAKEFLAGS) libcairo-script-interpreter.la
+
 
 # Do a funny transition of CAIRO_TEST_TARGET through TARGETS such that
 # one can limit tested targets both through CAIRO_TEST_TARGET env var
commit 844c809698635cf44658fcbfb5da6976890185b9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Jun 9 12:45:53 2009 +0100

    [boilerplate] Print out known targets on error.
    
    Improve the 'Cannot find target ...' error message for an incorrect
    CAIRO_TEST_TARGET by actually listing the targets that have been compiled
    into the test suite.

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index fb8897e..31df704 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -781,7 +781,20 @@ cairo_boilerplate_get_targets (int *pnum_targets, cairo_bool_t *plimited_targets
 	    }
 
 	    if (!found) {
-		fprintf (stderr, "Cannot find target '%.*s'\n", (int)(end - tname), tname);
+		fprintf (stderr, "Cannot find target '%.*s'.\n",
+			 (int)(end - tname), tname);
+		fprintf (stderr, "Known targets:");
+		for (i = 0; i < sizeof (targets) / sizeof (targets[0]); i++) {
+		    if (i != 0) {
+			if (strcmp (targets[i].name, targets[i-1].name) == 0) {
+			    /* filter out repeats that differ in content */
+			    continue;
+			}
+			fprintf (stderr, ",");
+		    }
+		    fprintf (stderr, " %s", targets[i].name);
+		}
+		fprintf (stderr, "\n");
 		exit(-1);
 	    }
 
commit ac563715506b911f142dd0e4460a6effee45119d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jun 8 23:58:56 2009 +0100

    [test] Exercise overlapping glyphs
    
    Quite an expensive test that converts an image into a distorted array of
    glyphs, using a perspective transformation taking the intensity of the
    pixel as depth. This generates a pretty picture and many overlapping
    glyphs.

diff --git a/test/Makefile.am b/test/Makefile.am
index ef2d875..3606658 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -461,6 +461,7 @@ REFERENCE_IMAGES = \
 	mask.pdf.rgb24.ref.png	\
 	mask.quartz.ref.png	\
 	mask.quartz.rgb24.ref.png	\
+	mask-glyphs.ref.png	\
 	mask-surface-ctm.ref.png	\
 	mask-surface-ctm.rgb24.ref.png	\
 	mask-surface-ctm.svg11.argb32.ref.png	\
diff --git a/test/Makefile.sources b/test/Makefile.sources
index eeb9294..23596f8 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -105,6 +105,7 @@ test_sources = \
 	mask.c						\
 	mask-alpha.c					\
 	mask-ctm.c					\
+	mask-glyphs.c					\
 	mask-surface-ctm.c				\
 	mask-transformed-image.c			\
 	mask-transformed-similar.c			\
diff --git a/test/mask-glyphs.c b/test/mask-glyphs.c
new file mode 100644
index 0000000..045dcaf
--- /dev/null
+++ b/test/mask-glyphs.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2009 Chris Wilson
+ *
+ * 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
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#include <assert.h>
+
+static const char *png_filename = "romedalen.png";
+
+#define WIDTH 800
+#define HEIGHT 600
+
+static int
+_image_to_glyphs (cairo_surface_t *image,
+		  int channel,
+		  int level,
+		  cairo_scaled_font_t *scaled_font,
+		  cairo_glyph_t *glyphs,
+		  double tx, double ty)
+{
+    int width, height, stride;
+    const unsigned char *data;
+    cairo_format_t format;
+    int x, y, z, n;
+
+    width = cairo_image_surface_get_width (image);
+    height = cairo_image_surface_get_height (image);
+    stride = cairo_image_surface_get_stride (image);
+    format = cairo_image_surface_get_format (image);
+    data = cairo_image_surface_get_data (image);
+
+    n = 0;
+    for (y = 0; y < height; y++) {
+	const uint32_t *row = (uint32_t *) (data + y * stride);
+
+	for (x = 0; x < width; x++) {
+	    z = (row[x] >> channel) & 0xff;
+	    if (z == level) {
+		double xx, yy, zz;
+		char c = n % 26 + 'a';
+		int count = 1;
+		cairo_glyph_t *glyphs_p = &glyphs[n];
+
+		xx = 4 * (x - width/2.) + width/2.;
+		yy = 4 * (y - height/2.) + height/2.;
+
+		zz = z / 1000.;
+		xx = xx + zz*(width/2. - xx);
+		yy = yy + zz*(height/2. - yy);
+
+		cairo_scaled_font_text_to_glyphs (scaled_font,
+						  tx + xx, ty + yy,
+						  &c, 1,
+						  &glyphs_p, &count,
+						  NULL, NULL,
+						  NULL);
+		assert (glyphs_p == &glyphs[n]);
+		assert (count == 1);
+		n++;
+	    }
+	}
+    }
+
+    return n;
+}
+
+static cairo_status_t
+_render_image (cairo_t *cr,
+	       int width, int height,
+	       cairo_surface_t *image)
+{
+    int ww, hh;
+    cairo_glyph_t *glyphs;
+    cairo_pattern_t *mask;
+    cairo_scaled_font_t *scaled_font;
+    double tx, ty;
+    const struct {
+	int shift;
+	double red;
+	double green;
+	double blue;
+    } channel[3] = {
+	{  0, 0.9, 0.3, 0.4 },
+	{  8, 0.4, 0.9, 0.3 },
+	{ 16, 0.3, 0.4, 0.9 },
+    };
+    unsigned int n, i;
+
+    ww = cairo_image_surface_get_width (image);
+    hh = cairo_image_surface_get_height (image);
+
+    glyphs = cairo_glyph_allocate (ww * hh);
+    if (glyphs == NULL) {
+	cairo_surface_destroy (image);
+	return CAIRO_STATUS_NO_MEMORY;
+    }
+
+    tx = (width - ww) / 2.;
+    ty = (height - hh) / 2.;
+
+    cairo_set_font_size (cr, 5);
+    scaled_font = cairo_get_scaled_font (cr);
+
+    for (i = 0; i < sizeof (channel) / sizeof (channel[0]); i++) {
+	cairo_push_group_with_content (cr, CAIRO_CONTENT_ALPHA);
+	for (n = 0; n < 256; n++) {
+	    int num_glyphs;
+
+	    num_glyphs = _image_to_glyphs (image, channel[i].shift, n,
+					   scaled_font,
+					   glyphs, tx, ty);
+
+	    cairo_set_source_rgba (cr,
+				   0, 0, 0,
+				   .15 + .85 * n / 255.);
+	    cairo_show_glyphs (cr, glyphs, num_glyphs);
+	}
+	mask = cairo_pop_group (cr);
+	cairo_set_source_rgb (cr,
+			      channel[i].red,
+			      channel[i].green,
+			      channel[i].blue);
+	cairo_mask (cr, mask);
+	cairo_pattern_destroy (mask);
+    }
+
+    cairo_glyph_free (glyphs);
+    return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
+    cairo_surface_t *image;
+    cairo_status_t status;
+
+    cairo_set_source_rgb (cr, 0, 0, 0);
+    cairo_paint (cr);
+
+    image = cairo_test_create_surface_from_png (ctx, png_filename);
+    status = _render_image (cr, width, height, image);
+    cairo_surface_destroy (image);
+
+    return cairo_test_status_from_status (ctx, status);
+}
+
+CAIRO_TEST (mask_glyphs,
+	    "Creates a mask using a distorted array of overlapping glyphs",
+	    "XFAIL=svg,pdf mask, glyphs", /* keywords */
+	    NULL, /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, draw)
diff --git a/test/mask-glyphs.ref.png b/test/mask-glyphs.ref.png
new file mode 100644
index 0000000..8abcc47
Binary files /dev/null and b/test/mask-glyphs.ref.png differ


More information about the cairo-commit mailing list