re PR fortran/63861 (OpenACC coarray ICE (also with OpenMP?))
[official-gcc.git] / gcc / timevar.h
blob85c761009c27eb0793acfdaea1bc273640f8d70f
1 /* Timing variables for measuring compiler performance.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Alex Samuel <samuel@codesourcery.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_TIMEVAR_H
22 #define GCC_TIMEVAR_H
24 /* Timing variables are used to measure elapsed time in various
25 portions of the compiler. Each measures elapsed user, system, and
26 wall-clock time, as appropriate to and supported by the host
27 system.
29 Timing variables are defined using the DEFTIMEVAR macro in
30 timevar.def. Each has an enumeral identifier, used when referring
31 to the timing variable in code, and a character string name.
33 Timing variables can be used in two ways:
35 - On the timing stack, using timevar_push and timevar_pop.
36 Timing variables may be pushed onto the stack; elapsed time is
37 attributed to the topmost timing variable on the stack. When
38 another variable is pushed on, the previous topmost variable is
39 `paused' until the pushed variable is popped back off.
41 - As a standalone timer, using timevar_start and timevar_stop.
42 All time elapsed between the two calls is attributed to the
43 variable.
46 /* This structure stores the various varieties of time that can be
47 measured. Times are stored in seconds. The time may be an
48 absolute time or a time difference; in the former case, the time
49 base is undefined, except that the difference between two times
50 produces a valid time difference. */
52 struct timevar_time_def
54 /* User time in this process. */
55 double user;
57 /* System time (if applicable for this host platform) in this
58 process. */
59 double sys;
61 /* Wall clock time. */
62 double wall;
64 /* Garbage collector memory. */
65 size_t ggc_mem;
68 /* An enumeration of timing variable identifiers. Constructed from
69 the contents of timevar.def. */
71 #define DEFTIMEVAR(identifier__, name__) \
72 identifier__,
73 typedef enum
75 TV_NONE,
76 #include "timevar.def"
77 TIMEVAR_LAST
79 timevar_id_t;
80 #undef DEFTIMEVAR
82 /* A class to hold all state relating to timing. */
84 class timer;
86 /* The singleton instance of timing state.
88 This is non-NULL if timevars should be used. In GCC, this happens with
89 the -ftime-report flag. Hence this is NULL for the common,
90 needs-to-be-fast case, with an early reject happening for this being
91 NULL. */
92 extern timer *g_timer;
94 /* Total amount of memory allocated by garbage collector. */
95 extern size_t timevar_ggc_mem_total;
97 extern void timevar_init (void);
98 extern void timevar_start (timevar_id_t);
99 extern void timevar_stop (timevar_id_t);
100 extern bool timevar_cond_start (timevar_id_t);
101 extern void timevar_cond_stop (timevar_id_t, bool);
103 /* The public (within GCC) interface for timing. */
105 class timer
107 public:
108 timer ();
109 ~timer ();
111 void start (timevar_id_t tv);
112 void stop (timevar_id_t tv);
113 void push (timevar_id_t tv);
114 void pop (timevar_id_t tv);
115 bool cond_start (timevar_id_t tv);
116 void cond_stop (timevar_id_t tv);
118 void push_client_item (const char *item_name);
119 void pop_client_item ();
121 void print (FILE *fp);
123 const char *get_topmost_item_name () const;
125 private:
126 /* Private member functions. */
127 void validate_phases (FILE *fp) const;
129 struct timevar_def;
130 void push_internal (struct timevar_def *tv);
131 void pop_internal ();
132 static void print_row (FILE *fp,
133 const timevar_time_def *total,
134 const timevar_def *tv);
136 private:
138 /* Private type: a timing variable. */
139 struct timevar_def
141 /* Elapsed time for this variable. */
142 struct timevar_time_def elapsed;
144 /* If this variable is timed independently of the timing stack,
145 using timevar_start, this contains the start time. */
146 struct timevar_time_def start_time;
148 /* The name of this timing variable. */
149 const char *name;
151 /* Nonzero if this timing variable is running as a standalone
152 timer. */
153 unsigned standalone : 1;
155 /* Nonzero if this timing variable was ever started or pushed onto
156 the timing stack. */
157 unsigned used : 1;
160 /* Private type: an element on the timing stack
161 Elapsed time is attributed to the topmost timing variable on the
162 stack. */
163 struct timevar_stack_def
165 /* The timing variable at this stack level. */
166 struct timevar_def *timevar;
168 /* The next lower timing variable context in the stack. */
169 struct timevar_stack_def *next;
172 /* A class for managing a collection of named timing items, for use
173 e.g. by libgccjit for timing client code. This class is declared
174 inside timevar.c to avoid everything using timevar.h
175 from needing vec and hash_map. */
176 class named_items;
178 private:
180 /* Data members (all private). */
182 /* Declared timing variables. Constructed from the contents of
183 timevar.def. */
184 timevar_def m_timevars[TIMEVAR_LAST];
186 /* The top of the timing stack. */
187 timevar_stack_def *m_stack;
189 /* A list of unused (i.e. allocated and subsequently popped)
190 timevar_stack_def instances. */
191 timevar_stack_def *m_unused_stack_instances;
193 /* The time at which the topmost element on the timing stack was
194 pushed. Time elapsed since then is attributed to the topmost
195 element. */
196 timevar_time_def m_start_time;
198 /* If non-NULL, for use when timing libgccjit's client code. */
199 named_items *m_jit_client_items;
201 friend class named_items;
204 /* Provided for backward compatibility. */
205 static inline void
206 timevar_push (timevar_id_t tv)
208 if (g_timer)
209 g_timer->push (tv);
212 static inline void
213 timevar_pop (timevar_id_t tv)
215 if (g_timer)
216 g_timer->pop (tv);
219 // This is a simple timevar wrapper class that pushes a timevar in its
220 // constructor and pops the timevar in its destructor.
221 class auto_timevar
223 public:
224 auto_timevar (timer *t, timevar_id_t tv)
225 : m_timer (t),
226 m_tv (tv)
228 if (m_timer)
229 m_timer->push (m_tv);
232 ~auto_timevar ()
234 if (m_timer)
235 m_timer->pop (m_tv);
238 private:
240 // Private to disallow copies.
241 auto_timevar (const auto_timevar &);
243 timer *m_timer;
244 timevar_id_t m_tv;
247 extern void print_time (const char *, long);
249 #endif /* ! GCC_TIMEVAR_H */