From f23ae97e307f00a79cbf2e01f9ca20da29ea87c3 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 24 Sep 2009 16:30:57 +0100 Subject: [perf] Support parsing reports from stdin --- perf/cairo-perf-compare-backends.c | 22 ++++++++++++---------- perf/cairo-perf-report.c | 29 +++++++++++++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/perf/cairo-perf-compare-backends.c b/perf/cairo-perf-compare-backends.c index 1448169b..277536e5 100644 --- a/perf/cairo-perf-compare-backends.c +++ b/perf/cairo-perf-compare-backends.c @@ -363,16 +363,18 @@ main (int argc, const char *argv[]) parse_args (argc, argv, &args); - if (args.num_filenames < 1) - usage (argv[0]); - - reports = xcalloc (args.num_filenames, sizeof (cairo_perf_report_t)); - - for (i = 0; i < args.num_filenames; i++) { - cairo_perf_report_load (&reports[i], args.filenames[i], - test_report_cmp_name); - printf ("loaded: %s, %d tests\n", - args.filenames[i], reports[i].tests_count); + if (args.num_filenames) { + reports = xcalloc (args.num_filenames, sizeof (cairo_perf_report_t)); + for (i = 0; i < args.num_filenames; i++) { + cairo_perf_report_load (&reports[i], args.filenames[i], + test_report_cmp_name); + printf ("loaded: %s, %d tests\n", + args.filenames[i], reports[i].tests_count); + } + } else { + args.num_filenames = 1; + reports = xcalloc (args.num_filenames, sizeof (cairo_perf_report_t)); + cairo_perf_report_load (&reports[0], NULL, test_report_cmp_name); } cairo_perf_reports_compare (reports, args.num_filenames, &args.options); diff --git a/perf/cairo-perf-report.c b/perf/cairo-perf-report.c index 1690e62a..2029a884 100644 --- a/perf/cairo-perf-report.c +++ b/perf/cairo-perf-report.c @@ -437,9 +437,14 @@ cairo_perf_report_load (cairo_perf_report_t *report, char *configuration; char *dot; char *baseName; + const char *name; - configuration = xmalloc (strlen (filename) * sizeof (char) + 1); - strcpy (configuration, filename); + name = filename; + if (name == NULL) + name = "stdin"; + + configuration = xmalloc (strlen (name) * sizeof (char) + 1); + strcpy (configuration, name); baseName = basename (configuration); report->configuration = xmalloc (strlen (baseName) * sizeof (char) + 1); strcpy (report->configuration, baseName); @@ -449,16 +454,20 @@ cairo_perf_report_load (cairo_perf_report_t *report, if (dot) *dot = '\0'; - report->name = filename; + report->name = name; report->tests_size = 16; report->tests = xmalloc (report->tests_size * sizeof (test_report_t)); report->tests_count = 0; - file = fopen (filename, "r"); - if (file == NULL) { - fprintf (stderr, "Failed to open %s: %s\n", - filename, strerror (errno)); - exit (1); + if (filename == NULL) { + file = stdin; + } else { + file = fopen (filename, "r"); + if (file == NULL) { + fprintf (stderr, "Failed to open %s: %s\n", + filename, strerror (errno)); + exit (1); + } } while (1) { @@ -485,7 +494,8 @@ cairo_perf_report_load (cairo_perf_report_t *report, if (line) free (line); - fclose (file); + if (filename != NULL) + fclose (file); cairo_perf_report_sort_and_compute_stats (report, cmp); @@ -497,4 +507,3 @@ cairo_perf_report_load (cairo_perf_report_t *report, } report->tests[report->tests_count].name = NULL; } - -- cgit v1.2.3