190075Sobrien/* Timing variables for measuring compiler performance.
2169689Skan   Copyright (C) 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
390075Sobrien   Contributed by Alex Samuel <samuel@codesourcery.com>
490075Sobrien
590075Sobrien   This file is part of GCC.
690075Sobrien
790075Sobrien   GCC is free software; you can redistribute it and/or modify it
890075Sobrien   under the terms of the GNU General Public License as published by
990075Sobrien   the Free Software Foundation; either version 2, or (at your option)
1090075Sobrien   any later version.
1190075Sobrien
1290075Sobrien   GCC is distributed in the hope that it will be useful, but WITHOUT
1390075Sobrien   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1490075Sobrien   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
1590075Sobrien   License for more details.
1690075Sobrien
1790075Sobrien   You should have received a copy of the GNU General Public License
1890075Sobrien   along with GCC; see the file COPYING.  If not, write to the Free
19169689Skan   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20169689Skan   02110-1301, USA.  */
2190075Sobrien
2290075Sobrien#ifndef GCC_TIMEVAR_H
2390075Sobrien#define GCC_TIMEVAR_H
2490075Sobrien
2590075Sobrien/* Timing variables are used to measure elapsed time in various
2690075Sobrien   portions of the compiler.  Each measures elapsed user, system, and
2790075Sobrien   wall-clock time, as appropriate to and supported by the host
2890075Sobrien   system.
2990075Sobrien
3090075Sobrien   Timing variables are defined using the DEFTIMEVAR macro in
3190075Sobrien   timevar.def.  Each has an enumeral identifier, used when referring
3290075Sobrien   to the timing variable in code, and a character string name.
3390075Sobrien
3490075Sobrien   Timing variables can be used in two ways:
3590075Sobrien
3690075Sobrien     - On the timing stack, using timevar_push and timevar_pop.
3790075Sobrien       Timing variables may be pushed onto the stack; elapsed time is
3890075Sobrien       attributed to the topmost timing variable on the stack.  When
3990075Sobrien       another variable is pushed on, the previous topmost variable is
4090075Sobrien       `paused' until the pushed variable is popped back off.
4190075Sobrien
4290075Sobrien     - As a standalone timer, using timevar_start and timevar_stop.
4390075Sobrien       All time elapsed between the two calls is attributed to the
44117395Skan       variable.
4590075Sobrien*/
46117395Skan
4790075Sobrien/* This structure stores the various varieties of time that can be
4890075Sobrien   measured.  Times are stored in seconds.  The time may be an
4990075Sobrien   absolute time or a time difference; in the former case, the time
5090075Sobrien   base is undefined, except that the difference between two times
5190075Sobrien   produces a valid time difference.  */
5290075Sobrien
5390075Sobrienstruct timevar_time_def
5490075Sobrien{
5590075Sobrien  /* User time in this process.  */
56132718Skan  double user;
5790075Sobrien
5890075Sobrien  /* System time (if applicable for this host platform) in this
5990075Sobrien     process.  */
60132718Skan  double sys;
6190075Sobrien
6290075Sobrien  /* Wall clock time.  */
63132718Skan  double wall;
64169689Skan
65169689Skan  /* Garbage collector memory.  */
66169689Skan  unsigned ggc_mem;
6790075Sobrien};
6890075Sobrien
6990075Sobrien/* An enumeration of timing variable identifiers.  Constructed from
7090075Sobrien   the contents of timevar.def.  */
7190075Sobrien
7290075Sobrien#define DEFTIMEVAR(identifier__, name__) \
73117395Skan    identifier__,
7490075Sobrientypedef enum
7590075Sobrien{
7690075Sobrien#include "timevar.def"
7790075Sobrien  TIMEVAR_LAST
7890075Sobrien}
7990075Sobrientimevar_id_t;
8090075Sobrien#undef DEFTIMEVAR
8190075Sobrien
82117395Skan/* Execute the sequence: timevar_pop (TV), return (E);  */
83169689Skan#define POP_TIMEVAR_AND_RETURN(TV, E)  do { timevar_pop (TV); return (E); }while(0)
84169689Skan#define timevar_pop(TV) do { if (timevar_enable) timevar_pop_1 (TV); }while(0)
85169689Skan#define timevar_push(TV) do { if (timevar_enable) timevar_push_1 (TV); }while(0)
86117395Skan
87132718Skanextern void timevar_init (void);
88169689Skanextern void timevar_push_1 (timevar_id_t);
89169689Skanextern void timevar_pop_1 (timevar_id_t);
90132718Skanextern void timevar_start (timevar_id_t);
91132718Skanextern void timevar_stop (timevar_id_t);
92132718Skanextern void timevar_print (FILE *);
9390075Sobrien
9490075Sobrien/* Provided for backward compatibility.  */
95132718Skanextern void print_time (const char *, long);
9690075Sobrien
97169689Skanextern bool timevar_enable;
98169689Skan
99169689Skanextern size_t timevar_ggc_mem_total;
100169689Skan
10190075Sobrien#endif /* ! GCC_TIMEVAR_H */
102