1 @node Profiling of program phases
2 @section Profiling of program phases
5 The module @samp{timevar} provides a simple self-profiling facility,
9 Execution times (seconds)
10 read : 0.09 (19%) usr 0.08 (80%) sys 0.09 (18%) wall
11 read: scan : 0.04 ( 9%) usr 0.08 (80%) sys 0.12 (26%) wall
12 read: parse : 0.05 (10%) usr 0.00 ( 0%) sys 0.05 (10%) wall
13 work : 0.33 (70%) usr 0.00 ( 0%) sys 0.35 (71%) wall
14 work: phase 1 : 0.30 (64%) usr 0.00 ( 0%) sys 0.30 (64%) wall
15 work: phase 2 : 0.13 (28%) usr 0.00 ( 0%) sys 0.14 (29%) wall
16 output : 0.04 ( 9%) usr 0.02 (20%) sys 0.04 ( 8%) wall
17 total time : 0.47 0.10 0.49
20 To set up @code{timevar}, copy the stub file
21 @file{gnulib/lib/timevar.def} next to where @file{timevar.h} and
22 @file{timevar.c} were imported in your project, and define your timers
26 /* The total execution time. Mandatory. */
27 DEFTIMEVAR (tv_total, "total time")
30 DEFTIMEVAR (tv_read, "read")
31 DEFTIMEVAR (tv_work, "work")
32 DEFTIMEVAR (tv_work_1, "work: phase 1")
33 DEFTIMEVAR (tv_work_2, "work: phase 2")
34 DEFTIMEVAR (tv_output, "output")
37 Do not remove @code{tv_total}, it is mandatory. You may change its
42 Use @code{timevar_push}/@code{timevar_pop} to start/stop timers, as in
43 the following example.
57 timevar_enabled = true;
59 timevar_start (tv_total);
61 timevar_push (tv_read);
63 timevar_pop (tv_read);
65 timevar_push (tv_work);
67 timevar_pop (tv_work);
69 timevar_push (tv_output);
71 timevar_pop (tv_output);
73 timevar_stop (tv_total);
74 timevar_print (stderr);
79 with, for instance, in @file{work.c}
88 timevar_push (tv_work_phase1);
90 timevar_pop (tv_work_phase1);
92 timevar_push (tv_work_phase2);
94 timevar_pop (tv_work_phase2);