exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / timevar.h
blobd7d05e7186525f2bce17c1890a1befc001c0e222
1 /* Timing variables for measuring application performance.
3 Copyright (C) 2000, 2002, 2004, 2009-2015, 2018-2024 Free Software
4 Foundation, Inc.
6 Contributed by Alex Samuel <samuel@codesourcery.com>
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #ifndef _TIMEVAR_H
22 # define _TIMEVAR_H 1
24 # include <stdio.h>
26 # include "xtime.h"
28 # ifdef __cplusplus
29 extern "C" {
30 # endif
32 /* Timing variables are used to measure elapsed time in various
33 portions of the application. Each measures elapsed user, system, and
34 wall-clock time, as appropriate to and supported by the host
35 system.
37 Timing variables are defined using the DEFTIMEVAR macro in
38 timevar.def. Each has an identifier of type timevar_id_t, used to refer
39 to the timing variable in code, and a character string name.
41 Timing variables can be used in two ways:
43 - On the timing stack, using timevar_push and timevar_pop.
44 Timing variables may be pushed onto the stack; elapsed time is
45 attributed to the topmost timing variable on the stack. When
46 another variable is pushed on, the previous topmost variable is
47 'paused' until the pushed variable is popped back off.
49 - As a standalone timer, using timevar_start and timevar_stop.
50 All time elapsed between the two calls is attributed to the
51 variable.
54 /* This structure stores the various varieties of time that can be
55 measured. Times are stored in seconds. The time may be an
56 absolute time or a time difference; in the former case, the time
57 base is undefined, except that the difference between two times
58 produces a valid time difference. */
60 struct timevar_time_def
62 /* User time in this process. */
63 xtime_t user;
65 /* System time (if applicable for this host platform) in this
66 process. */
67 xtime_t sys;
69 /* Wall clock time. */
70 xtime_t wall;
73 /* An enumeration of timing variable identifiers. Constructed from
74 the contents of timevar.def. */
76 #define DEFTIMEVAR(identifier__, name__) \
77 identifier__,
78 typedef enum
80 #include "timevar.def"
81 TIMEVAR_LAST
83 timevar_id_t;
84 #undef DEFTIMEVAR
86 /* Initialize timing variables. */
88 void timevar_init (void);
90 /* Push TIMEVAR onto the timing stack. No further elapsed time is
91 attributed to the previous topmost timing variable on the stack;
92 subsequent elapsed time is attributed to TIMEVAR, until it is
93 popped or another element is pushed on top.
95 TIMEVAR cannot be running as a standalone timer. */
97 void timevar_push (timevar_id_t timevar);
99 /* Pop the topmost timing variable element off the timing stack. The
100 popped variable must be TIMEVAR. Elapsed time since the that
101 element was pushed on, or since it was last exposed on top of the
102 stack when the element above it was popped off, is credited to that
103 timing variable. */
105 void timevar_pop (timevar_id_t timevar);
107 /* Start timing TIMEVAR independently of the timing stack. Elapsed
108 time until timevar_stop is called for the same timing variable is
109 attributed to TIMEVAR. */
111 void timevar_start (timevar_id_t timevar);
113 /* Stop timing TIMEVAR. Time elapsed since timevar_start was called
114 is attributed to it. */
116 void timevar_stop (timevar_id_t timevar);
118 /* Fill the elapsed time for TIMEVAR into ELAPSED. Returns
119 update-to-date information even if TIMEVAR is currently running. */
121 void timevar_get (timevar_id_t timevar, struct timevar_time_def *elapsed);
123 /* Summarize timing variables to FP. The timing variable TV_TOTAL has
124 a special meaning -- it's considered to be the total elapsed time,
125 for normalizing the others, and is displayed last. */
127 void timevar_print (FILE *fp);
129 /* Set to to nonzero to enable timing variables. All the timevar
130 functions make an early exit if timevar is disabled. */
132 extern int timevar_enabled;
134 # ifdef __cplusplus
136 # endif
138 #endif /* ! _TIMEVAR_H */