From c1ef0cf577d6659a248180ed785efb37fe516082 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 1 Dec 2010 22:41:48 -0500 Subject: Implement dmnsn_get_times() on Windows. --- libdimension/platform.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libdimension/platform.c') diff --git a/libdimension/platform.c b/libdimension/platform.c index 8b6182d..a678cf4 100644 --- a/libdimension/platform.c +++ b/libdimension/platform.c @@ -130,6 +130,27 @@ dmnsn_get_times(dmnsn_timer *timer) timer->real = (double)real/clk_tck; timer->user = (double)buf.tms_utime/clk_tck; timer->system = (double)buf.tms_stime/clk_tck; +#elif defined(_WIN32) + FILETIME real; + GetSystemTimeAsFileTime(&real); + + FILETIME user, system, creation, exit; + HANDLE current_process = GetCurrentProcess(); + if (GetProcessTimes(current_process, + &creation, &exit, &system, &user) != 0) + { + timer->real + = (((uint64_t)real.dwHighDateTime << 32) + real.dwLowDateTime)/1.0e7; + timer->user + = (((uint64_t)user.dwHighDateTime << 32) + user.dwLowDateTime)/1.0e7; + timer->system + = (((uint64_t)system.dwHighDateTime << 32) + system.dwLowDateTime)/1.0e7; + } else { + dmnsn_error(DMNSN_SEVERITY_MEDIUM, "GetProcessTimes() failed."); + timer->real = 0.0; + timer->user = 0.0; + timer->system = 0.0; + } #else timer->real = 0.0; timer->user = 0.0; -- cgit v1.2.3