1*e4b17023SJohn Marino /* Timing variables for measuring compiler performance.
2*e4b17023SJohn Marino Copyright (C) 2000, 2003, 2004, 2005, 2007, 2009, 2010
3*e4b17023SJohn Marino Free Software Foundation, Inc.
4*e4b17023SJohn Marino Contributed by Alex Samuel <samuel@codesourcery.com>
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it
9*e4b17023SJohn Marino under the terms of the GNU General Public License as published by
10*e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
11*e4b17023SJohn Marino any later version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT
14*e4b17023SJohn Marino ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15*e4b17023SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16*e4b17023SJohn Marino License for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino #ifndef GCC_TIMEVAR_H
23*e4b17023SJohn Marino #define GCC_TIMEVAR_H
24*e4b17023SJohn Marino
25*e4b17023SJohn Marino /* Timing variables are used to measure elapsed time in various
26*e4b17023SJohn Marino portions of the compiler. Each measures elapsed user, system, and
27*e4b17023SJohn Marino wall-clock time, as appropriate to and supported by the host
28*e4b17023SJohn Marino system.
29*e4b17023SJohn Marino
30*e4b17023SJohn Marino Timing variables are defined using the DEFTIMEVAR macro in
31*e4b17023SJohn Marino timevar.def. Each has an enumeral identifier, used when referring
32*e4b17023SJohn Marino to the timing variable in code, and a character string name.
33*e4b17023SJohn Marino
34*e4b17023SJohn Marino Timing variables can be used in two ways:
35*e4b17023SJohn Marino
36*e4b17023SJohn Marino - On the timing stack, using timevar_push and timevar_pop.
37*e4b17023SJohn Marino Timing variables may be pushed onto the stack; elapsed time is
38*e4b17023SJohn Marino attributed to the topmost timing variable on the stack. When
39*e4b17023SJohn Marino another variable is pushed on, the previous topmost variable is
40*e4b17023SJohn Marino `paused' until the pushed variable is popped back off.
41*e4b17023SJohn Marino
42*e4b17023SJohn Marino - As a standalone timer, using timevar_start and timevar_stop.
43*e4b17023SJohn Marino All time elapsed between the two calls is attributed to the
44*e4b17023SJohn Marino variable.
45*e4b17023SJohn Marino */
46*e4b17023SJohn Marino
47*e4b17023SJohn Marino /* This structure stores the various varieties of time that can be
48*e4b17023SJohn Marino measured. Times are stored in seconds. The time may be an
49*e4b17023SJohn Marino absolute time or a time difference; in the former case, the time
50*e4b17023SJohn Marino base is undefined, except that the difference between two times
51*e4b17023SJohn Marino produces a valid time difference. */
52*e4b17023SJohn Marino
53*e4b17023SJohn Marino struct timevar_time_def
54*e4b17023SJohn Marino {
55*e4b17023SJohn Marino /* User time in this process. */
56*e4b17023SJohn Marino double user;
57*e4b17023SJohn Marino
58*e4b17023SJohn Marino /* System time (if applicable for this host platform) in this
59*e4b17023SJohn Marino process. */
60*e4b17023SJohn Marino double sys;
61*e4b17023SJohn Marino
62*e4b17023SJohn Marino /* Wall clock time. */
63*e4b17023SJohn Marino double wall;
64*e4b17023SJohn Marino
65*e4b17023SJohn Marino /* Garbage collector memory. */
66*e4b17023SJohn Marino unsigned ggc_mem;
67*e4b17023SJohn Marino };
68*e4b17023SJohn Marino
69*e4b17023SJohn Marino /* An enumeration of timing variable identifiers. Constructed from
70*e4b17023SJohn Marino the contents of timevar.def. */
71*e4b17023SJohn Marino
72*e4b17023SJohn Marino #define DEFTIMEVAR(identifier__, name__) \
73*e4b17023SJohn Marino identifier__,
74*e4b17023SJohn Marino typedef enum
75*e4b17023SJohn Marino {
76*e4b17023SJohn Marino TV_NONE,
77*e4b17023SJohn Marino #include "timevar.def"
78*e4b17023SJohn Marino TIMEVAR_LAST
79*e4b17023SJohn Marino }
80*e4b17023SJohn Marino timevar_id_t;
81*e4b17023SJohn Marino #undef DEFTIMEVAR
82*e4b17023SJohn Marino
83*e4b17023SJohn Marino /* True if timevars should be used. In GCC, this happens with
84*e4b17023SJohn Marino the -ftime-report flag. */
85*e4b17023SJohn Marino extern bool timevar_enable;
86*e4b17023SJohn Marino
87*e4b17023SJohn Marino /* Total amount of memory allocated by garbage collector. */
88*e4b17023SJohn Marino extern size_t timevar_ggc_mem_total;
89*e4b17023SJohn Marino
90*e4b17023SJohn Marino extern void timevar_init (void);
91*e4b17023SJohn Marino extern void timevar_push_1 (timevar_id_t);
92*e4b17023SJohn Marino extern void timevar_pop_1 (timevar_id_t);
93*e4b17023SJohn Marino extern void timevar_start (timevar_id_t);
94*e4b17023SJohn Marino extern void timevar_stop (timevar_id_t);
95*e4b17023SJohn Marino extern bool timevar_cond_start (timevar_id_t);
96*e4b17023SJohn Marino extern void timevar_cond_stop (timevar_id_t, bool);
97*e4b17023SJohn Marino extern void timevar_print (FILE *);
98*e4b17023SJohn Marino
99*e4b17023SJohn Marino /* Provided for backward compatibility. */
100*e4b17023SJohn Marino static inline void
timevar_push(timevar_id_t tv)101*e4b17023SJohn Marino timevar_push (timevar_id_t tv)
102*e4b17023SJohn Marino {
103*e4b17023SJohn Marino if (timevar_enable)
104*e4b17023SJohn Marino timevar_push_1 (tv);
105*e4b17023SJohn Marino }
106*e4b17023SJohn Marino
107*e4b17023SJohn Marino static inline void
timevar_pop(timevar_id_t tv)108*e4b17023SJohn Marino timevar_pop (timevar_id_t tv)
109*e4b17023SJohn Marino {
110*e4b17023SJohn Marino if (timevar_enable)
111*e4b17023SJohn Marino timevar_pop_1 (tv);
112*e4b17023SJohn Marino }
113*e4b17023SJohn Marino
114*e4b17023SJohn Marino extern void print_time (const char *, long);
115*e4b17023SJohn Marino
116*e4b17023SJohn Marino #endif /* ! GCC_TIMEVAR_H */
117