annotate gcc/timevar.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Timing variables for measuring compiler performance.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2000-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Alex Samuel <samuel@codesourcery.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "system.h"
111
kono
parents: 67
diff changeset
23 #include "coretypes.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
24 #include "timevar.h"
111
kono
parents: 67
diff changeset
25 #include "options.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #ifndef HAVE_CLOCK_T
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 typedef int clock_t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 #ifndef HAVE_STRUCT_TMS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 struct tms
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 clock_t tms_utime;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 clock_t tms_stime;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 clock_t tms_cutime;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 clock_t tms_cstime;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 #ifndef RUSAGE_SELF
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 # define RUSAGE_SELF 0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 /* Calculation of scale factor to convert ticks to microseconds.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 We mustn't use CLOCKS_PER_SEC except with clock(). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 #if HAVE_SYSCONF && defined _SC_CLK_TCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 # define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 # ifdef CLK_TCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 # define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 # else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 # ifdef HZ
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 # define TICKS_PER_SECOND HZ /* traditional UNIX */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 # else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 # define TICKS_PER_SECOND 100 /* often the correct value */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 /* Prefer times to getrusage to clock (each gives successively less
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 information). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 #ifdef HAVE_TIMES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 # if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 extern clock_t times (struct tms *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 # define USE_TIMES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 # define HAVE_USER_TIME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 # define HAVE_SYS_TIME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 # define HAVE_WALL_TIME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 #ifdef HAVE_GETRUSAGE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 # if defined HAVE_DECL_GETRUSAGE && !HAVE_DECL_GETRUSAGE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 extern int getrusage (int, struct rusage *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 # define USE_GETRUSAGE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 # define HAVE_USER_TIME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 # define HAVE_SYS_TIME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 #ifdef HAVE_CLOCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 # if defined HAVE_DECL_CLOCK && !HAVE_DECL_CLOCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 extern clock_t clock (void);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 # define USE_CLOCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 # define HAVE_USER_TIME
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 /* libc is very likely to have snuck a call to sysconf() into one of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 the underlying constants, and that can be very slow, so we have to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 precompute them. Whose wonderful idea was it to make all those
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 _constants_ variable at run time, anyway? */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 #ifdef USE_TIMES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 static double ticks_to_msec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 #define TICKS_TO_MSEC (1 / (double)TICKS_PER_SECOND)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 #ifdef USE_CLOCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 static double clocks_to_msec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 #define CLOCKS_TO_MSEC (1 / (double)CLOCKS_PER_SEC)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
111
kono
parents: 67
diff changeset
104 /* Non-NULL if timevars should be used. In GCC, this happens with
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
105 the -ftime-report flag. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
111
kono
parents: 67
diff changeset
107 timer *g_timer;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 /* Total amount of memory allocated by garbage collector. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 size_t timevar_ggc_mem_total;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 /* The amount of memory that will cause us to report the timevar even
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 if the time spent is not significant. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 #define GGC_MEM_BOUND (1 << 20)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 /* See timevar.h for an explanation of timing variables. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 static void get_time (struct timevar_time_def *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 static void timevar_accumulate (struct timevar_time_def *,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 struct timevar_time_def *,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 struct timevar_time_def *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
111
kono
parents: 67
diff changeset
125 /* The implementation of timing events for jit client code, allowing
kono
parents: 67
diff changeset
126 arbitrary named items to appear on the timing stack. */
kono
parents: 67
diff changeset
127
kono
parents: 67
diff changeset
128 class timer::named_items
kono
parents: 67
diff changeset
129 {
kono
parents: 67
diff changeset
130 public:
kono
parents: 67
diff changeset
131 named_items (timer *t);
kono
parents: 67
diff changeset
132 ~named_items ();
kono
parents: 67
diff changeset
133
kono
parents: 67
diff changeset
134 void push (const char *item_name);
kono
parents: 67
diff changeset
135 void pop ();
kono
parents: 67
diff changeset
136 void print (FILE *fp, const timevar_time_def *total);
kono
parents: 67
diff changeset
137
kono
parents: 67
diff changeset
138 private:
kono
parents: 67
diff changeset
139 /* Which timer instance does this relate to? */
kono
parents: 67
diff changeset
140 timer *m_timer;
kono
parents: 67
diff changeset
141
kono
parents: 67
diff changeset
142 /* Dictionary, mapping from item names to timevar_def.
kono
parents: 67
diff changeset
143 Note that currently we merely store/compare the raw string
kono
parents: 67
diff changeset
144 pointers provided by client code; we don't take a copy,
kono
parents: 67
diff changeset
145 or use strcmp. */
kono
parents: 67
diff changeset
146 hash_map <const char *, timer::timevar_def> m_hash_map;
kono
parents: 67
diff changeset
147
kono
parents: 67
diff changeset
148 /* The order in which items were originally inserted. */
kono
parents: 67
diff changeset
149 auto_vec <const char *> m_names;
kono
parents: 67
diff changeset
150 };
kono
parents: 67
diff changeset
151
kono
parents: 67
diff changeset
152 /* The constructor for class timer::named_items. */
kono
parents: 67
diff changeset
153
kono
parents: 67
diff changeset
154 timer::named_items::named_items (timer *t)
kono
parents: 67
diff changeset
155 : m_timer (t),
kono
parents: 67
diff changeset
156 m_hash_map (),
kono
parents: 67
diff changeset
157 m_names ()
kono
parents: 67
diff changeset
158 {
kono
parents: 67
diff changeset
159 }
kono
parents: 67
diff changeset
160
kono
parents: 67
diff changeset
161 /* The destructor for class timer::named_items. */
kono
parents: 67
diff changeset
162
kono
parents: 67
diff changeset
163 timer::named_items::~named_items ()
kono
parents: 67
diff changeset
164 {
kono
parents: 67
diff changeset
165 }
kono
parents: 67
diff changeset
166
kono
parents: 67
diff changeset
167 /* Push the named item onto the timer stack. */
kono
parents: 67
diff changeset
168
kono
parents: 67
diff changeset
169 void
kono
parents: 67
diff changeset
170 timer::named_items::push (const char *item_name)
kono
parents: 67
diff changeset
171 {
kono
parents: 67
diff changeset
172 gcc_assert (item_name);
kono
parents: 67
diff changeset
173
kono
parents: 67
diff changeset
174 bool existed;
kono
parents: 67
diff changeset
175 timer::timevar_def *def = &m_hash_map.get_or_insert (item_name, &existed);
kono
parents: 67
diff changeset
176 if (!existed)
kono
parents: 67
diff changeset
177 {
kono
parents: 67
diff changeset
178 def->elapsed.user = 0;
kono
parents: 67
diff changeset
179 def->elapsed.sys = 0;
kono
parents: 67
diff changeset
180 def->elapsed.wall = 0;
kono
parents: 67
diff changeset
181 def->name = item_name;
kono
parents: 67
diff changeset
182 def->standalone = 0;
kono
parents: 67
diff changeset
183 m_names.safe_push (item_name);
kono
parents: 67
diff changeset
184 }
kono
parents: 67
diff changeset
185 m_timer->push_internal (def);
kono
parents: 67
diff changeset
186 }
kono
parents: 67
diff changeset
187
kono
parents: 67
diff changeset
188 /* Pop the top item from the timer stack. */
kono
parents: 67
diff changeset
189
kono
parents: 67
diff changeset
190 void
kono
parents: 67
diff changeset
191 timer::named_items::pop ()
kono
parents: 67
diff changeset
192 {
kono
parents: 67
diff changeset
193 m_timer->pop_internal ();
kono
parents: 67
diff changeset
194 }
kono
parents: 67
diff changeset
195
kono
parents: 67
diff changeset
196 /* Print the given client item. Helper function for timer::print. */
kono
parents: 67
diff changeset
197
kono
parents: 67
diff changeset
198 void
kono
parents: 67
diff changeset
199 timer::named_items::print (FILE *fp, const timevar_time_def *total)
kono
parents: 67
diff changeset
200 {
kono
parents: 67
diff changeset
201 unsigned int i;
kono
parents: 67
diff changeset
202 const char *item_name;
kono
parents: 67
diff changeset
203 fprintf (fp, "Client items:\n");
kono
parents: 67
diff changeset
204 FOR_EACH_VEC_ELT (m_names, i, item_name)
kono
parents: 67
diff changeset
205 {
kono
parents: 67
diff changeset
206 timer::timevar_def *def = m_hash_map.get (item_name);
kono
parents: 67
diff changeset
207 gcc_assert (def);
kono
parents: 67
diff changeset
208 m_timer->print_row (fp, total, def->name, def->elapsed);
kono
parents: 67
diff changeset
209 }
kono
parents: 67
diff changeset
210 }
kono
parents: 67
diff changeset
211
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 /* Fill the current times into TIME. The definition of this function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 also defines any or all of the HAVE_USER_TIME, HAVE_SYS_TIME, and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 HAVE_WALL_TIME macros. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 get_time (struct timevar_time_def *now)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 now->user = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 now->sys = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 now->wall = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 now->ggc_mem = timevar_ggc_mem_total;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 #ifdef USE_TIMES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 struct tms tms;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 now->wall = times (&tms) * ticks_to_msec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 now->user = tms.tms_utime * ticks_to_msec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 now->sys = tms.tms_stime * ticks_to_msec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 #ifdef USE_GETRUSAGE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 struct rusage rusage;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 getrusage (RUSAGE_SELF, &rusage);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 #ifdef USE_CLOCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 now->user = clock () * clocks_to_msec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 /* Add the difference between STOP_TIME and START_TIME to TIMER. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 timevar_accumulate (struct timevar_time_def *timer,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 struct timevar_time_def *start_time,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 struct timevar_time_def *stop_time)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 timer->user += stop_time->user - start_time->user;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 timer->sys += stop_time->sys - start_time->sys;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 timer->wall += stop_time->wall - start_time->wall;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 timer->ggc_mem += stop_time->ggc_mem - start_time->ggc_mem;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
111
kono
parents: 67
diff changeset
256 /* Class timer's constructor. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257
111
kono
parents: 67
diff changeset
258 timer::timer () :
kono
parents: 67
diff changeset
259 m_stack (NULL),
kono
parents: 67
diff changeset
260 m_unused_stack_instances (NULL),
kono
parents: 67
diff changeset
261 m_start_time (),
kono
parents: 67
diff changeset
262 m_jit_client_items (NULL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 /* Zero all elapsed times. */
111
kono
parents: 67
diff changeset
265 memset (m_timevars, 0, sizeof (m_timevars));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 /* Initialize the names of timing variables. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 #define DEFTIMEVAR(identifier__, name__) \
111
kono
parents: 67
diff changeset
269 m_timevars[identifier__].name = name__;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 #include "timevar.def"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 #undef DEFTIMEVAR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272
111
kono
parents: 67
diff changeset
273 /* Initialize configuration-specific state.
kono
parents: 67
diff changeset
274 Ideally this would be one-time initialization. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 #ifdef USE_TIMES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 ticks_to_msec = TICKS_TO_MSEC;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 #ifdef USE_CLOCK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 clocks_to_msec = CLOCKS_TO_MSEC;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
111
kono
parents: 67
diff changeset
283 /* Class timer's destructor. */
kono
parents: 67
diff changeset
284
kono
parents: 67
diff changeset
285 timer::~timer ()
kono
parents: 67
diff changeset
286 {
kono
parents: 67
diff changeset
287 timevar_stack_def *iter, *next;
kono
parents: 67
diff changeset
288
kono
parents: 67
diff changeset
289 for (iter = m_stack; iter; iter = next)
kono
parents: 67
diff changeset
290 {
kono
parents: 67
diff changeset
291 next = iter->next;
kono
parents: 67
diff changeset
292 free (iter);
kono
parents: 67
diff changeset
293 }
kono
parents: 67
diff changeset
294 for (iter = m_unused_stack_instances; iter; iter = next)
kono
parents: 67
diff changeset
295 {
kono
parents: 67
diff changeset
296 next = iter->next;
kono
parents: 67
diff changeset
297 free (iter);
kono
parents: 67
diff changeset
298 }
kono
parents: 67
diff changeset
299 for (unsigned i = 0; i < TIMEVAR_LAST; ++i)
kono
parents: 67
diff changeset
300 delete m_timevars[i].children;
kono
parents: 67
diff changeset
301
kono
parents: 67
diff changeset
302 delete m_jit_client_items;
kono
parents: 67
diff changeset
303 }
kono
parents: 67
diff changeset
304
kono
parents: 67
diff changeset
305 /* Initialize timing variables. */
kono
parents: 67
diff changeset
306
kono
parents: 67
diff changeset
307 void
kono
parents: 67
diff changeset
308 timevar_init (void)
kono
parents: 67
diff changeset
309 {
kono
parents: 67
diff changeset
310 if (g_timer)
kono
parents: 67
diff changeset
311 return;
kono
parents: 67
diff changeset
312
kono
parents: 67
diff changeset
313 g_timer = new timer ();
kono
parents: 67
diff changeset
314 }
kono
parents: 67
diff changeset
315
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 /* Push TIMEVAR onto the timing stack. No further elapsed time is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 attributed to the previous topmost timing variable on the stack;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 subsequent elapsed time is attributed to TIMEVAR, until it is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 popped or another element is pushed on top.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 TIMEVAR cannot be running as a standalone timer. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 void
111
kono
parents: 67
diff changeset
324 timer::push (timevar_id_t timevar)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 {
111
kono
parents: 67
diff changeset
326 struct timevar_def *tv = &m_timevars[timevar];
kono
parents: 67
diff changeset
327 push_internal (tv);
kono
parents: 67
diff changeset
328 }
kono
parents: 67
diff changeset
329
kono
parents: 67
diff changeset
330 /* Push TV onto the timing stack, either one of the builtin ones
kono
parents: 67
diff changeset
331 for a timevar_id_t, or one provided by client code to libgccjit. */
kono
parents: 67
diff changeset
332
kono
parents: 67
diff changeset
333 void
kono
parents: 67
diff changeset
334 timer::push_internal (struct timevar_def *tv)
kono
parents: 67
diff changeset
335 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 struct timevar_stack_def *context;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 struct timevar_time_def now;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338
111
kono
parents: 67
diff changeset
339 gcc_assert (tv);
kono
parents: 67
diff changeset
340
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 /* Mark this timing variable as used. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 tv->used = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 /* Can't push a standalone timer. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 gcc_assert (!tv->standalone);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 /* What time is it? */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 get_time (&now);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 /* If the stack isn't empty, attribute the current elapsed time to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 the old topmost element. */
111
kono
parents: 67
diff changeset
352 if (m_stack)
kono
parents: 67
diff changeset
353 timevar_accumulate (&m_stack->timevar->elapsed, &m_start_time, &now);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 /* Reset the start time; from now on, time is attributed to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 TIMEVAR. */
111
kono
parents: 67
diff changeset
357 m_start_time = now;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 /* See if we have a previously-allocated stack instance. If so,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 take it off the list. If not, malloc a new one. */
111
kono
parents: 67
diff changeset
361 if (m_unused_stack_instances != NULL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 {
111
kono
parents: 67
diff changeset
363 context = m_unused_stack_instances;
kono
parents: 67
diff changeset
364 m_unused_stack_instances = m_unused_stack_instances->next;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 context = XNEW (struct timevar_stack_def);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 /* Fill it in and put it on the stack. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 context->timevar = tv;
111
kono
parents: 67
diff changeset
371 context->next = m_stack;
kono
parents: 67
diff changeset
372 m_stack = context;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 /* Pop the topmost timing variable element off the timing stack. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 popped variable must be TIMEVAR. Elapsed time since the that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 element was pushed on, or since it was last exposed on top of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 stack when the element above it was popped off, is credited to that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 timing variable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 void
111
kono
parents: 67
diff changeset
382 timer::pop (timevar_id_t timevar)
kono
parents: 67
diff changeset
383 {
kono
parents: 67
diff changeset
384 gcc_assert (&m_timevars[timevar] == m_stack->timevar);
kono
parents: 67
diff changeset
385
kono
parents: 67
diff changeset
386 pop_internal ();
kono
parents: 67
diff changeset
387 }
kono
parents: 67
diff changeset
388
kono
parents: 67
diff changeset
389 /* Pop the topmost item from the stack, either one of the builtin ones
kono
parents: 67
diff changeset
390 for a timevar_id_t, or one provided by client code to libgccjit. */
kono
parents: 67
diff changeset
391
kono
parents: 67
diff changeset
392 void
kono
parents: 67
diff changeset
393 timer::pop_internal ()
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 struct timevar_time_def now;
111
kono
parents: 67
diff changeset
396 struct timevar_stack_def *popped = m_stack;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
397
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 /* What time is it? */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 get_time (&now);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 /* Attribute the elapsed time to the element we're popping. */
111
kono
parents: 67
diff changeset
402 timevar_accumulate (&popped->timevar->elapsed, &m_start_time, &now);
kono
parents: 67
diff changeset
403
kono
parents: 67
diff changeset
404 /* Take the item off the stack. */
kono
parents: 67
diff changeset
405 m_stack = m_stack->next;
kono
parents: 67
diff changeset
406
kono
parents: 67
diff changeset
407 /* Record the elapsed sub-time to the parent as well. */
kono
parents: 67
diff changeset
408 if (m_stack && time_report_details)
kono
parents: 67
diff changeset
409 {
kono
parents: 67
diff changeset
410 if (! m_stack->timevar->children)
kono
parents: 67
diff changeset
411 m_stack->timevar->children = new child_map_t (5);
kono
parents: 67
diff changeset
412 bool existed_p;
kono
parents: 67
diff changeset
413 timevar_time_def &time
kono
parents: 67
diff changeset
414 = m_stack->timevar->children->get_or_insert (popped->timevar, &existed_p);
kono
parents: 67
diff changeset
415 if (! existed_p)
kono
parents: 67
diff changeset
416 memset (&time, 0, sizeof (timevar_time_def));
kono
parents: 67
diff changeset
417 timevar_accumulate (&time, &m_start_time, &now);
kono
parents: 67
diff changeset
418 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 /* Reset the start time; from now on, time is attributed to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 element just exposed on the stack. */
111
kono
parents: 67
diff changeset
422 m_start_time = now;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 /* Don't delete the stack element; instead, add it to the list of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 unused elements for later use. */
111
kono
parents: 67
diff changeset
426 popped->next = m_unused_stack_instances;
kono
parents: 67
diff changeset
427 m_unused_stack_instances = popped;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 /* Start timing TIMEVAR independently of the timing stack. Elapsed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 time until timevar_stop is called for the same timing variable is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 attributed to TIMEVAR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 timevar_start (timevar_id_t timevar)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 {
111
kono
parents: 67
diff changeset
437 if (!g_timer)
kono
parents: 67
diff changeset
438 return;
kono
parents: 67
diff changeset
439
kono
parents: 67
diff changeset
440 g_timer->start (timevar);
kono
parents: 67
diff changeset
441 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
111
kono
parents: 67
diff changeset
443 /* See timevar_start above. */
kono
parents: 67
diff changeset
444
kono
parents: 67
diff changeset
445 void
kono
parents: 67
diff changeset
446 timer::start (timevar_id_t timevar)
kono
parents: 67
diff changeset
447 {
kono
parents: 67
diff changeset
448 struct timevar_def *tv = &m_timevars[timevar];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 /* Mark this timing variable as used. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 tv->used = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 /* Don't allow the same timing variable to be started more than
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 once. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 gcc_assert (!tv->standalone);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 tv->standalone = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 get_time (&tv->start_time);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 /* Stop timing TIMEVAR. Time elapsed since timevar_start was called
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 is attributed to it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 timevar_stop (timevar_id_t timevar)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 {
111
kono
parents: 67
diff changeset
467 if (!g_timer)
kono
parents: 67
diff changeset
468 return;
kono
parents: 67
diff changeset
469
kono
parents: 67
diff changeset
470 g_timer->stop (timevar);
kono
parents: 67
diff changeset
471 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472
111
kono
parents: 67
diff changeset
473 /* See timevar_stop above. */
kono
parents: 67
diff changeset
474
kono
parents: 67
diff changeset
475 void
kono
parents: 67
diff changeset
476 timer::stop (timevar_id_t timevar)
kono
parents: 67
diff changeset
477 {
kono
parents: 67
diff changeset
478 struct timevar_def *tv = &m_timevars[timevar];
kono
parents: 67
diff changeset
479 struct timevar_time_def now;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 /* TIMEVAR must have been started via timevar_start. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 gcc_assert (tv->standalone);
111
kono
parents: 67
diff changeset
483 tv->standalone = 0; /* Enable a restart. */
kono
parents: 67
diff changeset
484
kono
parents: 67
diff changeset
485 get_time (&now);
kono
parents: 67
diff changeset
486 timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
kono
parents: 67
diff changeset
487 }
kono
parents: 67
diff changeset
488
kono
parents: 67
diff changeset
489
kono
parents: 67
diff changeset
490 /* Conditionally start timing TIMEVAR independently of the timing stack.
kono
parents: 67
diff changeset
491 If the timer is already running, leave it running and return true.
kono
parents: 67
diff changeset
492 Otherwise, start the timer and return false.
kono
parents: 67
diff changeset
493 Elapsed time until the corresponding timevar_cond_stop
kono
parents: 67
diff changeset
494 is called for the same timing variable is attributed to TIMEVAR. */
kono
parents: 67
diff changeset
495
kono
parents: 67
diff changeset
496 bool
kono
parents: 67
diff changeset
497 timevar_cond_start (timevar_id_t timevar)
kono
parents: 67
diff changeset
498 {
kono
parents: 67
diff changeset
499 if (!g_timer)
kono
parents: 67
diff changeset
500 return false;
kono
parents: 67
diff changeset
501
kono
parents: 67
diff changeset
502 return g_timer->cond_start (timevar);
kono
parents: 67
diff changeset
503 }
kono
parents: 67
diff changeset
504
kono
parents: 67
diff changeset
505 /* See timevar_cond_start above. */
kono
parents: 67
diff changeset
506
kono
parents: 67
diff changeset
507 bool
kono
parents: 67
diff changeset
508 timer::cond_start (timevar_id_t timevar)
kono
parents: 67
diff changeset
509 {
kono
parents: 67
diff changeset
510 struct timevar_def *tv = &m_timevars[timevar];
kono
parents: 67
diff changeset
511
kono
parents: 67
diff changeset
512 /* Mark this timing variable as used. */
kono
parents: 67
diff changeset
513 tv->used = 1;
kono
parents: 67
diff changeset
514
kono
parents: 67
diff changeset
515 if (tv->standalone)
kono
parents: 67
diff changeset
516 return true; /* The timevar is already running. */
kono
parents: 67
diff changeset
517
kono
parents: 67
diff changeset
518 /* Don't allow the same timing variable
kono
parents: 67
diff changeset
519 to be unconditionally started more than once. */
kono
parents: 67
diff changeset
520 tv->standalone = 1;
kono
parents: 67
diff changeset
521
kono
parents: 67
diff changeset
522 get_time (&tv->start_time);
kono
parents: 67
diff changeset
523 return false; /* The timevar was not already running. */
kono
parents: 67
diff changeset
524 }
kono
parents: 67
diff changeset
525
kono
parents: 67
diff changeset
526 /* Conditionally stop timing TIMEVAR. The RUNNING parameter must come
kono
parents: 67
diff changeset
527 from the return value of a dynamically matching timevar_cond_start.
kono
parents: 67
diff changeset
528 If the timer had already been RUNNING, do nothing. Otherwise, time
kono
parents: 67
diff changeset
529 elapsed since timevar_cond_start was called is attributed to it. */
kono
parents: 67
diff changeset
530
kono
parents: 67
diff changeset
531 void
kono
parents: 67
diff changeset
532 timevar_cond_stop (timevar_id_t timevar, bool running)
kono
parents: 67
diff changeset
533 {
kono
parents: 67
diff changeset
534 if (!g_timer || running)
kono
parents: 67
diff changeset
535 return;
kono
parents: 67
diff changeset
536
kono
parents: 67
diff changeset
537 g_timer->cond_stop (timevar);
kono
parents: 67
diff changeset
538 }
kono
parents: 67
diff changeset
539
kono
parents: 67
diff changeset
540 /* See timevar_cond_stop above. */
kono
parents: 67
diff changeset
541
kono
parents: 67
diff changeset
542 void
kono
parents: 67
diff changeset
543 timer::cond_stop (timevar_id_t timevar)
kono
parents: 67
diff changeset
544 {
kono
parents: 67
diff changeset
545 struct timevar_def *tv;
kono
parents: 67
diff changeset
546 struct timevar_time_def now;
kono
parents: 67
diff changeset
547
kono
parents: 67
diff changeset
548 tv = &m_timevars[timevar];
kono
parents: 67
diff changeset
549
kono
parents: 67
diff changeset
550 /* TIMEVAR must have been started via timevar_cond_start. */
kono
parents: 67
diff changeset
551 gcc_assert (tv->standalone);
kono
parents: 67
diff changeset
552 tv->standalone = 0; /* Enable a restart. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 get_time (&now);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557
111
kono
parents: 67
diff changeset
558 /* Push the named item onto the timing stack. */
kono
parents: 67
diff changeset
559
kono
parents: 67
diff changeset
560 void
kono
parents: 67
diff changeset
561 timer::push_client_item (const char *item_name)
kono
parents: 67
diff changeset
562 {
kono
parents: 67
diff changeset
563 gcc_assert (item_name);
kono
parents: 67
diff changeset
564
kono
parents: 67
diff changeset
565 /* Lazily create the named_items instance. */
kono
parents: 67
diff changeset
566 if (!m_jit_client_items)
kono
parents: 67
diff changeset
567 m_jit_client_items = new named_items (this);
kono
parents: 67
diff changeset
568
kono
parents: 67
diff changeset
569 m_jit_client_items->push (item_name);
kono
parents: 67
diff changeset
570 }
kono
parents: 67
diff changeset
571
kono
parents: 67
diff changeset
572 /* Pop the top-most client item from the timing stack. */
kono
parents: 67
diff changeset
573
kono
parents: 67
diff changeset
574 void
kono
parents: 67
diff changeset
575 timer::pop_client_item ()
kono
parents: 67
diff changeset
576 {
kono
parents: 67
diff changeset
577 gcc_assert (m_jit_client_items);
kono
parents: 67
diff changeset
578 m_jit_client_items->pop ();
kono
parents: 67
diff changeset
579 }
kono
parents: 67
diff changeset
580
kono
parents: 67
diff changeset
581 /* Validate that phase times are consistent. */
kono
parents: 67
diff changeset
582
kono
parents: 67
diff changeset
583 void
kono
parents: 67
diff changeset
584 timer::validate_phases (FILE *fp) const
kono
parents: 67
diff changeset
585 {
kono
parents: 67
diff changeset
586 unsigned int /* timevar_id_t */ id;
kono
parents: 67
diff changeset
587 const timevar_time_def *total = &m_timevars[TV_TOTAL].elapsed;
kono
parents: 67
diff changeset
588 double phase_user = 0.0;
kono
parents: 67
diff changeset
589 double phase_sys = 0.0;
kono
parents: 67
diff changeset
590 double phase_wall = 0.0;
kono
parents: 67
diff changeset
591 size_t phase_ggc_mem = 0;
kono
parents: 67
diff changeset
592 static char phase_prefix[] = "phase ";
kono
parents: 67
diff changeset
593 const double tolerance = 1.000001; /* One part in a million. */
kono
parents: 67
diff changeset
594
kono
parents: 67
diff changeset
595 for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
kono
parents: 67
diff changeset
596 {
kono
parents: 67
diff changeset
597 const timevar_def *tv = &m_timevars[(timevar_id_t) id];
kono
parents: 67
diff changeset
598
kono
parents: 67
diff changeset
599 /* Don't evaluate timing variables that were never used. */
kono
parents: 67
diff changeset
600 if (!tv->used)
kono
parents: 67
diff changeset
601 continue;
kono
parents: 67
diff changeset
602
kono
parents: 67
diff changeset
603 if (strncmp (tv->name, phase_prefix, sizeof phase_prefix - 1) == 0)
kono
parents: 67
diff changeset
604 {
kono
parents: 67
diff changeset
605 phase_user += tv->elapsed.user;
kono
parents: 67
diff changeset
606 phase_sys += tv->elapsed.sys;
kono
parents: 67
diff changeset
607 phase_wall += tv->elapsed.wall;
kono
parents: 67
diff changeset
608 phase_ggc_mem += tv->elapsed.ggc_mem;
kono
parents: 67
diff changeset
609 }
kono
parents: 67
diff changeset
610 }
kono
parents: 67
diff changeset
611
kono
parents: 67
diff changeset
612 if (phase_user > total->user * tolerance
kono
parents: 67
diff changeset
613 || phase_sys > total->sys * tolerance
kono
parents: 67
diff changeset
614 || phase_wall > total->wall * tolerance
kono
parents: 67
diff changeset
615 || phase_ggc_mem > total->ggc_mem * tolerance)
kono
parents: 67
diff changeset
616 {
kono
parents: 67
diff changeset
617
kono
parents: 67
diff changeset
618 fprintf (fp, "Timing error: total of phase timers exceeds total time.\n");
kono
parents: 67
diff changeset
619 if (phase_user > total->user)
kono
parents: 67
diff changeset
620 fprintf (fp, "user %24.18e > %24.18e\n", phase_user, total->user);
kono
parents: 67
diff changeset
621 if (phase_sys > total->sys)
kono
parents: 67
diff changeset
622 fprintf (fp, "sys %24.18e > %24.18e\n", phase_sys, total->sys);
kono
parents: 67
diff changeset
623 if (phase_wall > total->wall)
kono
parents: 67
diff changeset
624 fprintf (fp, "wall %24.18e > %24.18e\n", phase_wall, total->wall);
kono
parents: 67
diff changeset
625 if (phase_ggc_mem > total->ggc_mem)
kono
parents: 67
diff changeset
626 fprintf (fp, "ggc_mem %24lu > %24lu\n", (unsigned long)phase_ggc_mem,
kono
parents: 67
diff changeset
627 (unsigned long)total->ggc_mem);
kono
parents: 67
diff changeset
628 gcc_unreachable ();
kono
parents: 67
diff changeset
629 }
kono
parents: 67
diff changeset
630 }
kono
parents: 67
diff changeset
631
kono
parents: 67
diff changeset
632 /* Helper function for timer::print. */
kono
parents: 67
diff changeset
633
kono
parents: 67
diff changeset
634 void
kono
parents: 67
diff changeset
635 timer::print_row (FILE *fp,
kono
parents: 67
diff changeset
636 const timevar_time_def *total,
kono
parents: 67
diff changeset
637 const char *name, const timevar_time_def &elapsed)
kono
parents: 67
diff changeset
638 {
kono
parents: 67
diff changeset
639 /* The timing variable name. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
640 fprintf (fp, " %-35s:", name);
111
kono
parents: 67
diff changeset
641
kono
parents: 67
diff changeset
642 #ifdef HAVE_USER_TIME
kono
parents: 67
diff changeset
643 /* Print user-mode time for this process. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
644 fprintf (fp, "%7.2f (%3.0f%%)",
111
kono
parents: 67
diff changeset
645 elapsed.user,
kono
parents: 67
diff changeset
646 (total->user == 0 ? 0 : elapsed.user / total->user) * 100);
kono
parents: 67
diff changeset
647 #endif /* HAVE_USER_TIME */
kono
parents: 67
diff changeset
648
kono
parents: 67
diff changeset
649 #ifdef HAVE_SYS_TIME
kono
parents: 67
diff changeset
650 /* Print system-mode time for this process. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651 fprintf (fp, "%7.2f (%3.0f%%)",
111
kono
parents: 67
diff changeset
652 elapsed.sys,
kono
parents: 67
diff changeset
653 (total->sys == 0 ? 0 : elapsed.sys / total->sys) * 100);
kono
parents: 67
diff changeset
654 #endif /* HAVE_SYS_TIME */
kono
parents: 67
diff changeset
655
kono
parents: 67
diff changeset
656 #ifdef HAVE_WALL_TIME
kono
parents: 67
diff changeset
657 /* Print wall clock time elapsed. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
658 fprintf (fp, "%7.2f (%3.0f%%)",
111
kono
parents: 67
diff changeset
659 elapsed.wall,
kono
parents: 67
diff changeset
660 (total->wall == 0 ? 0 : elapsed.wall / total->wall) * 100);
kono
parents: 67
diff changeset
661 #endif /* HAVE_WALL_TIME */
kono
parents: 67
diff changeset
662
kono
parents: 67
diff changeset
663 /* Print the amount of ggc memory allocated. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
664 fprintf (fp, "%8u kB (%3.0f%%)",
111
kono
parents: 67
diff changeset
665 (unsigned) (elapsed.ggc_mem >> 10),
kono
parents: 67
diff changeset
666 (total->ggc_mem == 0
kono
parents: 67
diff changeset
667 ? 0
kono
parents: 67
diff changeset
668 : (float) elapsed.ggc_mem / total->ggc_mem) * 100);
kono
parents: 67
diff changeset
669
kono
parents: 67
diff changeset
670 putc ('\n', fp);
kono
parents: 67
diff changeset
671 }
kono
parents: 67
diff changeset
672
kono
parents: 67
diff changeset
673 /* Return whether ELAPSED is all zero. */
kono
parents: 67
diff changeset
674
kono
parents: 67
diff changeset
675 bool
kono
parents: 67
diff changeset
676 timer::all_zero (const timevar_time_def &elapsed)
kono
parents: 67
diff changeset
677 {
kono
parents: 67
diff changeset
678 const double tiny = 5e-3;
kono
parents: 67
diff changeset
679 return (elapsed.user < tiny
kono
parents: 67
diff changeset
680 && elapsed.sys < tiny
kono
parents: 67
diff changeset
681 && elapsed.wall < tiny
kono
parents: 67
diff changeset
682 && elapsed.ggc_mem < GGC_MEM_BOUND);
kono
parents: 67
diff changeset
683 }
kono
parents: 67
diff changeset
684
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 /* Summarize timing variables to FP. The timing variable TV_TOTAL has
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 a special meaning -- it's considered to be the total elapsed time,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 for normalizing the others, and is displayed last. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 void
111
kono
parents: 67
diff changeset
690 timer::print (FILE *fp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 /* Only print stuff if we have some sort of time information. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 #if defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) || defined (HAVE_WALL_TIME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 unsigned int /* timevar_id_t */ id;
111
kono
parents: 67
diff changeset
695 const timevar_time_def *total = &m_timevars[TV_TOTAL].elapsed;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 struct timevar_time_def now;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 /* Update timing information in case we're calling this from GDB. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 if (fp == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 fp = stderr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 /* What time is it? */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 get_time (&now);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 /* If the stack isn't empty, attribute the current elapsed time to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 the old topmost element. */
111
kono
parents: 67
diff changeset
708 if (m_stack)
kono
parents: 67
diff changeset
709 timevar_accumulate (&m_stack->timevar->elapsed, &m_start_time, &now);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 /* Reset the start time; from now on, time is attributed to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 TIMEVAR. */
111
kono
parents: 67
diff changeset
713 m_start_time = now;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
715 fprintf (fp, "\n%-35s%16s%14s%14s%18s\n", "Time variable", "usr", "sys",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
716 "wall", "GGC");
111
kono
parents: 67
diff changeset
717 if (m_jit_client_items)
kono
parents: 67
diff changeset
718 fputs ("GCC items:\n", fp);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 {
111
kono
parents: 67
diff changeset
721 const timevar_def *tv = &m_timevars[(timevar_id_t) id];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 /* Don't print the total execution time here; that goes at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 end. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 if ((timevar_id_t) id == TV_TOTAL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 /* Don't print timing variables that were never used. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 if (!tv->used)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731
111
kono
parents: 67
diff changeset
732 bool any_children_with_time = false;
kono
parents: 67
diff changeset
733 if (tv->children)
kono
parents: 67
diff changeset
734 for (child_map_t::iterator i = tv->children->begin ();
kono
parents: 67
diff changeset
735 i != tv->children->end (); ++i)
kono
parents: 67
diff changeset
736 if (! all_zero ((*i).second))
kono
parents: 67
diff changeset
737 {
kono
parents: 67
diff changeset
738 any_children_with_time = true;
kono
parents: 67
diff changeset
739 break;
kono
parents: 67
diff changeset
740 }
kono
parents: 67
diff changeset
741
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 /* Don't print timing variables if we're going to get a row of
111
kono
parents: 67
diff changeset
743 zeroes. Unless there are children with non-zero time. */
kono
parents: 67
diff changeset
744 if (! any_children_with_time
kono
parents: 67
diff changeset
745 && all_zero (tv->elapsed))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747
111
kono
parents: 67
diff changeset
748 print_row (fp, total, tv->name, tv->elapsed);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749
111
kono
parents: 67
diff changeset
750 if (tv->children)
kono
parents: 67
diff changeset
751 for (child_map_t::iterator i = tv->children->begin ();
kono
parents: 67
diff changeset
752 i != tv->children->end (); ++i)
kono
parents: 67
diff changeset
753 {
kono
parents: 67
diff changeset
754 timevar_def *tv2 = (*i).first;
kono
parents: 67
diff changeset
755 /* Don't print timing variables if we're going to get a row of
kono
parents: 67
diff changeset
756 zeroes. */
kono
parents: 67
diff changeset
757 if (! all_zero ((*i).second))
kono
parents: 67
diff changeset
758 {
kono
parents: 67
diff changeset
759 char lname[256];
kono
parents: 67
diff changeset
760 snprintf (lname, 256, "`- %s", tv2->name);
kono
parents: 67
diff changeset
761 print_row (fp, total, lname, (*i).second);
kono
parents: 67
diff changeset
762 }
kono
parents: 67
diff changeset
763 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 }
111
kono
parents: 67
diff changeset
765 if (m_jit_client_items)
kono
parents: 67
diff changeset
766 m_jit_client_items->print (fp, total);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 /* Print total time. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
769 fprintf (fp, " %-35s:", "TOTAL");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 #ifdef HAVE_USER_TIME
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
771 fprintf (fp, "%7.2f ", total->user);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 #ifdef HAVE_SYS_TIME
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
774 fprintf (fp, "%8.2f ", total->sys);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 #ifdef HAVE_WALL_TIME
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
777 fprintf (fp, "%8.2f ", total->wall);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 #endif
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
779 fprintf (fp, "%9u kB\n", (unsigned) (total->ggc_mem >> 10));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780
111
kono
parents: 67
diff changeset
781 if (CHECKING_P || flag_checking)
kono
parents: 67
diff changeset
782 fprintf (fp, "Extra diagnostic checks enabled; compiler may run slowly.\n");
kono
parents: 67
diff changeset
783 if (CHECKING_P)
kono
parents: 67
diff changeset
784 fprintf (fp, "Configure with --enable-checking=release to disable checks.\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 #ifndef ENABLE_ASSERT_CHECKING
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 fprintf (fp, "Internal checks disabled; compiler is not suited for release.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 fprintf (fp, "Configure with --enable-checking=release to enable checks.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 #endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 || defined (HAVE_WALL_TIME) */
111
kono
parents: 67
diff changeset
792
kono
parents: 67
diff changeset
793 validate_phases (fp);
kono
parents: 67
diff changeset
794 }
kono
parents: 67
diff changeset
795
kono
parents: 67
diff changeset
796 /* Get the name of the topmost item. For use by jit for validating
kono
parents: 67
diff changeset
797 inputs to gcc_jit_timer_pop. */
kono
parents: 67
diff changeset
798 const char *
kono
parents: 67
diff changeset
799 timer::get_topmost_item_name () const
kono
parents: 67
diff changeset
800 {
kono
parents: 67
diff changeset
801 if (m_stack)
kono
parents: 67
diff changeset
802 return m_stack->timevar->name;
kono
parents: 67
diff changeset
803 else
kono
parents: 67
diff changeset
804 return NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 /* Prints a message to stderr stating that time elapsed in STR is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 TOTAL (given in microseconds). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 print_time (const char *str, long total)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 long all_time = get_run_time ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 fprintf (stderr,
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
815 "time in %s: %ld.%06ld (%ld%%)\n",
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816 str, total / 1000000, total % 1000000,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 all_time == 0 ? 0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 : (long) (((100.0 * (double) total) / (double) all_time) + .5));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 }