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