[project @ 2001-05-21 14:04:15 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / CPUTime.hsc
index 090f401..810ac5f 100644 (file)
@@ -1,5 +1,5 @@
 -- -----------------------------------------------------------------------------
--- $Id: CPUTime.hsc,v 1.1 2001/05/08 08:55:17 simonmar Exp $
+-- $Id: CPUTime.hsc,v 1.4 2001/05/21 14:04:15 simonmar Exp $
 --
 -- (c) The University of Glasgow, 1995-2001
 --
@@ -19,46 +19,10 @@ import PrelPtr
 import PrelBase                ( Int(..) )
 import PrelByteArr     ( ByteArray(..), newIntArray )
 import PrelArrExtra     ( unsafeFreezeByteArray )
-import PrelIOBase      ( IOException(..), 
-                         IOErrorType( UnsupportedOperation ), 
-                         unsafePerformIO, stToIO, ioException )
+import PrelIOBase      ( IOException(..) )
 import Ratio
 
-#include "config.h"
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifndef mingw32_TARGET_OS
-# ifdef HAVE_SYS_TIMES_H
-#  include <sys/times.h>
-# endif
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
-# if defined(HAVE_SYS_RESOURCE_H)
-#  include <sys/resource.h>
-# endif
-#endif
-
-#ifdef hpux_TARGET_OS
-#include <sys/syscall.h>
-#define getrusage(a, b)  syscall(SYS_GETRUSAGE, a, b)
-#define HAVE_GETRUSAGE
-#endif
-
-#ifdef HAVE_WINDOWS_H
-# include <windows.h>
-#endif
+#include "HsStd.h"
 
 -- -----------------------------------------------------------------------------
 -- Computation `getCPUTime' returns the number of picoseconds CPU time
@@ -94,14 +58,20 @@ getCPUTime = do
     return ((fromIntegral u_sec * 1000000 + fromIntegral u_usec + 
              fromIntegral s_sec * 1000000 + fromIntegral s_usec) 
                * 1000000)
+
+type CRUsage = ()
+foreign import unsafe getrusage :: CInt -> Ptr CRUsage -> IO CInt
 #else
 # if defined(HAVE_TIMES)
-    allocaBytes (#const sizeof(struct tms)) $ \ p_tms ->
+    allocaBytes (#const sizeof(struct tms)) $ \ p_tms -> do
     times p_tms
     u_ticks  <- (#peek struct tms,tms_utime) p_tms :: IO CClock
     s_ticks  <- (#peek struct tms,tms_stime) p_tms :: IO CClock
     return (( (fromIntegral u_ticks + fromIntegral s_ticks) * 1000000000000) 
                        `div` clockTicks)
+
+type CTms = ()
+foreign import unsafe times :: Ptr CTms -> CClock
 # else
     ioException (IOError Nothing UnsupportedOperation 
                         "getCPUTime"
@@ -165,8 +135,5 @@ clockTicks =
     (#const CLK_TCK)
 #else
     unsafePerformIO (sysconf (#const _SC_CLK_TCK) >>= return . fromIntegral)
+foreign import unsafe sysconf :: CInt -> IO CLong
 #endif
-
-type CRUsage = ()
-foreign import unsafe getrusage :: CInt -> Ptr CRUsage -> IO CInt
-foreign import unsafe sysconf   :: CInt -> IO CLong