forked from ldmud/ldmud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-rusage.h
88 lines (69 loc) · 2.32 KB
/
my-rusage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef MY_RUSAGE_H__
#define MY_RUSAGE_H__
/*------------------------------------------------------------------
* Portable rusage related definitions and prototypes.
*
* Use this file instead of <rusage.h> and others.
*------------------------------------------------------------------
*/
#include "driver.h"
#ifdef GETRUSAGE_VIA_SYSCALL /* hpux */
# include <sys/syscall.h>
# define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
#endif
#if defined(HAVE_GETRUSAGE)
# if defined(RUSAGE_USEC) || defined(__hpux__)
# define RUSAGE_TIME(t) ( (t).tv_sec * 1000 + (t).tv_usec / 1000 )
# else
# if defined(solaris)
/* the header files are POSIX, but the function is BSD :-( */
# define RUSAGE_TIME(t) ( (t).tv_sec * 1000 + (t).tv_nsec / 1000 )
# else
# define RUSAGE_TIME(t) ( (t).tv_sec * 1000 + (t).tv_nsec / 1000000 )
# endif /* ! solaris */
# endif /* RUSAGE_USEC */
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h> /* Needed on some systems for sys/resource.h */
# endif
# ifdef HAVE_SYS_RUSAGE_H /* solaris */
# include <sys/rusage.h>
# endif /* HAVE_SYS_RUSAGE */
# include <sys/resource.h>
# ifdef sun
extern int getpagesize();
# endif
# if defined(sun)
extern int getrusage (int, struct rusage *);
# endif
#else /* !HAVE_GETRUSAGE */
# undef GETRUSAGE_RESTRICTED
# define GETRUSAGE_RESTRICTED
# define RUSAGE_SELF 0
# if defined(POSIX) && (HAVE_SYSCONF)
/* there is actually a system that pretends to be POSIX, prototypes sysconf,
* but does not have it.
*/
# define TIMES_FREQ sysconf(_SC_CLK_TCK)
# else /* !POSIX */
# include <sys/time.h>
# include <sys/times.h>
# include <time.h>
# define TIMES_FREQ CLK_TCK
# ifndef CLK_TCK
# define CLK_TCK CLOCKS_PER_SEC
# ifndef CLOCKS_PER_SEC
# define CLOCKS_PER_SEC 60
# endif /* !CLOCKS_PER_SEC */
# endif /* !CLK_TCK */
# endif /* !POSIX */
# define RUSAGE_TIME(t) ( (t) * 1000 / TIMES_FREQ )
struct rusage {
long ru_utime, ru_stime;
};
extern int getrusage(int, struct rusage*);
/* Implemented in port.c */
#endif /* HAVE_GETRUSAGE */
#ifndef RUSAGE_SELF
# define RUSAGE_SELF 0
#endif
#endif /* MY_RUSAGE_H__ */