summaryrefslogtreecommitdiff
path: root/libs/cairo-1.16.0/perf/cairo-perf-print.c
blob: d7ae1311e1561e9d4aebaf0d1db6973480a5db7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright © 2006 Red Hat, Inc.
 * 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 the
 * copyright holders not be used in advertising or publicity
 * pertaining to distribution of the software without specific,
 * written prior permission. The copyright holders make no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS 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.
 *
 * Authors: Carl Worth <cworth@cworth.org>
 *	    Chris Wilson <chris@chris-wilson.co.uk>
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include "cairo-perf.h"
#include "cairo-stats.h"

#include <stdio.h>

#if HAVE_UNISTD_H && HAVE_SYS_IOCTL_H
#define USE_TERMINAL_SIZE 1
#else
#define USE_TERMINAL_SIZE 0
#endif

#if USE_TERMINAL_SIZE
#include <unistd.h>
#include <sys/ioctl.h>
#endif

static void
report_print (const cairo_perf_report_t *report,
	      int show_histogram)
{
    const test_report_t *test;
    cairo_histogram_t h;

    if (show_histogram) {
	int num_rows = 23;
	int num_cols = 80;

#if USE_TERMINAL_SIZE
	int fd = fileno(stdout);
	if (isatty(fd)) {
	    struct winsize ws;

	    if(ioctl(fd, TIOCGWINSZ, &ws) == 0 ) {
		num_rows = ws.ws_row - 1;
		num_cols = ws.ws_col;
	    }
	}
#endif

	if (!_cairo_histogram_init (&h, num_cols, num_rows))
	    show_histogram = 0;
    }

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

	if (show_histogram) {
	    const cairo_time_t *values;
	    int num_values;

	    if (show_histogram > 1) {
		values = test->stats.values;
		num_values = test->stats.iterations;
	    } else {
		values = test->samples;
		num_values = test->samples_count;
	    }

	    if (_cairo_histogram_compute (&h, values, num_values))
		_cairo_histogram_printf (&h, stdout);
	}

	if (test->size) {
	    printf ("%5s-%-4s %26s-%-3d  ",
		    test->backend, test->content,
		    test->name, test->size);
	} else {
	    printf ("%5s %26s  ", test->backend, test->name);
	}
	printf("%6.2f %4.2f%% (%d/%d)\n",
	       test->stats.median_ticks / test->stats.ticks_per_ms,
	       test->stats.std_dev * 100,
	       test->stats.iterations, test->samples_count);
    }

    if (show_histogram)
	_cairo_histogram_fini (&h);
}

int
main (int	  argc,
      const char *argv[])
{
    cairo_bool_t show_histogram = 0;
    int i;

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

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

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

	cairo_perf_report_load (&report, argv[i], i, NULL);
	report_print (&report, show_histogram);
    }

    return 0;
}