diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-09-26 03:05:06 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-09-26 03:05:06 -0400 |
commit | afb8dbf0b074b16382e23c1ecabcbf5b650e1dab (patch) | |
tree | 924d2c83f20a7a1d350d13c993776ad8e593442e /dimension/main.c | |
parent | bac926b1e54696beee1d84834876cfadd9939132 (diff) | |
download | dimension-afb8dbf0b074b16382e23c1ecabcbf5b650e1dab.tar.xz |
Add a timer API to libdimension.
Diffstat (limited to 'dimension/main.c')
-rw-r--r-- | dimension/main.c | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/dimension/main.c b/dimension/main.c index bb44df5..5274bdf 100644 --- a/dimension/main.c +++ b/dimension/main.c @@ -233,14 +233,19 @@ main(int argc, char **argv) } /* Realize the input */ + printf("Parsing scene ...\n"); - dmnsn_scene *scene = dmnsn_realize(input_file, symtable); - if (!scene) { - fprintf(stderr, "Error realizing input file!\n"); - dmnsn_delete_symbol_table(symtable); - fclose(input_file); - return EXIT_FAILURE; - } + /* Time the parser */ + dmnsn_timer *parse_timer = dmnsn_new_timer(); + dmnsn_scene *scene = dmnsn_realize(input_file, symtable); + if (!scene) { + fprintf(stderr, "Error realizing input file!\n"); + dmnsn_delete_timer(parse_timer); + dmnsn_delete_symbol_table(symtable); + fclose(input_file); + return EXIT_FAILURE; + } + dmnsn_complete_timer(parse_timer); dmnsn_delete_symbol_table(symtable); fclose(input_file); @@ -285,6 +290,7 @@ main(int argc, char **argv) if (free_output) dmnsn_free(output); if (!output_file) { + dmnsn_delete_timer(parse_timer); fprintf(stderr, "Couldn't open output file!"); return EXIT_FAILURE; } @@ -301,30 +307,49 @@ main(int argc, char **argv) scene->nthreads); if (dmnsn_finish_progress(render_progress) != 0) { + dmnsn_delete_timer(parse_timer); dmnsn_delete_scene(scene); fprintf(stderr, "Error rendering scene!\n"); return EXIT_FAILURE; } - dmnsn_progress *output_progress - = dmnsn_png_write_canvas_async(scene->canvas, output_file); - if (!output_progress) { - fclose(output_file); - dmnsn_delete_scene(scene); - fprintf(stderr, "Couldn't initialize PNG export!\n"); - return EXIT_FAILURE; - } + /* Time the export */ + dmnsn_timer *export_timer = dmnsn_new_timer(); + dmnsn_progress *output_progress + = dmnsn_png_write_canvas_async(scene->canvas, output_file); + if (!output_progress) { + dmnsn_delete_timer(parse_timer); + fclose(output_file); + dmnsn_delete_scene(scene); + fprintf(stderr, "Couldn't initialize PNG export!\n"); + return EXIT_FAILURE; + } - dmnsn_progressbar("Writing PNG", output_progress); + dmnsn_progressbar("Writing PNG", output_progress); - if (dmnsn_finish_progress(output_progress) != 0) { + if (dmnsn_finish_progress(output_progress) != 0) { + dmnsn_delete_timer(export_timer); + dmnsn_delete_timer(parse_timer); + fclose(output_file); + dmnsn_delete_scene(scene); + fprintf(stderr, "Couldn't write output!\n"); + return EXIT_FAILURE; + } fclose(output_file); - dmnsn_delete_scene(scene); - fprintf(stderr, "Couldn't write output!\n"); - return EXIT_FAILURE; - } - fclose(output_file); - + dmnsn_complete_timer(export_timer); + + printf("\n" + " Parse time: " DMNSN_TIMER_FORMAT "\n" + " Bounding time: " DMNSN_TIMER_FORMAT "\n" + " Render time: " DMNSN_TIMER_FORMAT "\n" + " Export time: " DMNSN_TIMER_FORMAT "\n", + DMNSN_TIMER_PRINTF(parse_timer), + DMNSN_TIMER_PRINTF(scene->bounding_timer), + DMNSN_TIMER_PRINTF(scene->render_timer), + DMNSN_TIMER_PRINTF(export_timer)); + + dmnsn_delete_timer(export_timer); + dmnsn_delete_timer(parse_timer); dmnsn_delete_scene(scene); return EXIT_SUCCESS; } |