-- |
-- Module     : Simulation.Aivika.Activity
-- Copyright  : Copyright (c) 2009-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- It models an activity that can be utilised. The activity is similar to a 'Server'
-- but destined for simulation within 'Net' computation.
module Simulation.Aivika.Activity
       (-- * Activity
        Activity,
        newActivity,
        newStateActivity,
        newPreemptibleActivity,
        newPreemptibleStateActivity,
        -- * Processing
        activityNet,
        -- * Activity Properties
        activityInitState,
        activityState,
        activityTotalUtilisationTime,
        activityTotalIdleTime,
        activityTotalPreemptionTime,
        activityUtilisationTime,
        activityIdleTime,
        activityPreemptionTime,
        activityUtilisationFactor,
        activityIdleFactor,
        activityPreemptionFactor,
        -- * Statistics Reset
        resetActivity,
        -- * Summary
        activitySummary,
        -- * Derived Signals for Properties
        activityStateChanged,
        activityStateChanged_,
        activityTotalUtilisationTimeChanged,
        activityTotalUtilisationTimeChanged_,
        activityTotalIdleTimeChanged,
        activityTotalIdleTimeChanged_,
        activityTotalPreemptionTimeChanged,
        activityTotalPreemptionTimeChanged_,
        activityUtilisationTimeChanged,
        activityUtilisationTimeChanged_,
        activityIdleTimeChanged,
        activityIdleTimeChanged_,
        activityPreemptionTimeChanged,
        activityPreemptionTimeChanged_,
        activityUtilisationFactorChanged,
        activityUtilisationFactorChanged_,
        activityIdleFactorChanged,
        activityIdleFactorChanged_,
        activityPreemptionFactorChanged,
        activityPreemptionFactorChanged_,
        -- * Basic Signals
        activityUtilising,
        activityUtilised,
        activityPreemptionBeginning,
        activityPreemptionEnding,
        -- * Overall Signal
        activityChanged_) where

import Data.IORef
import Data.Monoid

import Control.Monad
import Control.Monad.Trans
import Control.Arrow

import Simulation.Aivika.Simulation
import Simulation.Aivika.Dynamics
import Simulation.Aivika.Internal.Event
import Simulation.Aivika.Signal
import Simulation.Aivika.Cont
import Simulation.Aivika.Process
import Simulation.Aivika.Net
import Simulation.Aivika.Server
import Simulation.Aivika.Statistics

-- | Like 'Server' it models an activity that takes @a@ and provides @b@ having state @s@.
-- But unlike the former the activity is destined for simulation within 'Net' computation.
data Activity s a b =
  Activity { forall s a b. Activity s a b -> s
activityInitState :: s,
             -- ^ The initial state of the activity.
             forall s a b. Activity s a b -> IORef s
activityStateRef :: IORef s,
             -- ^ The current state of the activity.
             forall s a b. Activity s a b -> s -> a -> Process (s, b)
activityProcess :: s -> a -> Process (s, b),
             -- ^ Provide @b@ by specified @a@.
             forall s a b. Activity s a b -> Bool
activityProcessPreemptible :: Bool,
             -- ^ Whether the process is preemptible.
             forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef :: IORef Double,
             -- ^ The counted total time of utilising the activity.
             forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef :: IORef Double,
             -- ^ The counted total time when the activity was idle.
             forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef :: IORef Double,
             -- ^ The counted total time when the activity was preempted. 
             forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef :: IORef (SamplingStats Double),
             -- ^ The statistics for the utilisation time.
             forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef :: IORef (SamplingStats Double),
             -- ^ The statistics for the time when the activity was idle.
             forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef :: IORef (SamplingStats Double),
             -- ^ The statistics for the time when the activity was preempted.
             forall s a b. Activity s a b -> SignalSource a
activityUtilisingSource :: SignalSource a,
             -- ^ A signal raised when starting to utilise the activity.
             forall s a b. Activity s a b -> SignalSource (a, b)
activityUtilisedSource :: SignalSource (a, b),
             -- ^ A signal raised when the activity has been utilised.
             forall s a b. Activity s a b -> SignalSource a
activityPreemptionBeginningSource :: SignalSource a,
             -- ^ A signal raised when the utilisation was preempted.
             forall s a b. Activity s a b -> SignalSource a
activityPreemptionEndingSource :: SignalSource a
             -- ^ A signal raised when the utilisation was proceeded after it had been preempted earlier.
           }

-- | Create a new activity that can provide output @b@ by input @a@.
--
-- By default, it is assumed that the activity utilisation cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newActivity :: (a -> Process b)
               -- ^ provide an output by the specified input
               -> Simulation (Activity () a b)
newActivity :: forall a b. (a -> Process b) -> Simulation (Activity () a b)
newActivity = forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
False

-- | Create a new activity that can provide output @b@ by input @a@
-- starting from state @s@.
--
-- By default, it is assumed that the activity utilisation cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newStateActivity :: (s -> a -> Process (s, b))
                    -- ^ provide a new state and output by the specified 
                    -- old state and input
                    -> s
                    -- ^ the initial state
                    -> Simulation (Activity s a b)
newStateActivity :: forall s a b.
(s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
newStateActivity = forall s a b.
Bool
-> (s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
newPreemptibleStateActivity Bool
False

-- | Create a new preemptible activity that can provide output @b@ by input @a@.
newPreemptibleActivity :: Bool
                          -- ^ whether the activity can be preempted
                          -> (a -> Process b)
                          -- ^ provide an output by the specified input
                          -> Simulation (Activity () a b)
newPreemptibleActivity :: forall a b.
Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible a -> Process b
provide =
  forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall s a b.
Bool
-> (s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
newPreemptibleStateActivity Bool
preemptible) () forall a b. (a -> b) -> a -> b
$ \()
s a
a ->
  do b
b <- a -> Process b
provide a
a
     forall (m :: * -> *) a. Monad m => a -> m a
return (()
s, b
b)

-- | Create a new activity that can provide output @b@ by input @a@
-- starting from state @s@.
newPreemptibleStateActivity :: Bool
                               -- ^ whether the activity can be preempted
                               -> (s -> a -> Process (s, b))
                               -- ^ provide a new state and output by the specified 
                               -- old state and input
                               -> s
                               -- ^ the initial state
                               -> Simulation (Activity s a b)
newPreemptibleStateActivity :: forall s a b.
Bool
-> (s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
newPreemptibleStateActivity Bool
preemptible s -> a -> Process (s, b)
provide s
state =
  do IORef s
r0 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef s
state
     IORef Double
r1 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef Double
0
     IORef Double
r2 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef Double
0
     IORef Double
r3 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef Double
0
     IORef (SamplingStats Double)
r4 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef forall a. SamplingData a => SamplingStats a
emptySamplingStats
     IORef (SamplingStats Double)
r5 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef forall a. SamplingData a => SamplingStats a
emptySamplingStats
     IORef (SamplingStats Double)
r6 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef forall a. SamplingData a => SamplingStats a
emptySamplingStats
     SignalSource a
s1 <- forall a. Simulation (SignalSource a)
newSignalSource
     SignalSource (a, b)
s2 <- forall a. Simulation (SignalSource a)
newSignalSource
     SignalSource a
s3 <- forall a. Simulation (SignalSource a)
newSignalSource
     SignalSource a
s4 <- forall a. Simulation (SignalSource a)
newSignalSource
     forall (m :: * -> *) a. Monad m => a -> m a
return Activity { activityInitState :: s
activityInitState = s
state,
                       activityStateRef :: IORef s
activityStateRef = IORef s
r0,
                       activityProcess :: s -> a -> Process (s, b)
activityProcess = s -> a -> Process (s, b)
provide,
                       activityProcessPreemptible :: Bool
activityProcessPreemptible = Bool
preemptible,
                       activityTotalUtilisationTimeRef :: IORef Double
activityTotalUtilisationTimeRef = IORef Double
r1,
                       activityTotalIdleTimeRef :: IORef Double
activityTotalIdleTimeRef = IORef Double
r2,
                       activityTotalPreemptionTimeRef :: IORef Double
activityTotalPreemptionTimeRef = IORef Double
r3,
                       activityUtilisationTimeRef :: IORef (SamplingStats Double)
activityUtilisationTimeRef = IORef (SamplingStats Double)
r4,
                       activityIdleTimeRef :: IORef (SamplingStats Double)
activityIdleTimeRef = IORef (SamplingStats Double)
r5,
                       activityPreemptionTimeRef :: IORef (SamplingStats Double)
activityPreemptionTimeRef = IORef (SamplingStats Double)
r6,
                       activityUtilisingSource :: SignalSource a
activityUtilisingSource = SignalSource a
s1,
                       activityUtilisedSource :: SignalSource (a, b)
activityUtilisedSource = SignalSource (a, b)
s2,
                       activityPreemptionBeginningSource :: SignalSource a
activityPreemptionBeginningSource = SignalSource a
s3,
                       activityPreemptionEndingSource :: SignalSource a
activityPreemptionEndingSource = SignalSource a
s4 }

-- | Return a network computation for the specified activity.
--
-- The computation updates the internal state of the activity. The usual case is when 
-- the computation is applied only once in a chain of data processing. Otherwise; 
-- every time the computation is used, the state of the activity changes. Sometimes 
-- it can be indeed useful if you want to aggregate the statistics for different 
-- activities simultaneously, but it would be more preferable to avoid this.
--
-- If you connect different activity computations returned by this function in a chain 
-- with help of '>>>' or other category combinator then this chain will act as one 
-- whole, where the first activity will take a new task only after the last activity 
-- finishes its current task and requests for the next one from the previous activity 
-- in the chain. This is not always that thing you might need.
activityNet :: Activity s a b -> Net a b
activityNet :: forall s a b. Activity s a b -> Net a b
activityNet Activity s a b
act = forall a b. (a -> Process (b, Net a b)) -> Net a b
Net forall a b. (a -> b) -> a -> b
$ s -> Maybe Double -> a -> Process (b, Net a b)
loop (forall s a b. Activity s a b -> s
activityInitState Activity s a b
act) forall a. Maybe a
Nothing
  where
    loop :: s -> Maybe Double -> a -> Process (b, Net a b)
loop s
s Maybe Double
r a
a =
      do Double
t0 <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
         forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent forall a b. (a -> b) -> a -> b
$
           do case Maybe Double
r of
                Maybe Double
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
                Just Double
t' ->
                  forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
                  do forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act) (forall a. Num a => a -> a -> a
+ (Double
t0 forall a. Num a => a -> a -> a
- Double
t'))
                     forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef Activity s a b
act) forall a b. (a -> b) -> a -> b
$
                       forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t0 forall a. Num a => a -> a -> a
- Double
t')
              forall a. SignalSource a -> a -> Event ()
triggerSignal (forall s a b. Activity s a b -> SignalSource a
activityUtilisingSource Activity s a b
act) a
a
         -- utilise the activity
         (s
s', b
b, Double
dt) <- if forall s a b. Activity s a b -> Bool
activityProcessPreemptible Activity s a b
act
                        then forall s a b. Activity s a b -> s -> a -> Process (s, b, Double)
activityProcessPreempting Activity s a b
act s
s a
a
                        else do (s
s', b
b) <- forall s a b. Activity s a b -> s -> a -> Process (s, b)
activityProcess Activity s a b
act s
s a
a
                                forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', b
b, Double
0)
         Double
t1 <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
         forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent forall a b. (a -> b) -> a -> b
$
           do forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
                do forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef s
activityStateRef Activity s a b
act) forall a b. (a -> b) -> a -> b
$! s
s'
                   forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act) (forall a. Num a => a -> a -> a
+ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0 forall a. Num a => a -> a -> a
- Double
dt))
                   forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef Activity s a b
act) forall a b. (a -> b) -> a -> b
$
                     forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t1 forall a. Num a => a -> a -> a
- Double
t0 forall a. Num a => a -> a -> a
- Double
dt)
              forall a. SignalSource a -> a -> Event ()
triggerSignal (forall s a b. Activity s a b -> SignalSource (a, b)
activityUtilisedSource Activity s a b
act) (a
a, b
b)
         forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, forall a b. (a -> Process (b, Net a b)) -> Net a b
Net forall a b. (a -> b) -> a -> b
$ s -> Maybe Double -> a -> Process (b, Net a b)
loop s
s' (forall a. a -> Maybe a
Just Double
t1))

-- | Process the input with ability to handle a possible preemption.
activityProcessPreempting :: Activity s a b -> s -> a -> Process (s, b, Double)
activityProcessPreempting :: forall s a b. Activity s a b -> s -> a -> Process (s, b, Double)
activityProcessPreempting Activity s a b
act s
s a
a =
  do ProcessId
pid <- Process ProcessId
processId
     Double
t0  <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
     IORef Double
rs  <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef Double
0
     IORef Double
r0  <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef Double
t0
     DisposableEvent
h1  <- forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent forall a b. (a -> b) -> a -> b
$
            forall a. Signal a -> (a -> Event ()) -> Event DisposableEvent
handleSignal (ProcessId -> Signal ()
processPreemptionBeginning ProcessId
pid) forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t0 <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
               forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. IORef a -> a -> IO ()
writeIORef IORef Double
r0 Double
t0
               forall a. SignalSource a -> a -> Event ()
triggerSignal (forall s a b. Activity s a b -> SignalSource a
activityPreemptionBeginningSource Activity s a b
act) a
a
     DisposableEvent
h2  <- forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent forall a b. (a -> b) -> a -> b
$
            forall a. Signal a -> (a -> Event ()) -> Event DisposableEvent
handleSignal (ProcessId -> Signal ()
processPreemptionEnding ProcessId
pid) forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t0 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. IORef a -> IO a
readIORef IORef Double
r0
               Double
t1 <- forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
               let dt :: Double
dt = Double
t1 forall a. Num a => a -> a -> a
- Double
t0
               forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
                 do forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' IORef Double
rs (forall a. Num a => a -> a -> a
+ Double
dt)
                    forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act) (forall a. Num a => a -> a -> a
+ Double
dt)
                    forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef Activity s a b
act) forall a b. (a -> b) -> a -> b
$
                      forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
dt
               forall a. SignalSource a -> a -> Event ()
triggerSignal (forall s a b. Activity s a b -> SignalSource a
activityPreemptionEndingSource Activity s a b
act) a
a 
     let m1 :: Process (s, b, Double)
m1 =
           do (s
s', b
b) <- forall s a b. Activity s a b -> s -> a -> Process (s, b)
activityProcess Activity s a b
act s
s a
a
              Double
dt <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. IORef a -> IO a
readIORef IORef Double
rs
              forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', b
b, Double
dt)
         m2 :: Process ()
m2 =
           forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent forall a b. (a -> b) -> a -> b
$
           do DisposableEvent -> Event ()
disposeEvent DisposableEvent
h1
              DisposableEvent -> Event ()
disposeEvent DisposableEvent
h2
     forall a b. Process a -> Process b -> Process a
finallyProcess Process (s, b, Double)
m1 Process ()
m2

-- | Return the current state of the activity.
--
-- See also 'activityStateChanged' and 'activityStateChanged_'.
activityState :: Activity s a b -> Event s
activityState :: forall s a b. Activity s a b -> Event s
activityState Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef s
activityStateRef Activity s a b
act)
  
-- | Signal when the 'activityState' property value has changed.
activityStateChanged :: Activity s a b -> Signal s
activityStateChanged :: forall s a b. Activity s a b -> Signal s
activityStateChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event s
activityState Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityStateChanged_ Activity s a b
act)
  
-- | Signal when the 'activityState' property value has changed.
activityStateChanged_ :: Activity s a b -> Signal ()
activityStateChanged_ :: forall s a b. Activity s a b -> Signal ()
activityStateChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act)

-- | Return the counted total time when the activity was utilised.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'activityTotalUtilisationTimeChanged' and 'activityTotalUtilisationTimeChanged_'.
activityTotalUtilisationTime :: Activity s a b -> Event Double
activityTotalUtilisationTime :: forall s a b. Activity s a b -> Event Double
activityTotalUtilisationTime Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
  
-- | Signal when the 'activityTotalUtilisationTime' property value has changed.
activityTotalUtilisationTimeChanged :: Activity s a b -> Signal Double
activityTotalUtilisationTimeChanged :: forall s a b. Activity s a b -> Signal Double
activityTotalUtilisationTimeChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event Double
activityTotalUtilisationTime Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityTotalUtilisationTimeChanged_ Activity s a b
act)
  
-- | Signal when the 'activityTotalUtilisationTime' property value has changed.
activityTotalUtilisationTimeChanged_ :: Activity s a b -> Signal ()
activityTotalUtilisationTimeChanged_ :: forall s a b. Activity s a b -> Signal ()
activityTotalUtilisationTimeChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act)

-- | Return the counted total time when the activity was idle.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'activityTotalIdleTimeChanged' and 'activityTotalIdleTimeChanged_'.
activityTotalIdleTime :: Activity s a b -> Event Double
activityTotalIdleTime :: forall s a b. Activity s a b -> Event Double
activityTotalIdleTime Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
  
-- | Signal when the 'activityTotalIdleTime' property value has changed.
activityTotalIdleTimeChanged :: Activity s a b -> Signal Double
activityTotalIdleTimeChanged :: forall s a b. Activity s a b -> Signal Double
activityTotalIdleTimeChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event Double
activityTotalIdleTime Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityTotalIdleTimeChanged_ Activity s a b
act)
  
-- | Signal when the 'activityTotalIdleTime' property value has changed.
activityTotalIdleTimeChanged_ :: Activity s a b -> Signal ()
activityTotalIdleTimeChanged_ :: forall s a b. Activity s a b -> Signal ()
activityTotalIdleTimeChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act)

-- | Return the counted total time when the activity was preemted waiting for
-- the further proceeding.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'activityTotalPreemptionTimeChanged' and 'activityTotalPreemptionTimeChanged_'.
activityTotalPreemptionTime :: Activity s a b -> Event Double
activityTotalPreemptionTime :: forall s a b. Activity s a b -> Event Double
activityTotalPreemptionTime Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
  
-- | Signal when the 'activityTotalPreemptionTime' property value has changed.
activityTotalPreemptionTimeChanged :: Activity s a b -> Signal Double
activityTotalPreemptionTimeChanged :: forall s a b. Activity s a b -> Signal Double
activityTotalPreemptionTimeChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event Double
activityTotalPreemptionTime Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityTotalPreemptionTimeChanged_ Activity s a b
act)
  
-- | Signal when the 'activityTotalPreemptionTime' property value has changed.
activityTotalPreemptionTimeChanged_ :: Activity s a b -> Signal ()
activityTotalPreemptionTimeChanged_ :: forall s a b. Activity s a b -> Signal ()
activityTotalPreemptionTimeChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityPreemptionEnding Activity s a b
act)

-- | Return the statistics for the time when the activity was utilised.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'activityUtilisationTimeChanged' and 'activityUtilisationTimeChanged_'.
activityUtilisationTime :: Activity s a b -> Event (SamplingStats Double)
activityUtilisationTime :: forall s a b. Activity s a b -> Event (SamplingStats Double)
activityUtilisationTime Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef Activity s a b
act)
  
-- | Signal when the 'activityUtilisationTime' property value has changed.
activityUtilisationTimeChanged :: Activity s a b -> Signal (SamplingStats Double)
activityUtilisationTimeChanged :: forall s a b. Activity s a b -> Signal (SamplingStats Double)
activityUtilisationTimeChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event (SamplingStats Double)
activityUtilisationTime Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityUtilisationTimeChanged_ Activity s a b
act)
  
-- | Signal when the 'activityUtilisationTime' property value has changed.
activityUtilisationTimeChanged_ :: Activity s a b -> Signal ()
activityUtilisationTimeChanged_ :: forall s a b. Activity s a b -> Signal ()
activityUtilisationTimeChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act)

-- | Return the statistics for the time when the activity was idle.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'activityIdleTimeChanged' and 'activityIdleTimeChanged_'.
activityIdleTime :: Activity s a b -> Event (SamplingStats Double)
activityIdleTime :: forall s a b. Activity s a b -> Event (SamplingStats Double)
activityIdleTime Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef Activity s a b
act)
  
-- | Signal when the 'activityIdleTime' property value has changed.
activityIdleTimeChanged :: Activity s a b -> Signal (SamplingStats Double)
activityIdleTimeChanged :: forall s a b. Activity s a b -> Signal (SamplingStats Double)
activityIdleTimeChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event (SamplingStats Double)
activityIdleTime Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityIdleTimeChanged_ Activity s a b
act)
  
-- | Signal when the 'activityIdleTime' property value has changed.
activityIdleTimeChanged_ :: Activity s a b -> Signal ()
activityIdleTimeChanged_ :: forall s a b. Activity s a b -> Signal ()
activityIdleTimeChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act)

-- | Return the statistics for the time when the activity was preempted
-- waiting for the further proceeding.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'activityPreemptionTimeChanged' and 'activityPreemptionTimeChanged_'.
activityPreemptionTime :: Activity s a b -> Event (SamplingStats Double)
activityPreemptionTime :: forall s a b. Activity s a b -> Event (SamplingStats Double)
activityPreemptionTime Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p -> forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef Activity s a b
act)
  
-- | Signal when the 'activityPreemptionTime' property value has changed.
activityPreemptionTimeChanged :: Activity s a b -> Signal (SamplingStats Double)
activityPreemptionTimeChanged :: forall s a b. Activity s a b -> Signal (SamplingStats Double)
activityPreemptionTimeChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event (SamplingStats Double)
activityPreemptionTime Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityPreemptionTimeChanged_ Activity s a b
act)
  
-- | Signal when the 'activityPreemptionTime' property value has changed.
activityPreemptionTimeChanged_ :: Activity s a b -> Signal ()
activityPreemptionTimeChanged_ :: forall s a b. Activity s a b -> Signal ()
activityPreemptionTimeChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityPreemptionEnding Activity s a b
act)
  
-- | It returns the factor changing from 0 to 1, which estimates how often
-- the activity was utilised.
--
-- This factor is calculated as
--
-- @
--   totalUtilisationTime \/ (totalUtilisationTime + totalIdleTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'activityUtilisationFactorChanged' and 'activityUtilisationFactorChanged_'.
activityUtilisationFactor :: Activity s a b -> Event Double
activityUtilisationFactor :: forall s a b. Activity s a b -> Event Double
activityUtilisationFactor Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
x1 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
x2 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
x3 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x1 forall a. Fractional a => a -> a -> a
/ (Double
x1 forall a. Num a => a -> a -> a
+ Double
x2 forall a. Num a => a -> a -> a
+ Double
x3))
  
-- | Signal when the 'activityUtilisationFactor' property value has changed.
activityUtilisationFactorChanged :: Activity s a b -> Signal Double
activityUtilisationFactorChanged :: forall s a b. Activity s a b -> Signal Double
activityUtilisationFactorChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event Double
activityUtilisationFactor Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityUtilisationFactorChanged_ Activity s a b
act)
  
-- | Signal when the 'activityUtilisationFactor' property value has changed.
activityUtilisationFactorChanged_ :: Activity s a b -> Signal ()
activityUtilisationFactorChanged_ :: forall s a b. Activity s a b -> Signal ()
activityUtilisationFactorChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityPreemptionEnding Activity s a b
act)
  
-- | It returns the factor changing from 0 to 1, which estimates how often
-- the activity was idle.
--
-- This factor is calculated as
--
-- @
--   totalIdleTime \/ (totalUtilisationTime + totalIdleTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'activityIdleFactorChanged' and 'activityIdleFactorChanged_'.
activityIdleFactor :: Activity s a b -> Event Double
activityIdleFactor :: forall s a b. Activity s a b -> Event Double
activityIdleFactor Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
x1 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
x2 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
x3 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x2 forall a. Fractional a => a -> a -> a
/ (Double
x1 forall a. Num a => a -> a -> a
+ Double
x2 forall a. Num a => a -> a -> a
+ Double
x3))
  
-- | Signal when the 'activityIdleFactor' property value has changed.
activityIdleFactorChanged :: Activity s a b -> Signal Double
activityIdleFactorChanged :: forall s a b. Activity s a b -> Signal Double
activityIdleFactorChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event Double
activityIdleFactor Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityIdleFactorChanged_ Activity s a b
act)
  
-- | Signal when the 'activityIdleFactor' property value has changed.
activityIdleFactorChanged_ :: Activity s a b -> Signal ()
activityIdleFactorChanged_ :: forall s a b. Activity s a b -> Signal ()
activityIdleFactorChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityPreemptionEnding Activity s a b
act)

-- | It returns the factor changing from 0 to 1, which estimates how often
-- the activity was preempted waiting for the further proceeding.
--
-- This factor is calculated as
--
-- @
--   totalUtilisationTime \/ (totalUtilisationTime + totalIdleTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'activityPreemptionFactorChanged' and 'activityPreemptionFactorChanged_'.
activityPreemptionFactor :: Activity s a b -> Event Double
activityPreemptionFactor :: forall s a b. Activity s a b -> Event Double
activityPreemptionFactor Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
x1 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
x2 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
x3 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x3 forall a. Fractional a => a -> a -> a
/ (Double
x1 forall a. Num a => a -> a -> a
+ Double
x2 forall a. Num a => a -> a -> a
+ Double
x3))
  
-- | Signal when the 'activityPreemptionFactor' property value has changed.
activityPreemptionFactorChanged :: Activity s a b -> Signal Double
activityPreemptionFactorChanged :: forall s a b. Activity s a b -> Signal Double
activityPreemptionFactorChanged Activity s a b
act =
  forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall s a b. Activity s a b -> Event Double
activityPreemptionFactor Activity s a b
act) (forall s a b. Activity s a b -> Signal ()
activityPreemptionFactorChanged_ Activity s a b
act)
  
-- | Signal when the 'activityPreemptionFactor' property value has changed.
activityPreemptionFactorChanged_ :: Activity s a b -> Signal ()
activityPreemptionFactorChanged_ :: forall s a b. Activity s a b -> Signal ()
activityPreemptionFactorChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityPreemptionEnding Activity s a b
act)
  
-- | Raised when starting to utilise the activity after a new input task is received.
activityUtilising :: Activity s a b -> Signal a
activityUtilising :: forall s a b. Activity s a b -> Signal a
activityUtilising = forall a. SignalSource a -> Signal a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a b. Activity s a b -> SignalSource a
activityUtilisingSource

-- | Raised when the activity has been utilised after the current task is processed.
activityUtilised :: Activity s a b -> Signal (a, b)
activityUtilised :: forall s a b. Activity s a b -> Signal (a, b)
activityUtilised = forall a. SignalSource a -> Signal a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a b. Activity s a b -> SignalSource (a, b)
activityUtilisedSource

-- | Raised when the activity utilisation was preempted.
activityPreemptionBeginning :: Activity s a b -> Signal a
activityPreemptionBeginning :: forall s a b. Activity s a b -> Signal a
activityPreemptionBeginning = forall a. SignalSource a -> Signal a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a b. Activity s a b -> SignalSource a
activityPreemptionBeginningSource

-- | Raised when the activity utilisation was proceeded after it had been preempted earlier.
activityPreemptionEnding :: Activity s a b -> Signal a
activityPreemptionEnding :: forall s a b. Activity s a b -> Signal a
activityPreemptionEnding = forall a. SignalSource a -> Signal a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a b. Activity s a b -> SignalSource a
activityPreemptionEndingSource

-- | Signal whenever any property of the activity changes.
activityChanged_ :: Activity s a b -> Signal ()
activityChanged_ :: forall s a b. Activity s a b -> Signal ()
activityChanged_ Activity s a b
act =
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) forall a. Semigroup a => a -> a -> a
<>
  forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (forall a b. a -> b -> a
const ()) (forall s a b. Activity s a b -> Signal a
activityPreemptionEnding Activity s a b
act)

-- | Return the summary for the activity with desciption of its
-- properties using the specified indent.
activitySummary :: Activity s a b -> Int -> Event ShowS
activitySummary :: forall s a b. Activity s a b -> Int -> Event ShowS
activitySummary Activity s a b
act Int
indent =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
tx1 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
tx2 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
tx3 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     let xf1 :: Double
xf1 = Double
tx1 forall a. Fractional a => a -> a -> a
/ (Double
tx1 forall a. Num a => a -> a -> a
+ Double
tx2 forall a. Num a => a -> a -> a
+ Double
tx3)
         xf2 :: Double
xf2 = Double
tx2 forall a. Fractional a => a -> a -> a
/ (Double
tx1 forall a. Num a => a -> a -> a
+ Double
tx2 forall a. Num a => a -> a -> a
+ Double
tx3)
         xf3 :: Double
xf3 = Double
tx3 forall a. Fractional a => a -> a -> a
/ (Double
tx1 forall a. Num a => a -> a -> a
+ Double
tx2 forall a. Num a => a -> a -> a
+ Double
tx3)
     SamplingStats Double
xs1 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef Activity s a b
act)
     SamplingStats Double
xs2 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef Activity s a b
act)
     SamplingStats Double
xs3 <- forall a. IORef a -> IO a
readIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef Activity s a b
act)
     let tab :: [Char]
tab = forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total utilisation time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total idle time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx2 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total preemption time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx3 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"utilisation factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"idle factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf2 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf3 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"utilisation time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs1 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"idle time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs2 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs3 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent)

-- | Reset the statistics.
resetActivity :: Activity s a b -> Event ()
resetActivity :: forall s a b. Activity s a b -> Event ()
resetActivity Activity s a b
act =
  forall a. (Point -> IO a) -> Event a
Event forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act) Double
0
     forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act) Double
0
     forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act) Double
0
     forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef Activity s a b
act) forall a. Monoid a => a
mempty
     forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef Activity s a b
act) forall a. Monoid a => a
mempty
     forall a. IORef a -> a -> IO ()
writeIORef (forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef Activity s a b
act) forall a. Monoid a => a
mempty