X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Flib%2Fstd%2Fcbits%2FgetCPUTime.c;h=8e348411c9724fb5d31b292d12775047aa6267f9;hb=e548e8aa01501daa9ac475af7e8318ff888dc2da;hp=edc5794d986a05360de0d9a1c2ffb5fd1c40961c;hpb=438596897ebbe25a07e1c82085cfbc5bdb00f09e;p=ghc-hetmet.git diff --git a/ghc/lib/std/cbits/getCPUTime.c b/ghc/lib/std/cbits/getCPUTime.c index edc5794..8e34841 100644 --- a/ghc/lib/std/cbits/getCPUTime.c +++ b/ghc/lib/std/cbits/getCPUTime.c @@ -1,7 +1,7 @@ /* * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998 * - * $Id: getCPUTime.c,v 1.3 1998/12/02 13:27:36 simonm Exp $ + * $Id: getCPUTime.c,v 1.5 1999/05/03 13:22:29 sof Exp $ * * getCPUTime Runtime Support */ @@ -25,16 +25,20 @@ #include #endif -#ifdef HAVE_SYS_TIMES_H -#include +#ifndef mingw32_TARGET_OS +# ifdef HAVE_SYS_TIMES_H +# include +# endif #endif #ifdef HAVE_SYS_TIME_H #include #endif -#if defined(HAVE_SYS_RESOURCE_H) && ! irix_TARGET_OS -#include +#if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS) +# if defined(HAVE_SYS_RESOURCE_H) +# include +# endif #endif #ifdef HAVE_SYS_TIMEB_H @@ -47,6 +51,10 @@ #define HAVE_GETRUSAGE #endif +#ifdef HAVE_WINDOWS_H +# include +#endif + StgInt clockTicks () { @@ -67,6 +75,7 @@ clockTicks () * seconds to overflow 31 bits. */ +#ifndef _WIN32 StgByteArray getCPUTime(StgByteArray cpuStruct) { @@ -110,3 +119,48 @@ getCPUTime(StgByteArray cpuStruct) #endif return (StgByteArray) cpuStruct; } + +#else + +#ifdef _WIN32 +/* 100ns units per sec, really */ +#define NS_PER_SEC 10000000LL +#define FT2usecs(ll,ft) \ + (ll)=(ft).dwHighDateTime; \ + (ll) <<= 32; \ + (ll) |= (ft).dwLowDateTime; + +#endif + +/* cygwin32 or mingw32 version */ +StgByteArray +getCPUTime(StgByteArray cpuStruct) +{ + FILETIME creationTime, exitTime, kernelTime, userTime; + StgInt *cpu=(StgInt *)cpuStruct; + unsigned long long uT, kT; + + /* ToDo: pin down elapsed times to just the OS thread(s) that + are evaluating/managing Haskell code. + */ + if (!GetProcessTimes (GetCurrentProcess(), &creationTime, + &exitTime, &kernelTime, &userTime)) { + /* Probably on a Win95 box..*/ + cpu[0]=0; + cpu[1]=0; + cpu[2]=0; + cpu[3]=0; + return (StgByteArray)cpu; + } + + FT2usecs(uT, userTime); + FT2usecs(kT, kernelTime); + + cpu[0] = (unsigned int)(uT / NS_PER_SEC); + cpu[1] = (unsigned int)(uT * 100); + cpu[0] = (unsigned int)(kT / NS_PER_SEC); + cpu[1] = (unsigned int)(kT * 100); + return (StgByteArray)cpu; +} + +#endif /* _WIN32 */