summaryrefslogtreecommitdiff
path: root/perf
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-06-11 11:47:24 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-06-11 11:47:24 +0100
commitb9f0ef4496eca31b47296543f48078b2a7034750 (patch)
treeb9c7ff098416aefafb06471d3421a172515ad1b7 /perf
parent9a12c2e02369f0920c1f1f578eb8d228add77ea1 (diff)
downloadcairo-b9f0ef4496eca31b47296543f48078b2a7034750.tar.gz
perf: Rescale the histogram for the terminal
If running ./cairo-perf-print in a terminal, query the terminal size and rescale the histogram to use the maximum available space. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'perf')
-rw-r--r--perf/cairo-perf-print.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/perf/cairo-perf-print.c b/perf/cairo-perf-print.c
index b6cf4ca01..1bf1b41bb 100644
--- a/perf/cairo-perf-print.c
+++ b/perf/cairo-perf-print.c
@@ -27,11 +27,27 @@
* 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
+#error bang
+#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)
@@ -39,8 +55,25 @@ report_print (const cairo_perf_report_t *report,
const test_report_t *test;
cairo_histogram_t h;
- if (show_histogram && !_cairo_histogram_init (&h, 80, 23))
- show_histogram = 0;
+ 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)