Get the time spent in the process.
Copyright (C) 1992 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program 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 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
/* Prefer gettimeofday to ftime to times. */
#if HAVE_GETTIMEOFDAY || HAVE_FTIME
#if HAVE_TIME_H && (HAVE_SYS_TIME_AND_TIME_H || ! HAVE_GETTIMEOFDAY)
/* We use a macro to protect this because times really returns clock_t
and on some systems, such as Ultrix 4.0, clock_t is int. We don't
leave it out entirely because on some systems, such as System III,
the declaration is necessary for correct compilation. */
#endif /* TIMES_DECLARATION_OK */
#define HAVE_SC_CLK_TCK 1
#define HAVE_SC_CLK_TCK 0
/* TIMES_TICK may have been set in policy.h, or we may be able to get
it using sysconf. If neither is the case, try to find a useful
definition from the system header files. */
#if TIMES_TICK == 0 && (! HAVE_SYSCONF || ! HAVE_SC_CLK_TCK)
#define TIMES_TICK CLK_TCK
#else /* ! defined (CLK_TCK) */
#endif /* defined (HZ) */
#endif /* ! defined (CLK_TCK) */
#endif /* TIMES_TICK == 0 && (! HAVE_SYSCONF || ! HAVE_SC_CLK_TCK) */
/* Get the time in seconds and microseconds; this need only work
within the process when called from the system independent code.
It is also called by ixsysdep_time. */
ixsysdep_process_time (pimicros
)
(void) gettimeofday (&stime
, &stz
);
*pimicros
= (long) stime
.tv_usec
;
return (long) stime
.tv_sec
;
#endif /* HAVE_GETTIMEOFDAY */
static struct timeb slast
;
/* On some systems, such as SCO 3.2.2, ftime can go backwards in
time. If we detect this, we switch to using time. */
&& (stime
.time
< slast
.time
|| (stime
.time
== slast
.time
&&
stime
.millitm
< slast
.millitm
)))
*pimicros
= (long) stime
.millitm
* (long) 1000;
return (long) stime
.time
;
return (long) time ((time_t *) NULL
);
#if HAVE_SYSCONF && HAVE_SC_CLK_TCK
itick
= (int) sysconf (_SC_CLK_TCK
);
#else /* ! HAVE_SYSCONF || ! HAVE_SC_CLK_TCK */
itick
= (int) strtol (z
, (char **) NULL
, 10);
/* If we really couldn't get anything, just use 60. */
#endif /* ! HAVE_SYSCONF || ! HAVE_SC_CLK_TCK */
#else /* TIMES_TICK != 0 */
#endif /* TIMES_TICK == 0 */
*pimicros
= (i
% (long) itick
) * ((long) 1000000 / (long) itick
);
#if ! HAVE_GETTIMEOFDAY && ! HAVE_FTIME && ! HAVE_TIMES
return (long) time ((time_t *) NULL
);
#endif /* ! HAVE_GETTIMEOFDAY && ! HAVE_FTIME && ! HAVE_TIMES */