1989-06-12 15:22:14 +00:00
|
|
|
/*
|
|
|
|
* clock - determine the processor time used
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-06-12 15:22:14 +00:00
|
|
|
|
|
|
|
#include <time.h>
|
1989-12-18 15:33:48 +00:00
|
|
|
|
|
|
|
#if defined(__BSD4_2)
|
|
|
|
|
|
|
|
struct timeval {
|
|
|
|
long tv_sec; /* seconds */
|
|
|
|
long tv_usec; /* and microseconds */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RUSAGE_SELF 0
|
|
|
|
#define RUSAGE_CHILDREN -1
|
|
|
|
|
|
|
|
struct rusage {
|
|
|
|
struct timeval ru_utime; /* user time used */
|
|
|
|
struct timeval ru_stime; /* system time used */
|
|
|
|
long ru_maxrss;
|
|
|
|
long ru_ixrss; /* integral shared memory size */
|
|
|
|
long ru_idrss; /* integral unshared data size */
|
|
|
|
long ru_isrss; /* integral unshared stack size */
|
|
|
|
long ru_minflt; /* page reclaims */
|
|
|
|
long ru_majflt; /* page faults */
|
|
|
|
long ru_nswap; /* swaps */
|
|
|
|
long ru_inblock; /* block input operations */
|
|
|
|
long ru_oublock; /* block output operations */
|
|
|
|
long ru_msgsnd; /* messages sent */
|
|
|
|
long ru_msgrcv; /* messages received */
|
|
|
|
long ru_nsignals; /* signals received */
|
|
|
|
long ru_nvcsw; /* voluntary context switches */
|
|
|
|
long ru_nivcsw; /* involuntary context switches */
|
|
|
|
};
|
|
|
|
|
1990-01-22 13:08:36 +00:00
|
|
|
void _getrusage(int who, struct rusage *rusage);
|
1989-12-18 15:33:48 +00:00
|
|
|
|
|
|
|
#elif defined(_POSIX_SOURCE) || defined(__USG)
|
|
|
|
|
|
|
|
struct tms {
|
|
|
|
time_t tms_utime; /* user time */
|
|
|
|
time_t tms_stime; /* system time */
|
|
|
|
time_t tms_cutime; /* user time, children */
|
|
|
|
time_t tms_cstime; /* system time, children */
|
|
|
|
};
|
|
|
|
|
1990-01-22 13:08:36 +00:00
|
|
|
long _times(struct tms *buffer);
|
1989-12-18 15:33:48 +00:00
|
|
|
|
|
|
|
#else /* Version 7 UNIX */
|
|
|
|
|
|
|
|
struct tbuffer {
|
|
|
|
long proc_user_time;
|
|
|
|
long proc_system_time;
|
|
|
|
long child_user_time;
|
|
|
|
long child_system_time;
|
|
|
|
};
|
|
|
|
|
1990-01-22 13:08:36 +00:00
|
|
|
long _times(struct tbuffer *buffer);
|
1989-12-18 15:33:48 +00:00
|
|
|
|
|
|
|
#endif
|
1989-06-12 15:22:14 +00:00
|
|
|
|
|
|
|
clock_t
|
|
|
|
clock(void)
|
|
|
|
{
|
1989-12-18 15:33:48 +00:00
|
|
|
#if defined(__BSD4_2)
|
1989-06-12 15:22:14 +00:00
|
|
|
struct rusage rusage;
|
|
|
|
|
1990-01-22 13:08:36 +00:00
|
|
|
_getrusage(RUSAGE_SELF, &rusage);
|
1989-06-12 15:22:14 +00:00
|
|
|
|
1989-12-18 15:33:48 +00:00
|
|
|
return (((unsigned long)rusage.ru_utime.tv_sec * CLOCKS_PER_SEC)
|
|
|
|
+ rusage.ru_utime.tv_usec);
|
|
|
|
#elif defined(_POSIX_SOURCE) || defined(__USG)
|
|
|
|
struct tms tms;
|
|
|
|
|
1990-01-22 13:08:36 +00:00
|
|
|
_times(&tms);
|
1989-12-18 15:33:48 +00:00
|
|
|
/* Assume that time_t can be converted to clock_t for Sys5 */
|
|
|
|
return tms.tms_utime;
|
|
|
|
#else
|
|
|
|
struct tbuffer tbuffer;
|
|
|
|
|
1990-01-22 13:08:36 +00:00
|
|
|
_times(&tbuffer);
|
1989-12-18 15:33:48 +00:00
|
|
|
return tbuffer.proc_user_time;
|
|
|
|
#endif
|
1989-06-12 15:22:14 +00:00
|
|
|
}
|