clock 0.2.0.0 → 0.3
raw patch · 6 files changed
+204/−204 lines, 6 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- System.Posix.Clock: Monotonic :: Clock
- System.Posix.Clock: ProcessCPUTime :: Clock
- System.Posix.Clock: Realtime :: Clock
- System.Posix.Clock: ThreadCPUTime :: Clock
- System.Posix.Clock: TimeSpec :: Int -> Int -> TimeSpec
- System.Posix.Clock: data Clock
- System.Posix.Clock: data TimeSpec
- System.Posix.Clock: getRes :: Clock -> IO TimeSpec
- System.Posix.Clock: getTime :: Clock -> IO TimeSpec
- System.Posix.Clock: instance Eq TimeSpec
- System.Posix.Clock: instance Ord TimeSpec
- System.Posix.Clock: instance Read TimeSpec
- System.Posix.Clock: instance Show TimeSpec
- System.Posix.Clock: instance Storable TimeSpec
- System.Posix.Clock: nsec :: TimeSpec -> Int
- System.Posix.Clock: sec :: TimeSpec -> Int
+ System.Clock: Monotonic :: Clock
+ System.Clock: ProcessCPUTime :: Clock
+ System.Clock: Realtime :: Clock
+ System.Clock: ThreadCPUTime :: Clock
+ System.Clock: TimeSpec :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> TimeSpec
+ System.Clock: data Clock
+ System.Clock: data TimeSpec
+ System.Clock: getRes :: Clock -> IO TimeSpec
+ System.Clock: getTime :: Clock -> IO TimeSpec
+ System.Clock: instance Eq TimeSpec
+ System.Clock: instance Ord TimeSpec
+ System.Clock: instance Read TimeSpec
+ System.Clock: instance Show TimeSpec
+ System.Clock: instance Storable TimeSpec
+ System.Clock: nsec :: TimeSpec -> Int
+ System.Clock: sec :: TimeSpec -> Int
Files
- COPYING +0/−32
- LICENSE +32/−0
- System/Clock.hs +117/−0
- System/Posix/Clock.hs +0/−127
- clock.cabal +51/−41
- csec/clock.c +4/−4
− COPYING
@@ -1,32 +0,0 @@-Copyright (c) 2010, Eugene Kirpichov-Copyright (c) 2009-2010, Cetin Sert--All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions are-met:-- * Redistributions of source code must retain the above copyright- notice, this list of conditions and the following disclaimer.-- * Redistributions in binary form must reproduce the above- copyright notice, this list of conditions and the following- disclaimer in the documentation and/or other materials provided- with the distribution.-- * The names of contributors may not be used to endorse or promote- products derived from this software without specific prior- written permission. --THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ LICENSE view
@@ -0,0 +1,32 @@+Copyright (c) 2009-2012, Cetin Sert+Copyright (c) 2010, Eugene Kirpichov++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * The names of contributors may not be used to endorse or promote+ products derived from this software without specific prior+ written permission. ++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ System/Clock.hs view
@@ -0,0 +1,117 @@+-- | High-resolution, realtime clock and timer functions for Posix+-- systems. This module is being developed according to IEEE Std+-- 1003.1-2008: <http://www.opengroup.org/onlinepubs/9699919799/>,+-- <http://www.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html#>++module System.Clock (++ Clock (Monotonic, Realtime, ProcessCPUTime, ThreadCPUTime),+ TimeSpec (TimeSpec),++ getTime,+ getRes,++ sec,+ nsec++) where++import Foreign.Ptr+import Foreign.Storable+import Foreign.Marshal.Alloc+import Control.Applicative++-- | Clock types.+-- A clock may be system-wide (that is, visible to all processes)+-- or per-process (measuring time that is meaningful only within+-- a process). All implementations shall support CLOCK_REALTIME.+data Clock = Monotonic -- ^ The identifier for the system-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be set via clock_settime and which cannot have negative clock jumps. The maximum possible clock jump shall be implementation-defined. For this clock, the value returned by 'getTime' represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past (for example, system start-up time, or the Epoch). This point does not change after system start-up time. Note that the absolute value of the monotonic clock is meaningless (because its origin is arbitrary), and thus there is no need to set it. Furthermore, realtime applications can rely on the fact that the value of this clock is never set.+ | Realtime -- ^ The identifier of the system-wide clock measuring real time. For this clock, the value returned by getTime represents the amount of time (in seconds and nanoseconds) since the Epoch.+ | ProcessCPUTime -- ^ The identifier of the CPU-time clock associated with the calling process. For this clock, the value returned by getTime represents the amount of execution time of the current process.+ | ThreadCPUTime -- ^ The identifier of the CPU-time clock associated with the calling OS thread. For this clock, the value returned by getTime represents the amount of execution time of the current OS thread.++-- | TimeSpec structure+data TimeSpec = TimeSpec {-# UNPACK #-} !Int -- seconds+ {-# UNPACK #-} !Int -- nanoseconds+ deriving (Show, Read, Eq)++-- | Gets seconds of a timespec value.+sec :: TimeSpec -> Int+-- | Gets nanoseconds of a timespec value.+nsec :: TimeSpec -> Int++sec (TimeSpec s _) = s+nsec (TimeSpec _ n) = n++instance Storable TimeSpec where+ sizeOf _ = sizeOf (0 :: Int) * 2+ alignment _ = 1+ poke t v = do+ let i :: Ptr Int = castPtr t+ i |^ 0 $! sec v+ i |^ 1 $! nsec v+ peek t = do+ let i :: Ptr Int = castPtr t+ TimeSpec <$> i |. 0 <*> i |. 1++instance Ord TimeSpec where+ compare (TimeSpec xs xn) (TimeSpec ys yn) = + if xs > ys then GT+ else if xs < ys then LT+ else if xn > yn then GT+ else if xn < yn then LT+ else EQ++-- | The 'getTime' function shall return the current value for the+-- specified clock.+getTime :: Clock -> IO TimeSpec+getTime = call . time++-- | The 'getRes' function shall return the resolution of any clock.+-- Clock resolutions are implementation-defined and cannot be set+-- by a process.+getRes :: Clock -> IO TimeSpec+getRes = call . res++---------------------------------------------++-- Reader function+type ReaderFunc = Ptr TimeSpec -> IO ()++-- Readers+foreign import ccall clock_readtime_monotonic :: ReaderFunc+foreign import ccall clock_readtime_realtime :: ReaderFunc+foreign import ccall clock_readtime_processtime :: ReaderFunc+foreign import ccall clock_readtime_threadtime :: ReaderFunc++foreign import ccall clock_readres_monotonic :: ReaderFunc+foreign import ccall clock_readres_realtime :: ReaderFunc+foreign import ccall clock_readres_processtime :: ReaderFunc+foreign import ccall clock_readres_threadtime :: ReaderFunc++-- Clock-to-time reading+time :: Clock -> ReaderFunc+time Monotonic = clock_readtime_monotonic+time Realtime = clock_readtime_realtime+time ProcessCPUTime = clock_readtime_processtime+time ThreadCPUTime = clock_readtime_threadtime++-- Clock-to-res reading+res :: Clock -> ReaderFunc+res Monotonic = clock_readres_monotonic+res Realtime = clock_readres_realtime+res ProcessCPUTime = clock_readres_processtime+res ThreadCPUTime = clock_readres_threadtime++-- Marshalling+call :: ReaderFunc -> IO TimeSpec+call read_ = do+ x <- malloc+ read_ x+ t <- peek x+ free x+ return t++-- Allocation and pointer operations+{-# INLINE (|.) #-}; (|.)::Storable a=>Ptr a -> Int -> IO a ; (|.) a i = peekElemOff a i+{-# INLINE (|^) #-}; (|^)::Storable a=>Ptr a -> Int -> a -> IO (); (|^) a i v = pokeElemOff a i v
− System/Posix/Clock.hs
@@ -1,127 +0,0 @@--- | High-resolution, realtime clock and timer functions for Posix--- systems. This module is being developed according to IEEE Std--- 1003.1-2008: <http://www.opengroup.org/onlinepubs/9699919799/>,--- <http://www.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html#>-module System.Posix.Clock (-- Clock (Monotonic, Realtime, ProcessCPUTime, ThreadCPUTime),- TimeSpec (TimeSpec),-- getTime,- getRes,-- sec,- nsec--) where---import Foreign.Ptr---import System.IO.Unsafe-import Foreign.Storable-import Foreign.Marshal.Alloc----- | Clock types.--- A clock may be system-wide (that is, visible to all processes)--- or per-process (measuring time that is meaningful only within--- a process). All implementations shall support CLOCK_REALTIME.-data Clock = Monotonic -- ^ The identifier for the system-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be set via clock_settime and which cannot have negative clock jumps. The maximum possible clock jump shall be implementation-defined. For this clock, the value returned by 'getTime' represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past (for example, system start-up time, or the Epoch). This point does not change after system start-up time. Note that the absolute value of the monotonic clock is meaningless (because its origin is arbitrary), and thus there is no need to set it. Furthermore, realtime applications can rely on the fact that the value of this clock is never set.- | Realtime -- ^ The identifier of the system-wide clock measuring real time. For this clock, the value returned by getTime represents the amount of time (in seconds and nanoseconds) since the Epoch.- | ProcessCPUTime -- ^ The identifier of the CPU-time clock associated with the calling process. For this clock, the value returned by getTime represents the amount of execution time of the current process.- | ThreadCPUTime -- ^ The identifier of the CPU-time clock associated with the calling OS thread. For this clock, the value returned by getTime represents the amount of execution time of the current OS thread.---- | TimeSpec structure-data TimeSpec = TimeSpec {- - sec :: Int, -- ^ Seconds- nsec :: Int -- ^ Nanoseconds--} deriving (Show, Read, Eq)--instance Storable TimeSpec where- sizeOf _ = sizeOf (0 :: Int) * 2- alignment _ = 1- poke t v = do- let i :: Ptr Int = castPtr t- (i ≣← 0) $ sec v- (i ≣← 1) $ nsec v- peek t = do- let i :: Ptr Int = castPtr t- s ← (i ≣→ 0)- n ← (i ≣→ 1)- return $ TimeSpec s n--instance Ord TimeSpec where- compare (TimeSpec xs xn) (TimeSpec ys yn) = - if xs > ys then GT- else if xs < ys then LT- else if xn > yn then GT- else if xn < yn then LT- else EQ---- | The 'getTime' function shall return the current value for the--- specified clock.-getTime :: Clock → IO TimeSpec-getTime = call . time---- | The 'getRes' function shall return the resolution of any clock.--- Clock resolutions are implementation-defined and cannot be set--- by a process.-getRes :: Clock → IO TimeSpec-getRes = call . res--------------------------------------------------- Reader function-type ReaderFunc = Ptr TimeSpec → IO ()---- Readers-foreign import ccall clock_readtime_monotonic :: ReaderFunc-foreign import ccall clock_readtime_realtime :: ReaderFunc-foreign import ccall clock_readtime_processtime :: ReaderFunc-foreign import ccall clock_readtime_threadtime :: ReaderFunc--foreign import ccall clock_readres_monotonic :: ReaderFunc-foreign import ccall clock_readres_realtime :: ReaderFunc-foreign import ccall clock_readres_processtime :: ReaderFunc-foreign import ccall clock_readres_threadtime :: ReaderFunc---- Clock-to-time reading-time :: Clock → ReaderFunc-time Monotonic = clock_readtime_monotonic-time Realtime = clock_readtime_realtime-time ProcessCPUTime = clock_readtime_processtime-time ThreadCPUTime = clock_readtime_threadtime---- Clock-to-res reading-res :: Clock → ReaderFunc-res Monotonic = clock_readres_monotonic-res Realtime = clock_readres_realtime-res ProcessCPUTime = clock_readres_processtime-res ThreadCPUTime = clock_readres_threadtime---- Marshalling-call :: ReaderFunc → IO TimeSpec-call read_ = do- x ← (↑)- read_ x- t ← (x ⋅)- (x ⊠)- return t---- Allocation and pointer operations-(↑) :: Storable a ⇒ IO (Ptr a)-(↑) = malloc--(⋅) :: Storable a ⇒ Ptr a → IO a-(⋅) = peek--(≣→) :: Storable a ⇒ Ptr a → Int → IO a-(≣→) = peekElemOff--(≣←) :: Storable a ⇒ Ptr a → Int → a → IO ()-(≣←) = pokeElemOff--(⊠) :: Ptr a → IO ()-(⊠) = Foreign.Marshal.Alloc.free
clock.cabal view
@@ -1,41 +1,51 @@-Name: clock-Version: 0.2.0.0-License: BSD3-License-file: COPYING-Copyright: (c) Cetin Sert 2009-2010, (c) Eugene Kirpichov 2010-Author: Cetin Sert <cetin@sertcom.de>, Eugene Kirpichov <ekirpichov@gmail.com>-Maintainer: Cetin Sert <cetin@sertcom.de>-Homepage: http://corsis.sourceforge.net/index.php/Haskell/Clock-Category: System-Synopsis: High-resolution clock and timer functions:- realtime, monotonic, cputime, etc.-Description: A package for convenient access to high-resolution- clock and timer functions of different operating- systems.- .- It is planned to consist of two layers. The lower- layer will provide direct access to OS-specific- clock and timer functions like clock_gettime of- Posix or GetTickCount of Windows and its upper- layer shall then provide a common API for all- supported systems. Currently only the lower level- is being developed.- .- .- POSIX reference: IEEE Std 1003.1-2008- <http://www.opengroup.org/onlinepubs/9699919799/>, - <http://www.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html#>- .- WINDOWS reference: ...- .- For more information, see:- <http://corsis.sourceforge.net/index.php/Haskell/Clock>-Stability: Experimental-Build-type: Simple-Build-depends: base >= 2 && < 5-Exposed-Modules: System.Posix.Clock-Extensions: ForeignFunctionInterface-C-sources: csec/clock.c-Include-dirs: csec-Install-includes: clock.h-ghc-options: -O2 -Wall -fglasgow-exts+name: clock+version: 0.3+stability: stable+synopsis: High-resolution clock functions: monotonic, realtime, cputime.+description: A package for convenient access to high-resolution clock and+ timer functions of different operating systems.+ .+ POSIX layer was developed by Cetin Sert in 2009.+ .+ Windows layer was contributed by Eugene Kirpichov in 2010.+ .+ Both layers share the same surface API.+ .+ [Version Scheme]+ Major-@/R/@-ewrite . New-@/F/@-unctionality . @/I/@-mprovementAndBugFixes . @/P/@-ackagingOnly+ .+ * @PackagingOnly@ changes are made for quality assurance reasons.++copyright: Copyright © Cetin Sert 2009-2012, Eugene Kirpichov 2010+license: BSD3+license-file: LICENSE+author: Cetin Sert <cetin@corsis.eu>, Corsis Research; Eugene Kirpichov <ekirpichov@gmail.com>+maintainer: Cetin Sert <cetin@corsis.eu>, Corsis Research+homepage: http://corsis.github.com/clock/+bug-reports: http://corsis.github.com/clock/issues+category: System+build-type: Simple+cabal-version: >= 1.6+++source-repository head+ type: git+ location: git://github.com/corsis/clock.git+++flag llvm+ description: compile via LLVM+ default : False+++library+ build-depends: base >= 2 && <= 5+ exposed-modules: System.Clock+ extensions: ForeignFunctionInterface ScopedTypeVariables+ c-sources: csec/clock.c+ include-dirs: csec+ install-includes: clock.h+ ghc-options: -O2 -Wall+ + if flag(llvm)+ ghc-options: -fllvm -optlo-O3
csec/clock.c view
@@ -125,11 +125,11 @@ clock_gettime(clock, (struct timespec*)t); -/* struct timespec a;+/*struct timespec a; clock_gettime(clock, &a); - t[0] = a.tv_sec ;+ t[0] = a.tv_sec; t[1] = a.tv_nsec;*/ }@@ -160,11 +160,11 @@ clock_getres(clock, (struct timespec*)t); -/* struct timespec a;+/*struct timespec a; clock_getres(clock, &a); - t[0] = a.tv_sec ;+ t[0] = a.tv_sec; t[1] = a.tv_nsec;*/ }