This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: optimizations to timevar.c
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: optimizations to timevar.c
- From: Alex Samuel <samuel at codesourcery dot com>
- Date: Thu, 27 Apr 2000 23:03:57 -0700 (PDT)
- Organization: CodeSourcery, LLC
This patch incorporates some improvements to timevar.c suggested by
Richard Henderson. External timevar functions now return immediately
if quiet_flag is set, since timing information is not printed in that
case. Timing variables have a used flag, so that they are not printed
if they are never used. Popped-off timevar_stack_def elements are
kept in a list for reuse.
OK to commit?
* Makefile.in (timevar.o): Depend on flags.h.
* timevar.c (unused_stack_instances): New variable.
(timevar_push): Take a timevar_stack_def from
unused_stack_instances if available.
(timevar_pop): Push the popped timevar_stack_def onto
unused_stack_instances.
(TIMEVAR_ENABLE): New macro.
(timevar_def): Make standalone a 1-bit field. Add field used.
(get_time): Rename parameter to now. Return after clearing it if
not TIMEVAR_ENABLE.
(init_timevar): Do nothing if not TIMEVAR_ENABLE.
(timevar_pop): Likewise.
(timevar_stop): Likewise.
(timevar_push): Likewise. Mark the timing variable as used.
(timevar_start): Likewise.
(timevar_print): Do nothing if not TIMEVAR_ENABLE. Don't print
timevars that were never used.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/Makefile.in,v
retrieving revision 1.427
diff -c -p -r1.427 Makefile.in
*** Makefile.in 2000/04/28 00:59:38 1.427
--- Makefile.in 2000/04/28 06:04:17
*************** lists.o: lists.c $(CONFIG_H) system.h to
*** 1658,1664 ****
bb-reorder.o : bb-reorder.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
insn-config.h $(BASIC_BLOCK_H) $(REGS_H) hard-reg-set.h output.h toplev.h \
$(RECOG_H) insn-flags.h function.h except.h $(EXPR_H)
! timevar.o : timevar.c $(CONFIG_H) system.h timevar.h timevar.def
timevar.h : timevar.def
regrename.o : regrename.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
--- 1658,1664 ----
bb-reorder.o : bb-reorder.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
insn-config.h $(BASIC_BLOCK_H) $(REGS_H) hard-reg-set.h output.h toplev.h \
$(RECOG_H) insn-flags.h function.h except.h $(EXPR_H)
! timevar.o : timevar.c $(CONFIG_H) system.h timevar.h timevar.def flags.h
timevar.h : timevar.def
regrename.o : regrename.c $(CONFIG_H) system.h $(RTL_H) $(TREE_H) flags.h \
Index: timevar.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/timevar.c,v
retrieving revision 1.1
diff -c -p -r1.1 timevar.c
*** timevar.c 2000/04/28 00:59:39 1.1
--- timevar.c 2000/04/28 06:04:17
***************
*** 26,35 ****
--- 26,39 ----
# include <sys/times.h>
#endif
+ #include "flags.h"
#include "timevar.h"
/* See timevar.h for an explanation of timing variables. */
+ /* This macro evaluates to non-zero if timing variables are enabled. */
+ #define TIMEVAR_ENABLE (!quiet_flag)
+
/* A timing variable. */
struct timevar_def
*************** struct timevar_def
*** 41,52 ****
using timevar_start, this contains the start time. */
struct timevar_time_def start_time;
/* Non-zero if this timing variable is running as a standalone
timer. */
! int standalone;
! /* The name of this timing variable. */
! const char *name;
};
/* An element on the timing stack. Elapsed time is attributed to the
--- 45,60 ----
using timevar_start, this contains the start time. */
struct timevar_time_def start_time;
+ /* The name of this timing variable. */
+ const char *name;
+
/* Non-zero if this timing variable is running as a standalone
timer. */
! unsigned standalone : 1;
! /* Non-zero if this timing variable was ever started or pushed onto
! the timing stack. */
! unsigned used : 1;
};
/* An element on the timing stack. Elapsed time is attributed to the
*************** static struct timevar_def timevars[TIMEV
*** 68,73 ****
--- 76,85 ----
/* The top of the timing stack. */
static struct timevar_stack_def *stack;
+ /* A list of unused (i.e. allocated and subsequently popped)
+ timevar_stack_def instances. */
+ static struct timevar_stack_def *unused_stack_instances;
+
/* The time at which the topmost element on the timing stack was
pushed. Time elapsed since then is attributed to the topmost
element. */
*************** static void timevar_accumulate
*** 86,104 ****
HAVA_WALL_TIME macros. */
static void
! get_time (time)
! struct timevar_time_def *time;
{
! time->user = 0;
! time->sys = 0;
! time->wall = 0;
#ifdef __BEOS__
/* Nothing. */
#else /* not BeOS */
#if defined (_WIN32) && !defined (__CYGWIN__)
if (clock () >= 0)
! time->user = clock () * 1000;
#define HAVE_USER_TIME
#else /* not _WIN32 */
--- 98,119 ----
HAVA_WALL_TIME macros. */
static void
! get_time (now)
! struct timevar_time_def *now;
{
! now->user = 0;
! now->sys = 0;
! now->wall = 0;
!
! if (!TIMEVAR_ENABLE)
! return;
#ifdef __BEOS__
/* Nothing. */
#else /* not BeOS */
#if defined (_WIN32) && !defined (__CYGWIN__)
if (clock () >= 0)
! now->user = clock () * 1000;
#define HAVE_USER_TIME
#else /* not _WIN32 */
*************** get_time (time)
*** 108,116 ****
struct tms tms;
if (tick == 0)
tick = 1000000 / sysconf (_SC_CLK_TCK);
! time->wall = times (&tms) * tick;
! time->user = tms.tms_utime * tick;
! time->sys = tms.tms_stime * tick;
}
#define HAVE_USER_TIME
#define HAVE_SYS_TIME
--- 123,131 ----
struct tms tms;
if (tick == 0)
tick = 1000000 / sysconf (_SC_CLK_TCK);
! now->wall = times (&tms) * tick;
! now->user = tms.tms_utime * tick;
! now->sys = tms.tms_stime * tick;
}
#define HAVE_USER_TIME
#define HAVE_SYS_TIME
*************** get_time (time)
*** 129,137 ****
# define TICKS_PER_SECOND HZ /* traditional UNIX */
# endif
# endif
! time->wall = times (&tms) * (1000000 / TICKS_PER_SECOND);
! time->user = tms.tms_utime * (1000000 / TICKS_PER_SECOND);
! time->sys = tms.tms_stime * (1000000 / TICKS_PER_SECOND);
}
#define HAVE_USER_TIME
#define HAVE_SYS_TIME
--- 144,152 ----
# define TICKS_PER_SECOND HZ /* traditional UNIX */
# endif
# endif
! now->wall = times (&tms) * (1000000 / TICKS_PER_SECOND);
! now->user = tms.tms_utime * (1000000 / TICKS_PER_SECOND);
! now->sys = tms.tms_stime * (1000000 / TICKS_PER_SECOND);
}
#define HAVE_USER_TIME
#define HAVE_SYS_TIME
*************** get_time (time)
*** 142,150 ****
{
struct rusage rusage;
getrusage (0, &rusage);
! time->user
= rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec;
! time->sys
= rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec;
}
#define HAVE_USER_TIME
--- 157,165 ----
{
struct rusage rusage;
getrusage (0, &rusage);
! now->user
= rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec;
! now->sys
= rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec;
}
#define HAVE_USER_TIME
*************** get_time (time)
*** 159,167 ****
int child_user_time;
int child_system_time;
} vms_times;
! time->wall = times ((void *) &vms_times) * 10000;
! time->user = vms_times.proc_user_time * 10000;
! time->sys = vms_times.proc_system_time * 10000;
}
#define HAVE_USER_TIME
#define HAVE_SYS_TIME
--- 174,182 ----
int child_user_time;
int child_system_time;
} vms_times;
! now->wall = times ((void *) &vms_times) * 10000;
! now->user = vms_times.proc_user_time * 10000;
! now->sys = vms_times.proc_system_time * 10000;
}
#define HAVE_USER_TIME
#define HAVE_SYS_TIME
*************** timevar_accumulate (timer, start_time, s
*** 204,209 ****
--- 219,227 ----
void
init_timevar (void)
{
+ if (!TIMEVAR_ENABLE)
+ return;
+
/* Zero all elapsed times. */
memset ((void *) timevars, 0, sizeof (timevars));
*************** timevar_push (timevar)
*** 229,234 ****
--- 247,258 ----
struct timevar_stack_def *context;
struct timevar_time_def now;
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* Mark this timing variable as used. */
+ tv->used = 1;
+
/* Can't push a standalone timer. */
if (tv->standalone)
abort ();
*************** timevar_push (timevar)
*** 245,253 ****
TIMEVAR. */
start_time = now;
! /* Create a new stack element, and push it. */
! context = (struct timevar_stack_def *)
! xmalloc (sizeof (struct timevar_stack_def));
context->timevar = tv;
context->next = stack;
stack = context;
--- 269,286 ----
TIMEVAR. */
start_time = now;
! /* See if we have a previously-allocated stack instance. If so,
! take it off the list. If not, malloc a new one. */
! if (unused_stack_instances != NULL)
! {
! context = unused_stack_instances;
! unused_stack_instances = unused_stack_instances->next;
! }
! else
! context = (struct timevar_stack_def *)
! xmalloc (sizeof (struct timevar_stack_def));
!
! /* Fill it in and put it on the stack. */
context->timevar = tv;
context->next = stack;
stack = context;
*************** timevar_pop (timevar)
*** 264,270 ****
timevar_id_t timevar;
{
struct timevar_time_def now;
! struct timevar_stack_def *next = stack->next;
if (&timevars[timevar] != stack->timevar)
abort ();
--- 297,306 ----
timevar_id_t timevar;
{
struct timevar_time_def now;
! struct timevar_stack_def *popped = stack;
!
! if (!TIMEVAR_ENABLE)
! return;
if (&timevars[timevar] != stack->timevar)
abort ();
*************** timevar_pop (timevar)
*** 273,287 ****
get_time (&now);
/* Attribute the elapsed time to the element we're popping. */
! timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
/* Reset the start time; from now on, time is attributed to the
element just exposed on the stack. */
start_time = now;
! /* Remove the stack element. */
! free (stack);
! stack = next;
}
/* Start timing TIMEVAR independently of the timing stack. Elapsed
--- 309,327 ----
get_time (&now);
/* Attribute the elapsed time to the element we're popping. */
! timevar_accumulate (&popped->timevar->elapsed, &start_time, &now);
/* Reset the start time; from now on, time is attributed to the
element just exposed on the stack. */
start_time = now;
! /* Take the item off the stack. */
! stack = stack->next;
!
! /* Don't delete the stack element; instead, add it to the list of
! unused elements for later use. */
! popped->next = unused_stack_instances;
! unused_stack_instances = popped;
}
/* Start timing TIMEVAR independently of the timing stack. Elapsed
*************** timevar_start (timevar)
*** 294,299 ****
--- 334,345 ----
{
struct timevar_def *tv = &timevars[timevar];
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* Mark this timing variable as used. */
+ tv->used = 1;
+
/* Don't allow the same timing variable to be started more than
once. */
if (tv->standalone)
*************** timevar_stop (timevar)
*** 313,318 ****
--- 359,367 ----
struct timevar_def *tv = &timevars[timevar];
struct timevar_time_def now;
+ if (!TIMEVAR_ENABLE)
+ return;
+
/* TIMEVAR must have been started via timevar_start. */
if (!tv->standalone)
abort ();
*************** timevar_print (fp)
*** 357,362 ****
--- 406,414 ----
timevar_id_t id;
struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed;
+ if (!TIMEVAR_ENABLE)
+ return;
+
fprintf (fp, "\nExecution times (seconds)\n");
for (id = 0; id < TIMEVAR_LAST; ++id)
{
*************** timevar_print (fp)
*** 367,372 ****
--- 419,428 ----
if (id == TV_TOTAL)
continue;
+ /* Don't print timing variables that were never used. */
+ if (!tv->used)
+ continue;
+
/* The timing variable name. */
fprintf (fp, " %-22s:", tv->name);
*************** print_time (str, total)
*** 445,448 ****
all_time == 0 ? 0
: (long) (((100.0 * (double) total) / (double) all_time) + .5));
}
-
--- 501,503 ----