/* _lib7_Time_gettime : Void -> (int32.Int * int * int32.Int * int * int32.Int * int) * * Return this process's CPU time consumption * so far, broken down as: * User-mode seconds and microseconds. * Kernel-mode seconds and microseconds. * Garbage collection seconds and microseconds. * used by this process so far. */ lib7_val_t _lib7_Time_gettime (lib7_state_t *lib7_state, lib7_val_t arg) { Time_t usr; /* User-mode time consumption as reported by os. */ Time_t sys; /* Kernel-mode time consumption as reported by os. */ lib7_val_t usr_seconds; lib7_val_t sys_seconds; lib7_val_t gc_seconds; lib7_val_t result; /* For result 6-vector. */ vproc_state_t *vsp = lib7_state->lib7_vproc; /* On posix: get_cpu_time() def in src/runtime/main/unix-timers.c */ /* On win32: get_cpu_time() def in src/runtime/main/win32-timers.c */ get_cpu_time (&usr, &sys); INT32_ALLOC (lib7_state, usr_seconds, usr.seconds ); INT32_ALLOC (lib7_state, sys_seconds, sys.seconds ); INT32_ALLOC (lib7_state, gc_seconds, vsp->vp_gcTime->seconds); REC_ALLOC6 (lib7_state, result, usr_seconds, INT_CtoLib7(usr.uSeconds), sys_seconds, INT_CtoLib7(sys.uSeconds), gc_seconds, INT_CtoLib7(vsp->vp_gcTime->uSeconds) ); return result; }
/* _lib7_Date_mktime : (Int, Int, Int, Int, Int, Int, Int, Int, Int) * -> int32::Int * * This takes a 9-tuple with the fields: tm_sec, tm_min, tm_hour, tm_mday, * tm_mon, tm_year, tm_wday, tm_yday, tm_isdst, and returns the corresponding * localtime value (in seconds). */ lib7_val_t _lib7_Date_mktime (lib7_state_t *lib7_state, lib7_val_t arg) { struct tm tm; time_t t; tm.tm_sec = REC_SELINT(arg, 0); tm.tm_min = REC_SELINT(arg, 1); tm.tm_hour = REC_SELINT(arg, 2); tm.tm_mday = REC_SELINT(arg, 3); tm.tm_mon = REC_SELINT(arg, 4); tm.tm_year = REC_SELINT(arg, 5); /* tm.tm_wday = REC_SELINT(arg, 6); */ /* ignored by mktime */ /* tm.tm_yday = REC_SELINT(arg, 7); */ /* ignored by mktime */ tm.tm_isdst = REC_SELINT(arg, 8); t = mktime (&tm); if (t < 0) { return RAISE_ERROR(lib7_state, "Invalid date"); } else { lib7_val_t result; INT32_ALLOC(lib7_state, result, t); return result; } }
/* _lib7_Time_gettime : Void -> (int32.Int * int * int32.Int * int * int32.Int * int) * * Return the total CPU time, system time and garbage collection time used by this * process so far. */ lib7_val_t _lib7_Time_gettime (lib7_state_t *lib7_state, lib7_val_t arg) { Time_t t, s; lib7_val_t tSec, sSec, gcSec, res; vproc_state_t *vsp = lib7_state->lib7_vproc; get_cpu_time (&t, &s); INT32_ALLOC (lib7_state, tSec, t.seconds); INT32_ALLOC (lib7_state, sSec, s.seconds); INT32_ALLOC (lib7_state, gcSec, vsp->vp_gcTime->seconds); REC_ALLOC6 (lib7_state, res, tSec, INT_CtoLib7(t.uSeconds), sSec, INT_CtoLib7(s.uSeconds), gcSec, INT_CtoLib7(vsp->vp_gcTime->uSeconds)); return res; } /* end of _lib7_Time_gettime */