diff options
Diffstat (limited to 'gcc/timevar.c')
-rw-r--r-- | gcc/timevar.c | 85 |
1 files changed, 75 insertions, 10 deletions
diff --git a/gcc/timevar.c b/gcc/timevar.c index 1b5d2443c19..84d9a2af80b 100644 --- a/gcc/timevar.c +++ b/gcc/timevar.c @@ -27,6 +27,17 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif + +/* APPLE LOCAL begin Mach time */ +#ifdef HAVE_MACH_MACH_TIME_H +#include <mach/mach_time.h> +#define HAVE_MACH_TIME 1 +static double timeBaseRatio; +static struct mach_timebase_info tbase; +#else +#define HAVE_MACH_TIME 0 +#endif +/* APPLE LOCAL end Mach time */ #include "coretypes.h" #include "tm.h" #include "intl.h" @@ -69,6 +80,33 @@ struct tms /* Prefer times to getrusage to clock (each gives successively less information). */ +/* APPLE LOCAL begin Mach time */ +/* On Darwin, prefer getrusage, plus Mach absolute time for the wall + clock time. Use PPC intrinsics if possible. */ +#if defined(__APPLE__) && defined(__POWERPC__) && HAVE_MACH_TIME +#if __POWERPC__ +# include "../more-hdrs/ppc_intrinsics.h" +# define HAVE_WALL_TIME +# define USE_PPC_INTRINSICS +inline double ppc_intrinsic_time() +{ + unsigned long hi, lo; + do + { + hi = __mftbu(); + lo = __mftb(); + } while (hi != __mftbu()); + return (hi * 0x100000000ull + lo) * timeBaseRatio; +} +#endif /* __POWERPC__ */ +#elif HAVE_MACH_TIME +# define USE_GETRUSAGE +# define USE_MACH_TIME +# define HAVE_USER_TIME +# define HAVE_SYS_TIME +# define HAVE_WALL_TIME +# else +/* APPLE LOCAL end Mach time */ #ifdef HAVE_TIMES # if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES extern clock_t times (struct tms *); @@ -95,6 +133,8 @@ struct tms #endif #endif #endif +/* APPLE LOCAL Mach time */ +#endif /* HAVE_MACH_TIME */ /* libc is very likely to have snuck a call to sysconf() into one of the underlying constants, and that can be very slow, so we have to @@ -203,6 +243,14 @@ get_time (struct timevar_time_def *now) #ifdef USE_CLOCK now->user = clock () * clocks_to_msec; #endif + /* APPLE LOCAL begin Mach time */ +#ifdef USE_MACH_TIME + now->wall = mach_absolute_time() * timeBaseRatio; +#endif +#ifdef USE_PPC_INTRINSICS + now->wall = ppc_intrinsic_time(); +#endif + /* APPLE LOCAL end Mach time */ } } @@ -240,6 +288,12 @@ timevar_init (void) #ifdef USE_CLOCK clocks_to_msec = CLOCKS_TO_MSEC; #endif + /* APPLE LOCAL begin Mach time */ +#if defined(USE_MACH_TIME) || defined(USE_PPC_INTRINSICS) + mach_timebase_info(&tbase); + timeBaseRatio = ((double) tbase.numer / (double) tbase.denom) * 1e-9; +#endif + /* APPLE LOCAL end Mach time */ } /* Push TIMEVAR onto the timing stack. No further elapsed time is @@ -489,22 +543,33 @@ timevar_print (FILE *fp) /* Print total time. */ fputs (_(" TOTAL :"), fp); #ifdef HAVE_USER_TIME - fprintf (fp, "%7.2f ", total->user); -#endif + /* APPLE LOCAL time formatting */ + fprintf (fp, "%7.2f", total->user); +#endif #ifdef HAVE_SYS_TIME - fprintf (fp, "%7.2f ", total->sys); + /* APPLE LOCAL time formatting */ + fprintf (fp, " %7.2f", total->sys); #endif #ifdef HAVE_WALL_TIME - fprintf (fp, "%7.2f\n", total->wall); + /* APPLE LOCAL time formatting */ + fprintf (fp, " %7.2f", total->wall); #endif + /* APPLE LOCAL time formatting */ + putc ('\n', fp); + +#endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) + || defined (HAVE_WALL_TIME) */ +} -#ifdef ENABLE_CHECKING - fprintf (fp, "Extra diagnostic checks enabled; compiler may run slowly.\n"); - fprintf (fp, "Configure with --disable-checking to disable checks.\n"); -#endif +/* Returns time (user + system) used so far by the compiler process, + in microseconds. */ -#endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) - || defined (HAVE_WALL_TIME) */ +long +get_run_time () +{ + struct timevar_time_def total_elapsed; + timevar_get (TV_TOTAL, &total_elapsed); + return total_elapsed.user + total_elapsed.sys; } /* Prints a message to stderr stating that time elapsed in STR is |