From d1b294eecc1bcc04524ac9dafde81e40334da530 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Fri, 8 Nov 2013 11:57:37 -0800 Subject: Tabulate data to stdout; write the json to a file only if directed --- src/caskbench.cpp | 73 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'src/caskbench.cpp') diff --git a/src/caskbench.cpp b/src/caskbench.cpp index fcb8a6c..02a86cd 100644 --- a/src/caskbench.cpp +++ b/src/caskbench.cpp @@ -17,6 +17,7 @@ typedef struct _caskbench_options { int dry_run; int iterations; + char* output_file; } caskbench_options_t; typedef struct _caskbench_perf_test { @@ -36,16 +37,19 @@ typedef struct _caskbench_result { caskbench_perf_test_t perf_tests[] = { {"cairo-fill", ca_setup_fill, ca_teardown_fill, ca_test_fill}, + {"skia-fill", sk_setup_fill, sk_teardown_fill, sk_test_fill}, + {"cairo-image", ca_setup_image, ca_teardown_image, ca_test_image}, + {"skia-image", sk_setup_image, sk_teardown_image, sk_test_image}, + {"cairo-mask", ca_setup_mask, ca_teardown_mask, ca_test_mask}, + {"skia-mask", sk_setup_mask, sk_teardown_mask, sk_test_mask}, + {"cairo-paint", ca_setup_paint, ca_teardown_paint, ca_test_paint}, - {"cairo-stroke", ca_setup_stroke, ca_teardown_stroke, ca_test_stroke}, + {"skia-paint", sk_setup_paint, sk_teardown_paint, sk_test_paint}, - {"skia-fill", sk_setup_fill, sk_teardown_fill, sk_test_fill}, - {"skia-image", sk_setup_image, sk_teardown_image, sk_test_image}, - {"skia-mask", sk_setup_mask, sk_teardown_mask, sk_test_mask}, - {"skia-paint", sk_setup_paint, sk_teardown_paint, sk_test_paint}, - {"skia-stroke", sk_setup_stroke, sk_teardown_stroke, sk_test_stroke}, + {"cairo-stroke", ca_setup_stroke, ca_teardown_stroke, ca_test_stroke}, + {"skia-stroke", sk_setup_stroke, sk_teardown_stroke, sk_test_stroke}, }; #define NUM_ELEM(x) (sizeof(x)/sizeof(x[0])) @@ -85,6 +89,9 @@ process_options(caskbench_options_t *opt, int argc, char *argv[]) {"dry-run", 'n', POPT_ARG_NONE, &opt->dry_run, 0, "Just list the selected test case names without executing", NULL}, + {"output-file", 'o', POPT_ARG_STRING, &opt->output_file, 0, + "Filename to write JSON output to", + NULL}, POPT_AUTOHELP {NULL} }; @@ -94,6 +101,7 @@ process_options(caskbench_options_t *opt, int argc, char *argv[]) // Initialize options opt->dry_run = 0; opt->iterations = 64; + opt->output_file = NULL; pc = poptGetContext(NULL, argc, (const char **)argv, po, 0); poptSetOtherOptionHelp(pc, "[ARG...]"); @@ -142,30 +150,21 @@ randomize_color(cairo_t *cr) cairo_set_source_rgba (cr, red, green, blue, alpha); } -void -display_results_json(const caskbench_result_t *result) -{ - printf(" {\n"); - printf(" \"test case\": \"%s\",\n", result->test_case_name); - printf(" \"iterations\": %d,\n", result->iterations); - printf(" \"minimum run time (s)\": %f,\n", result->min_run_time); - printf(" \"average run time (s)\": %f,\n", result->avg_run_time); - printf(" \"status\": \"%s\"\n", _status_to_string(result->status)); - printf(" }"); -} - int main (int argc, char *argv[]) { int c, i; caskbench_options_t opt; double start_time, stop_time, run_time, run_total; + FILE *fp; process_options(&opt, argc, argv); - // TODO: Open output file - // start json - printf("[\n"); + if (opt.output_file) { + // start writing json to output file + fp = fopen(opt.output_file, "w"); + fprintf(fp, "[\n"); + } for (c=0; c