/* Timing variables for measuring compiler performance.
- Copyright (C) 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2003, 2004, 2005, 2007, 2010
+ Free Software Foundation, Inc.
Contributed by Alex Samuel <samuel@codesourcery.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
for more details.
You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA. */
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
-#ifdef HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-#include "coretypes.h"
-#include "tm.h"
-#include "intl.h"
-#include "rtl.h"
-#include "toplev.h"
+#include "timevar.h"
#ifndef HAVE_CLOCK_T
typedef int clock_t;
#define CLOCKS_TO_MSEC (1 / (double)CLOCKS_PER_SEC)
#endif
-#include "flags.h"
-#include "timevar.h"
+/* True if timevars should be used. In GCC, this happens with
+ the -ftime-report flag. */
bool timevar_enable;
struct timevar_stack_def *popped = stack;
gcc_assert (&timevars[timevar] == stack->timevar);
-
+
/* What time is it? */
get_time (&now);
/* TIMEVAR must have been started via timevar_start. */
gcc_assert (tv->standalone);
+ tv->standalone = 0; /* Enable a restart. */
+
+ get_time (&now);
+ timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
+}
+
+
+/* Conditionally start timing TIMEVAR independently of the timing stack.
+ If the timer is already running, leave it running and return true.
+ Otherwise, start the timer and return false.
+ Elapsed time until the corresponding timevar_cond_stop
+ is called for the same timing variable is attributed to TIMEVAR. */
+
+bool
+timevar_cond_start (timevar_id_t timevar)
+{
+ struct timevar_def *tv = &timevars[timevar];
+
+ if (!timevar_enable)
+ return false;
+
+ /* Mark this timing variable as used. */
+ tv->used = 1;
+
+ if (tv->standalone)
+ return true; /* The timevar is already running. */
+
+ /* Don't allow the same timing variable
+ to be unconditionally started more than once. */
+ tv->standalone = 1;
+
+ get_time (&tv->start_time);
+ return false; /* The timevar was not already running. */
+}
+
+/* Conditionally stop timing TIMEVAR. The RUNNING parameter must come
+ from the return value of a dynamically matching timevar_cond_start.
+ If the timer had already been RUNNING, do nothing. Otherwise, time
+ elapsed since timevar_cond_start was called is attributed to it. */
+
+void
+timevar_cond_stop (timevar_id_t timevar, bool running)
+{
+ struct timevar_def *tv;
+ struct timevar_time_def now;
+
+ if (!timevar_enable || running)
+ return;
+
+ tv = &timevars[timevar];
+
+ /* TIMEVAR must have been started via timevar_cond_start. */
+ gcc_assert (tv->standalone);
+ tv->standalone = 0; /* Enable a restart. */
get_time (&now);
timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
}
+
/* Summarize timing variables to FP. The timing variable TV_TOTAL has
a special meaning -- it's considered to be the total elapsed time,
for normalizing the others, and is displayed last. */
TIMEVAR. */
start_time = now;
- fputs (_("\nExecution times (seconds)\n"), fp);
+ fputs ("\nExecution times (seconds)\n", fp);
for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
{
struct timevar_def *tv = &timevars[(timevar_id_t) id];
continue;
/* The timing variable name. */
- fprintf (fp, " %-22s:", tv->name);
+ fprintf (fp, " %-24s:", tv->name);
#ifdef HAVE_USER_TIME
/* Print user-mode time for this process. */
}
/* Print total time. */
- fputs (_(" TOTAL :"), fp);
+ fputs (" TOTAL :", fp);
#ifdef HAVE_USER_TIME
fprintf (fp, "%7.2f ", total->user);
#endif
{
long all_time = get_run_time ();
fprintf (stderr,
- _("time in %s: %ld.%06ld (%ld%%)\n"),
+ "time in %s: %ld.%06ld (%ld%%)\n",
str, total / 1000000, total % 1000000,
all_time == 0 ? 0
: (long) (((100.0 * (double) total) / (double) all_time) + .5));