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