diff options
author | Jun FURUSE / 古瀬 淳 <jun.furuse@gmail.com> | 2008-01-28 05:29:20 +0000 |
---|---|---|
committer | Jun FURUSE / 古瀬 淳 <jun.furuse@gmail.com> | 2008-01-28 05:29:20 +0000 |
commit | 3f4a98da0fbf8a87c674d6737d8c6cec7e8567e5 (patch) | |
tree | f5aa13505824d708414ece1f00219b811315c44a /byterun/sys.c | |
parent | 30f3fa2c5bc27f8c59930741aa1b6dd5a34a6b40 (diff) | |
download | ocaml-gcaml3090.tar.gz |
3.09.1 updategcaml3090
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/gcaml3090@8792 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
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 } |