1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 2005
5 * Machine-dependent time measurement functions
7 * ---------------------------------------------------------------------------*/
18 #define HNS_PER_SEC 10000000LL /* FILETIMES are in units of 100ns */
19 /* Convert FILETIMEs into secs */
21 static INLINE_ME Ticks
22 fileTimeToTicks(FILETIME ft)
25 t = ((Ticks)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
26 t = (t * TICKS_PER_SECOND) / HNS_PER_SEC;
30 static int is_win9x = -1;
32 static INLINE_ME rtsBool
36 /* figure out whether we're on a Win9x box or not. */
40 /* Need to init the size field first.*/
41 oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
42 b = GetVersionEx(&oi);
44 is_win9x = ( (b && (oi.dwPlatformId & VER_PLATFORM_WIN32_WINDOWS)) ? 1 : 0);
51 getProcessTimes(Ticks *user, Ticks *elapsed)
53 *user = getProcessCPUTime();
54 *elapsed = getProcessElapsedTime();
58 getProcessCPUTime(void)
60 FILETIME creationTime, exitTime, userTime, kernelTime = {0,0};
62 if (isWin9x()) return getProcessElapsedTime();
64 if (!GetProcessTimes(GetCurrentProcess(), &creationTime,
65 &exitTime, &kernelTime, &userTime)) {
69 return fileTimeToTicks(userTime);
73 getProcessElapsedTime(void)
76 GetSystemTimeAsFileTime(&system_time);
77 return fileTimeToTicks(system_time);
81 getThreadCPUTime(void)
83 FILETIME creationTime, exitTime, userTime, kernelTime = {0,0};
85 if (isWin9x()) return getProcessCPUTime();
87 if (!GetThreadTimes(GetCurrentThread(), &creationTime,
88 &exitTime, &kernelTime, &userTime)) {
92 return fileTimeToTicks(userTime);
98 /* ToDo (on NT): better, get this via the performance data
99 that's stored in the registry. */