diff options
Diffstat (limited to 'byterun/sys.c')
-rw-r--r-- | byterun/sys.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/byterun/sys.c b/byterun/sys.c index 2dd20312ac..7e130c065d 100644 --- a/byterun/sys.c +++ b/byterun/sys.c @@ -34,6 +34,10 @@ #ifdef HAS_TIMES #include <sys/times.h> #endif +#ifdef HAS_GETRUSAGE +#include <sys/time.h> +#include <sys/resource.h> +#endif #ifdef HAS_GETTIMEOFDAY #include <sys/time.h> #endif @@ -247,20 +251,28 @@ CAMLprim value caml_sys_system_command(value command) CAMLprim value caml_sys_time(value unit) { -#ifdef HAS_TIMES -#ifndef CLK_TCK -#ifdef HZ -#define CLK_TCK HZ -#else -#define CLK_TCK 60 -#endif -#endif - struct tms t; - times(&t); - return caml_copy_double((double)(t.tms_utime + t.tms_stime) / CLK_TCK); +#ifdef HAS_GETRUSAGE + struct rusage ru; + + getrusage (RUSAGE_SELF, &ru); + return caml_copy_double (ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1e6 + + ru.ru_stime.tv_sec + ru.ru_stime.tv_usec / 1e6); #else - /* clock() is standard ANSI C */ - return caml_copy_double((double)clock() / CLOCKS_PER_SEC); + #ifdef HAS_TIMES + #ifndef CLK_TCK + #ifdef HZ + #define CLK_TCK HZ + #else + #define CLK_TCK 60 + #endif + #endif + struct tms t; + times(&t); + return caml_copy_double((double)(t.tms_utime + t.tms_stime) / CLK_TCK); + #else + /* clock() is standard ANSI C */ + return caml_copy_double((double)clock() / CLOCKS_PER_SEC); + #endif #endif } |