packages feed

clock 0.1.1 → 0.1.2

raw patch · 8 files changed

+245/−117 lines, 8 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- System.CPUTime.Clock: Monotonic :: Clock
- System.CPUTime.Clock: ProcessTime :: Clock
- System.CPUTime.Clock: Realtime :: Clock
- System.CPUTime.Clock: ThreadTime :: Clock
- System.CPUTime.Clock: Time :: Int -> Int -> TimeSpec
- System.CPUTime.Clock: clock_getres :: Clock -> IO TimeSpec
- System.CPUTime.Clock: clock_gettime :: Clock -> IO TimeSpec
- System.CPUTime.Clock: data Clock
- System.CPUTime.Clock: data TimeSpec
- System.CPUTime.Clock: instance Read TimeSpec
- System.CPUTime.Clock: instance Show TimeSpec
- System.CPUTime.Clock: nsec :: TimeSpec -> Int
- System.CPUTime.Clock: sec :: TimeSpec -> Int
+ 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

Files

CHANGES view
@@ -1,3 +1,24 @@ CHANGES -  0.1.1: added rudimentary documentation+  0.1.2: → System.CPUTime.Clock:+           renamed to System.Posix.Clock because it contained a+           posix-only implementation.++           later System.Windows.Clock can be implemented using+           QueryPerformanceCounter, GetTickCount64, etc. and a+           common interface could be exposed in System.Clock++         → System.Posix.Clock:+           clock_gettime renamed to getTime+           clock_getres  renamed to getRes++         → System.Posix.Clock.TimeSpec:+           now uses a record syntax and is also an instance of+           Foreign.Storable, Eq and Ord.++         → Source Documentation:+           improved according to IEEE Std 1003.1-2008+           http://www.opengroup.org/onlinepubs/9699919799/+++  0.1.1: → added rudimentary documentation
README view
@@ -1,26 +1,80 @@-Dedicated to An Le Thi Thanh+---------------- +DEDICATED TO++  An Le Thi Thanh++ ----------------  DESCRIPTION -  low-level bindings to time.h: clock_gettime and clock_getres+  see+  http://sert.homedns.org/hs/clock/dist/doc/html/clock/ ++  0.1.2 (current version)++  System+    Posix+      Clock+++  1.0.0 (future projection)++  System+    Clock+    Posix+      Clock+    Windows+      Clock++ ----------------  CONSIDERATIONS -  → Move from System.CPUTime.Clock to either System.Posix.Clock-    or ask for suggestions from other people.+  → Implement System.Windows.Clock using QueryPerformanceCounter,+    GetTickCount64, etc. and export a common interface in another+    module System.Clock -  → clock_getres has type 'Clock → IO TimeSpec' discuss changing-    to 'Clock → TimeSpec' with other haskell developers.+  → System.Posix.Clock:+    getRes has type 'Clock → IO TimeSpec' discuss changing this to+    'Clock → TimeSpec' with other haskell developers or read the+    IEEE Std 1003.1-2008 thoroughly and decide on what to do. +  → System.Posix.Clock:+    move to a more flexible clock_id representation so that we can+    get the process/thread cpu-time for not just the caller but any+    process/thread for which we can obtain a correspoinding clock_id +  → Namespaces:+    use *.Clocks instead of *.Clock?++ ----------------  KNOWN ISSUES -  → clock_settime not implemented.+  → namespace(s) have not been confirmed final. -  → namespace have not been confirmed final.+  → posix-only: windows implementation to be added later.++  → no tests.+++----------------++DISCLAIMER++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/CPUTime/Clock.hs
@@ -1,95 +0,0 @@--- | From time.h, provides clockid_t, timespec, clock_gettime, clock_getres.-module System.CPUTime.Clock (--  Clock (Monotonic, Realtime, ProcessTime, ThreadTime),-  TimeSpec (Time),--  clock_gettime,-  clock_getres,--  sec,-  nsec,  --) where--import GHC.Ptr---import System.IO.Unsafe-import Foreign.Storable-import Foreign.Marshal.Alloc (free)-import Foreign.Marshal.Array---- | Clock types-data Clock = Monotonic   -- ^ Clock that cannot be set and represents monotonic time since some unspecified starting point. -           | Realtime    -- ^ System-wide realtime clock-           | ProcessTime -- ^ High-resolution per-process timer from the CPU. -           | ThreadTime  -- ^ Thread-specific CPU-time clock. ---- | TimeSpec structure-data TimeSpec = Time Int Int deriving (Show, Read)---- | Seconds of a TimeSpec-sec  :: TimeSpec → Int-sec  (Time s _) = s---- | Nanoseconds of a TimeSpec-nsec :: TimeSpec → Int-nsec (Time _ n) = n---- | Retrieves the time of the specified clock.-clock_gettime :: Clock → IO TimeSpec-clock_gettime = call . time---- | Finds the resolution (precision) of the specified clock.-clock_getres :: Clock → IO TimeSpec-clock_getres = call . res--------------------------------------------------- Reader function-type ReaderFunc = Ptr Int → IO ()---- Clock-to-time reading-time :: Clock → ReaderFunc-time Monotonic = clock_readtime_monotonic-time Realtime  = clock_readtime_realtime-time ProcessTime = clock_readtime_processtime-time ThreadTime = clock_readtime_threadtime---- Clock-to-res reading-res :: Clock → ReaderFunc-res Monotonic = clock_readres_monotonic-res Realtime  = clock_readres_realtime-res ProcessTime = clock_readres_processtime-res ThreadTime = clock_readres_threadtime---- 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---- Marshalling-call :: ReaderFunc → IO TimeSpec-call read_ = do-  t ← (2 ↑≣)-  read_ t-  s ← (t ≣→ 0)-  n ← (t ≣→ 1)-  (t ≣⊠)-  return $ Time s n---- Arrays--(↑≣) :: Storable a ⇒ Int → IO (Ptr a)-(↑≣) = mallocArray--(≣→) :: Storable a ⇒ Ptr a → Int → IO a-(≣→) = peekElemOff--(≣⊠) :: Ptr a → IO ()-(≣⊠) = Foreign.Marshal.Alloc.free
+ System/Posix/Clock.hs view
@@ -0,0 +1,123 @@+-- | 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/>.+module System.Posix.Clock (++  Clock (Monotonic, Realtime, ProcessCPUTime, ThreadCPUTime),+  TimeSpec (TimeSpec),++  getTime,+  getRes,++) 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
clean view
@@ -1,2 +1,2 @@ cabal clean-find | grep -iE ~$ | xargs -n 1 rm+find | grep -iE ~$ | xargs -n 1 rm &> /dev/null
clock.cabal view
@@ -1,19 +1,41 @@ Name:               clock-Version:            0.1.1+Version:            0.1.2 License:            BSD3 License-file:       COPYING Copyright:          (c) 2009 Cetin Sert Author:             Cetin Sert <cetin@sertcom.de> Maintainer:         Cetin Sert <cetin@sertcom.de>-Homepage:           http://sert.homedns.org/hs/clock/+Homepage:           <http://sert.homedns.org/hs/clock/> Category:           System-Synopsis:           low-level binding to time.h: clock_gettime and clock_getres-Description:        low-level binding to time.h: clock_gettime and clock_getres. -                    clock_settime will be added in later versions.+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: !! This early version is+                    posix-only and does not build on Windows. Support+                    will be added in the future. !!+                    .+                    For more information, see:+                    <http://sert.homedns.org/hs/clock> Stability:          Experimental Build-type:         Simple Build-depends:      base >= 2 && < 5-Exposed-Modules:    System.CPUTime.Clock+Exposed-Modules:    System.Posix.Clock Extensions:         ForeignFunctionInterface C-sources:	        csec/clock.c Include-dirs:       csec
csec/clock.c view
@@ -5,12 +5,14 @@ void time_(clockid_t clock, long* t) { -  struct timespec a;+  clock_getres(clock, (struct timespec*)t); +/*  struct timespec a;+   clock_gettime(clock, &a);    t[0] = a.tv_sec ;-  t[1] = a.tv_nsec;+  t[1] = a.tv_nsec;*/  } @@ -38,12 +40,14 @@ void res_(clockid_t clock, long* t) { -  struct timespec a;+  clock_getres(clock, (struct timespec*)t); +/*  struct timespec a;+   clock_getres(clock, &a);    t[0] = a.tv_sec ;-  t[1] = a.tv_nsec;  +  t[1] = a.tv_nsec;*/  } @@ -66,4 +70,3 @@ {   res_(CLOCK_THREAD_CPUTIME_ID , t); }-
edit view
@@ -1,1 +1,1 @@-gedit AUTHORS COPYING README CHANGES clock.cabal csec/*.c csec/*.h System/CPUTime/*.hs &+gedit AUTHORS README CHANGES clock.cabal csec/*.c csec/*.h System/CPUTime/*.hs &