/* Store the CPU time used by this process and all its dead children (and their dead children) in BUFFER. Return the elapsed real time, or (clock_t) -1 for errors. All times are in CLK_TCKths of a second. */ clock_t __times (struct tms *tms) { struct task_basic_info bi; struct task_thread_times_info tti; mach_msg_type_number_t count; union { time_value_t tvt; struct timeval tv; } now; error_t err; count = TASK_BASIC_INFO_COUNT; err = __task_info (__mach_task_self (), TASK_BASIC_INFO, (task_info_t) &bi, &count); if (err) return __hurd_fail (err); count = TASK_THREAD_TIMES_INFO_COUNT; err = __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO, (task_info_t) &tti, &count); if (err) return __hurd_fail (err); tms->tms_utime = (clock_from_time_value (&bi.user_time) + clock_from_time_value (&tti.user_time)); tms->tms_stime = (clock_from_time_value (&bi.system_time) + clock_from_time_value (&tti.system_time)); /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */ tms->tms_cutime = tms->tms_cstime = 0; if (__gettimeofday (&now.tv, NULL) < 0) return -1; return (clock_from_time_value (&now.tvt) - clock_from_time_value (&bi.creation_time)); }
/* Return the time used by the program so far (user time + system time). */ clock_t clock (void) { struct task_basic_info bi; struct task_thread_times_info tti; mach_msg_type_number_t count; clock_t total; error_t err; count = TASK_BASIC_INFO_COUNT; err = __task_info (__mach_task_self (), TASK_BASIC_INFO, (task_info_t) &bi, &count); if (err) return __hurd_fail (err); count = TASK_THREAD_TIMES_INFO_COUNT; err = __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO, (task_info_t) &tti, &count); if (err) return __hurd_fail (err); total = bi.user_time.seconds * 1000000 + bi.user_time.microseconds; total += tti.user_time.seconds * 1000000 + tti.user_time.microseconds; total += bi.system_time.seconds * 1000000 + bi.system_time.microseconds; total += tti.system_time.seconds * 1000000 + tti.system_time.microseconds; return total; }