module System.CPUTime.Posix.Times
( getCPUTime
, getCpuTimePrecision
) where
import Data.Ratio
import Foreign
import Foreign.C
import System.CPUTime.Utils
getCPUTime :: IO Integer
getCPUTime = allocaBytes (32) $ \ p_tms -> do
_ <- times p_tms
u_ticks <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p_tms :: IO CClock
s_ticks <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p_tms :: IO CClock
return (( (cClockToInteger u_ticks + cClockToInteger s_ticks) * 1e12)
`div` fromIntegral clockTicks)
type CTms = ()
foreign import ccall unsafe times :: Ptr CTms -> IO CClock
getCpuTimePrecision :: IO Integer
getCpuTimePrecision =
return $ round ((1e12::Integer) % clockTicks)
foreign import ccall unsafe clk_tck :: CLong
clockTicks :: Integer
clockTicks = fromIntegral clk_tck