1
/*
2
 * Copyright © 2006 Red Hat, Inc.
3
 * Copyright © 2009 Chris Wilson
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software
6
 * and its documentation for any purpose is hereby granted without
7
 * fee, provided that the above copyright notice appear in all copies
8
 * and that both that copyright notice and this permission notice
9
 * appear in supporting documentation, and that the name of the
10
 * copyright holders not be used in advertising or publicity
11
 * pertaining to distribution of the software without specific,
12
 * written prior permission. The copyright holders make no
13
 * representations about the suitability of this software for any
14
 * purpose.  It is provided "as is" without express or implied
15
 * warranty.
16
 *
17
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24
 * SOFTWARE.
25
 *
26
 * Authors: Carl Worth <cworth@cworth.org>
27
 *	    Chris Wilson <chris@chris-wilson.co.uk>
28
 */
29

            
30
#include "config.h"
31

            
32
#include "cairo-perf.h"
33
#include "cairo-stats.h"
34

            
35
#include <stdio.h>
36

            
37
#if HAVE_UNISTD_H && HAVE_SYS_IOCTL_H
38
#define USE_TERMINAL_SIZE 1
39
#else
40
#define USE_TERMINAL_SIZE 0
41
#endif
42

            
43
#if USE_TERMINAL_SIZE
44
#include <unistd.h>
45
#include <sys/ioctl.h>
46
#if HAVE_TERMIOS_H
47
#include <termios.h>
48
#endif
49
#endif
50

            
51
static void
52
report_print (const cairo_perf_report_t *report,
53
	      int show_histogram)
54
{
55
    const test_report_t *test;
56
    cairo_histogram_t h;
57

            
58
    if (show_histogram) {
59
	int num_rows = 23;
60
	int num_cols = 80;
61

            
62
#if USE_TERMINAL_SIZE
63
	int fd = fileno(stdout);
64
	if (isatty(fd)) {
65
	    struct winsize ws;
66

            
67
	    if(ioctl(fd, TIOCGWINSZ, &ws) == 0 ) {
68
		num_rows = ws.ws_row - 1;
69
		num_cols = ws.ws_col;
70
	    }
71
	}
72
#endif
73

            
74
	if (!_cairo_histogram_init (&h, num_cols, num_rows))
75
	    show_histogram = 0;
76
    }
77

            
78
    for (test = report->tests; test->name != NULL; test++) {
79
	if (test->stats.iterations == 0)
80
	    continue;
81

            
82
	if (show_histogram) {
83
	    const cairo_time_t *values;
84
	    int num_values;
85

            
86
	    if (show_histogram > 1) {
87
		values = test->stats.values;
88
		num_values = test->stats.iterations;
89
	    } else {
90
		values = test->samples;
91
		num_values = test->samples_count;
92
	    }
93

            
94
	    if (_cairo_histogram_compute (&h, values, num_values))
95
		_cairo_histogram_printf (&h, stdout);
96
	}
97

            
98
	if (test->size) {
99
	    printf ("%5s-%-4s %26s-%-3d  ",
100
		    test->backend, test->content,
101
		    test->name, test->size);
102
	} else {
103
	    printf ("%5s %26s  ", test->backend, test->name);
104
	}
105
	printf("%6.2f %4.2f%% (%d/%d)\n",
106
	       test->stats.median_ticks / test->stats.ticks_per_ms,
107
	       test->stats.std_dev * 100,
108
	       test->stats.iterations, test->samples_count);
109
    }
110

            
111
    if (show_histogram)
112
	_cairo_histogram_fini (&h);
113
}
114

            
115
int
116
main (int	  argc,
117
      const char *argv[])
118
{
119
    cairo_bool_t show_histogram = 0;
120
    int i;
121

            
122
    for (i = 1; i < argc; i++ ) {
123
	cairo_perf_report_t report;
124

            
125
	if (strcmp(argv[i], "--histogram") == 0) {
126
	    show_histogram = 1;
127
	    continue;
128
	}
129

            
130
	if (strcmp(argv[i], "--short-histogram") == 0) {
131
	    show_histogram = 2;
132
	    continue;
133
	}
134

            
135
	cairo_perf_report_load (&report, argv[i], i, NULL);
136
	report_print (&report, show_histogram);
137
    }
138

            
139
    return 0;
140
}