1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team 2005
5 * Machine-dependent time measurement functions
7 * ---------------------------------------------------------------------------*/
18 /* elapsedtime() -- The current elapsed time in seconds */
20 #define HNS_PER_SEC 10000000LL /* FILETIMES are in units of 100ns */
21 /* Convert FILETIMEs into secs */
22 #define FT2longlong(ll,ft) \
23 (ll)=(ft).dwHighDateTime; \
25 (ll) |= (ft).dwLowDateTime; \
26 (ll) /= (unsigned long long) (HNS_PER_SEC / CLOCKS_PER_SEC)
28 /* cygwin32 or mingw32 version */
30 getProcessTimes( Ticks *user, Ticks *elapsed )
32 static int is_win9x = -1;
33 static Ticks elapsed_start = 0;
35 FILETIME creationTime, exitTime, userTime, kernelTime = {0,0};
39 /* figure out whether we're on a Win9x box or not. */
43 /* Need to init the size field first.*/
44 oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
45 b = GetVersionEx(&oi);
47 is_win9x = ( (b && (oi.dwPlatformId & VER_PLATFORM_WIN32_WINDOWS)) ? 1 : 0);
51 /* On Win9x, just attribute all running time to the user. */
55 SystemTimeToFileTime(&st,&userTime);
57 /* ToDo: pin down elapsed times to just the OS thread(s) that
58 are evaluating/managing Haskell code.
60 if (!GetProcessTimes (GetCurrentProcess(), &creationTime,
61 &exitTime, &kernelTime, &userTime)) {
62 /* Probably on a Win95 box..*/
69 FT2longlong(kT,kernelTime);
70 FT2longlong(uT,userTime);
75 /* User time is assumed to start at zero, so adjust for the fact
76 that we're using system time & not process time on Win9x. */
77 if (elapsed_start == 0) {
78 elapsed_start = *elapsed;
80 *user -= elapsed_start;
84 Ticks getProcessCPUTime(void)
87 getProcessTimes(&user,&elapsed);
91 Ticks getProcessElapsedTime(void)
94 getProcessTimes(&user,&elapsed);
98 nat getPageFaults(void)
100 /* ToDo (on NT): better, get this via the performance data
101 that's stored in the registry. */