-- |
-- 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 { Activity s a b -> s
activityInitState :: s,
             -- ^ The initial state of the activity.
             Activity s a b -> IORef s
activityStateRef :: IORef s,
             -- ^ The current state of the activity.
             Activity s a b -> s -> a -> Process (s, b)
activityProcess :: s -> a -> Process (s, b),
             -- ^ Provide @b@ by specified @a@.
             Activity s a b -> Bool
activityProcessPreemptible :: Bool,
             -- ^ Whether the process is preemptible.
             Activity s a b -> IORef Double
activityTotalUtilisationTimeRef :: IORef Double,
             -- ^ The counted total time of utilising the activity.
             Activity s a b -> IORef Double
activityTotalIdleTimeRef :: IORef Double,
             -- ^ The counted total time when the activity was idle.
             Activity s a b -> IORef Double
activityTotalPreemptionTimeRef :: IORef Double,
             -- ^ The counted total time when the activity was preempted. 
             Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef :: IORef (SamplingStats Double),
             -- ^ The statistics for the utilisation time.
             Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef :: IORef (SamplingStats Double),
             -- ^ The statistics for the time when the activity was idle.
             Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef :: IORef (SamplingStats Double),
             -- ^ The statistics for the time when the activity was preempted.
             Activity s a b -> SignalSource a
activityUtilisingSource :: SignalSource a,
             -- ^ A signal raised when starting to utilise the activity.
             Activity s a b -> SignalSource (a, b)
activityUtilisedSource :: SignalSource (a, b),
             -- ^ A signal raised when the activity has been utilised.
             Activity s a b -> SignalSource a
activityPreemptionBeginningSource :: SignalSource a,
             -- ^ A signal raised when the utilisation was preempted.
             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 :: (a -> Process b) -> Simulation (Activity () a b)
newActivity = Bool -> (a -> Process b) -> Simulation (Activity () a b)
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 :: (s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
newStateActivity = Bool
-> (s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
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 :: Bool -> (a -> Process b) -> Simulation (Activity () a b)
newPreemptibleActivity Bool
preemptible a -> Process b
provide =
  ((() -> a -> Process ((), b))
 -> () -> Simulation (Activity () a b))
-> ()
-> (() -> a -> Process ((), b))
-> Simulation (Activity () a b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Bool
-> (() -> a -> Process ((), b))
-> ()
-> Simulation (Activity () a b)
forall s a b.
Bool
-> (s -> a -> Process (s, b)) -> s -> Simulation (Activity s a b)
newPreemptibleStateActivity Bool
preemptible) () ((() -> a -> Process ((), b)) -> Simulation (Activity () a b))
-> (() -> a -> Process ((), b)) -> Simulation (Activity () a b)
forall a b. (a -> b) -> a -> b
$ \()
s a
a ->
  do b
b <- a -> Process b
provide a
a
     ((), b) -> Process ((), b)
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 :: 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 <- IO (IORef s) -> Simulation (IORef s)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef s) -> Simulation (IORef s))
-> IO (IORef s) -> Simulation (IORef s)
forall a b. (a -> b) -> a -> b
$ s -> IO (IORef s)
forall a. a -> IO (IORef a)
newIORef s
state
     IORef Double
r1 <- IO (IORef Double) -> Simulation (IORef Double)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef Double) -> Simulation (IORef Double))
-> IO (IORef Double) -> Simulation (IORef Double)
forall a b. (a -> b) -> a -> b
$ Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
0
     IORef Double
r2 <- IO (IORef Double) -> Simulation (IORef Double)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef Double) -> Simulation (IORef Double))
-> IO (IORef Double) -> Simulation (IORef Double)
forall a b. (a -> b) -> a -> b
$ Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
0
     IORef Double
r3 <- IO (IORef Double) -> Simulation (IORef Double)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef Double) -> Simulation (IORef Double))
-> IO (IORef Double) -> Simulation (IORef Double)
forall a b. (a -> b) -> a -> b
$ Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
0
     IORef (SamplingStats Double)
r4 <- IO (IORef (SamplingStats Double))
-> Simulation (IORef (SamplingStats Double))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef (SamplingStats Double))
 -> Simulation (IORef (SamplingStats Double)))
-> IO (IORef (SamplingStats Double))
-> Simulation (IORef (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> IO (IORef (SamplingStats Double))
forall a. a -> IO (IORef a)
newIORef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     IORef (SamplingStats Double)
r5 <- IO (IORef (SamplingStats Double))
-> Simulation (IORef (SamplingStats Double))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef (SamplingStats Double))
 -> Simulation (IORef (SamplingStats Double)))
-> IO (IORef (SamplingStats Double))
-> Simulation (IORef (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> IO (IORef (SamplingStats Double))
forall a. a -> IO (IORef a)
newIORef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     IORef (SamplingStats Double)
r6 <- IO (IORef (SamplingStats Double))
-> Simulation (IORef (SamplingStats Double))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef (SamplingStats Double))
 -> Simulation (IORef (SamplingStats Double)))
-> IO (IORef (SamplingStats Double))
-> Simulation (IORef (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> IO (IORef (SamplingStats Double))
forall a. a -> IO (IORef a)
newIORef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     SignalSource a
s1 <- Simulation (SignalSource a)
forall a. Simulation (SignalSource a)
newSignalSource
     SignalSource (a, b)
s2 <- Simulation (SignalSource (a, b))
forall a. Simulation (SignalSource a)
newSignalSource
     SignalSource a
s3 <- Simulation (SignalSource a)
forall a. Simulation (SignalSource a)
newSignalSource
     SignalSource a
s4 <- Simulation (SignalSource a)
forall a. Simulation (SignalSource a)
newSignalSource
     Activity s a b -> Simulation (Activity s a b)
forall (m :: * -> *) a. Monad m => a -> m a
return Activity :: forall s a b.
s
-> IORef s
-> (s -> a -> Process (s, b))
-> Bool
-> IORef Double
-> IORef Double
-> IORef Double
-> IORef (SamplingStats Double)
-> IORef (SamplingStats Double)
-> IORef (SamplingStats Double)
-> SignalSource a
-> SignalSource (a, b)
-> SignalSource a
-> SignalSource a
-> Activity s a b
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 :: Activity s a b -> Net a b
activityNet Activity s a b
act = (a -> Process (b, Net a b)) -> Net a b
forall a b. (a -> Process (b, Net a b)) -> Net a b
Net ((a -> Process (b, Net a b)) -> Net a b)
-> (a -> Process (b, Net a b)) -> Net a b
forall a b. (a -> b) -> a -> b
$ s -> Maybe Double -> a -> Process (b, Net a b)
loop (Activity s a b -> s
forall s a b. Activity s a b -> s
activityInitState Activity s a b
act) Maybe Double
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 <- Dynamics Double -> Process Double
forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
         Event () -> Process ()
forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent (Event () -> Process ()) -> Event () -> Process ()
forall a b. (a -> b) -> a -> b
$
           do case Maybe Double
r of
                Maybe Double
Nothing -> () -> Event ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                Just Double
t' ->
                  IO () -> Event ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event ()) -> IO () -> Event ()
forall a b. (a -> b) -> a -> b
$
                  do IORef Double -> (Double -> Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t'))
                     IORef (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Activity s a b -> IORef (SamplingStats Double)
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef Activity s a b
act) ((SamplingStats Double -> SamplingStats Double) -> IO ())
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a b. (a -> b) -> a -> b
$
                       Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t')
              SignalSource a -> a -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Activity s a b -> SignalSource a
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 Activity s a b -> Bool
forall s a b. Activity s a b -> Bool
activityProcessPreemptible Activity s a b
act
                        then Activity s a b -> s -> a -> Process (s, b, Double)
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) <- Activity s a b -> s -> a -> Process (s, b)
forall s a b. Activity s a b -> s -> a -> Process (s, b)
activityProcess Activity s a b
act s
s a
a
                                (s, b, Double) -> Process (s, b, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', b
b, Double
0)
         Double
t1 <- Dynamics Double -> Process Double
forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
         Event () -> Process ()
forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent (Event () -> Process ()) -> Event () -> Process ()
forall a b. (a -> b) -> a -> b
$
           do IO () -> Event ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event ()) -> IO () -> Event ()
forall a b. (a -> b) -> a -> b
$
                do IORef s -> s -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (Activity s a b -> IORef s
forall s a b. Activity s a b -> IORef s
activityStateRef Activity s a b
act) (s -> IO ()) -> s -> IO ()
forall a b. (a -> b) -> a -> b
$! s
s'
                   IORef Double -> (Double -> Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
dt))
                   IORef (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Activity s a b -> IORef (SamplingStats Double)
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef Activity s a b
act) ((SamplingStats Double -> SamplingStats Double) -> IO ())
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a b. (a -> b) -> a -> b
$
                     Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
dt)
              SignalSource (a, b) -> (a, b) -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Activity s a b -> SignalSource (a, b)
forall s a b. Activity s a b -> SignalSource (a, b)
activityUtilisedSource Activity s a b
act) (a
a, b
b)
         (b, Net a b) -> Process (b, Net a b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, (a -> Process (b, Net a b)) -> Net a b
forall a b. (a -> Process (b, Net a b)) -> Net a b
Net ((a -> Process (b, Net a b)) -> Net a b)
-> (a -> Process (b, Net a b)) -> Net a b
forall a b. (a -> b) -> a -> b
$ s -> Maybe Double -> a -> Process (b, Net a b)
loop s
s' (Double -> Maybe Double
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 :: 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  <- Dynamics Double -> Process Double
forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
     IORef Double
rs  <- IO (IORef Double) -> Process (IORef Double)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef Double) -> Process (IORef Double))
-> IO (IORef Double) -> Process (IORef Double)
forall a b. (a -> b) -> a -> b
$ Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
0
     IORef Double
r0  <- IO (IORef Double) -> Process (IORef Double)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef Double) -> Process (IORef Double))
-> IO (IORef Double) -> Process (IORef Double)
forall a b. (a -> b) -> a -> b
$ Double -> IO (IORef Double)
forall a. a -> IO (IORef a)
newIORef Double
t0
     DisposableEvent
h1  <- Event DisposableEvent -> Process DisposableEvent
forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent (Event DisposableEvent -> Process DisposableEvent)
-> Event DisposableEvent -> Process DisposableEvent
forall a b. (a -> b) -> a -> b
$
            Signal () -> (() -> Event ()) -> Event DisposableEvent
forall a. Signal a -> (a -> Event ()) -> Event DisposableEvent
handleSignal (ProcessId -> Signal ()
processPreemptionBeginning ProcessId
pid) ((() -> Event ()) -> Event DisposableEvent)
-> (() -> Event ()) -> Event DisposableEvent
forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t0 <- Dynamics Double -> Event Double
forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
               IO () -> Event ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event ()) -> IO () -> Event ()
forall a b. (a -> b) -> a -> b
$ IORef Double -> Double -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef Double
r0 Double
t0
               SignalSource a -> a -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Activity s a b -> SignalSource a
forall s a b. Activity s a b -> SignalSource a
activityPreemptionBeginningSource Activity s a b
act) a
a
     DisposableEvent
h2  <- Event DisposableEvent -> Process DisposableEvent
forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent (Event DisposableEvent -> Process DisposableEvent)
-> Event DisposableEvent -> Process DisposableEvent
forall a b. (a -> b) -> a -> b
$
            Signal () -> (() -> Event ()) -> Event DisposableEvent
forall a. Signal a -> (a -> Event ()) -> Event DisposableEvent
handleSignal (ProcessId -> Signal ()
processPreemptionEnding ProcessId
pid) ((() -> Event ()) -> Event DisposableEvent)
-> (() -> Event ()) -> Event DisposableEvent
forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t0 <- IO Double -> Event Double
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Double -> Event Double) -> IO Double -> Event Double
forall a b. (a -> b) -> a -> b
$ IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef IORef Double
r0
               Double
t1 <- Dynamics Double -> Event Double
forall (m :: * -> *) a. DynamicsLift m => Dynamics a -> m a
liftDynamics Dynamics Double
time
               let dt :: Double
dt = Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0
               IO () -> Event ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Event ()) -> IO () -> Event ()
forall a b. (a -> b) -> a -> b
$
                 do IORef Double -> (Double -> Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' IORef Double
rs (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
dt)
                    IORef Double -> (Double -> Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
dt)
                    IORef (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' (Activity s a b -> IORef (SamplingStats Double)
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef Activity s a b
act) ((SamplingStats Double -> SamplingStats Double) -> IO ())
-> (SamplingStats Double -> SamplingStats Double) -> IO ()
forall a b. (a -> b) -> a -> b
$
                      Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
dt
               SignalSource a -> a -> Event ()
forall a. SignalSource a -> a -> Event ()
triggerSignal (Activity s a b -> SignalSource a
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) <- Activity s a b -> s -> a -> Process (s, 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 <- IO Double -> Process Double
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Double -> Process Double) -> IO Double -> Process Double
forall a b. (a -> b) -> a -> b
$ IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef IORef Double
rs
              (s, b, Double) -> Process (s, b, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', b
b, Double
dt)
         m2 :: Process ()
m2 =
           Event () -> Process ()
forall (m :: * -> *) a. EventLift m => Event a -> m a
liftEvent (Event () -> Process ()) -> Event () -> Process ()
forall a b. (a -> b) -> a -> b
$
           do DisposableEvent -> Event ()
disposeEvent DisposableEvent
h1
              DisposableEvent -> Event ()
disposeEvent DisposableEvent
h2
     Process (s, b, Double) -> Process () -> Process (s, b, Double)
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 :: Activity s a b -> Event s
activityState Activity s a b
act =
  (Point -> IO s) -> Event s
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO s) -> Event s) -> (Point -> IO s) -> Event s
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef s -> IO s
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef s
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 :: Activity s a b -> Signal s
activityStateChanged Activity s a b
act =
  (() -> Event s) -> Signal () -> Signal s
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event s -> () -> Event s
forall a b. a -> b -> a
const (Event s -> () -> Event s) -> Event s -> () -> Event s
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event s
forall s a b. Activity s a b -> Event s
activityState Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityStateChanged_ Activity s a b
act =
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
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 :: Activity s a b -> Event Double
activityTotalUtilisationTime Activity s a b
act =
  (Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
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 :: Activity s a b -> Signal Double
activityTotalUtilisationTimeChanged Activity s a b
act =
  (() -> Event Double) -> Signal () -> Signal Double
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event Double -> () -> Event Double
forall a b. a -> b -> a
const (Event Double -> () -> Event Double)
-> Event Double -> () -> Event Double
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event Double
forall s a b. Activity s a b -> Event Double
activityTotalUtilisationTime Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityTotalUtilisationTimeChanged_ Activity s a b
act =
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
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 :: Activity s a b -> Event Double
activityTotalIdleTime Activity s a b
act =
  (Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
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 :: Activity s a b -> Signal Double
activityTotalIdleTimeChanged Activity s a b
act =
  (() -> Event Double) -> Signal () -> Signal Double
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event Double -> () -> Event Double
forall a b. a -> b -> a
const (Event Double -> () -> Event Double)
-> Event Double -> () -> Event Double
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event Double
forall s a b. Activity s a b -> Event Double
activityTotalIdleTime Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityTotalIdleTimeChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Event Double
activityTotalPreemptionTime Activity s a b
act =
  (Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
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 :: Activity s a b -> Signal Double
activityTotalPreemptionTimeChanged Activity s a b
act =
  (() -> Event Double) -> Signal () -> Signal Double
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event Double -> () -> Event Double
forall a b. a -> b -> a
const (Event Double -> () -> Event Double)
-> Event Double -> () -> Event Double
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event Double
forall s a b. Activity s a b -> Event Double
activityTotalPreemptionTime Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityTotalPreemptionTimeChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Event (SamplingStats Double)
activityUtilisationTime Activity s a b
act =
  (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (SamplingStats Double))
 -> Event (SamplingStats Double))
-> (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef (SamplingStats Double)
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 :: Activity s a b -> Signal (SamplingStats Double)
activityUtilisationTimeChanged Activity s a b
act =
  (() -> Event (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event (SamplingStats Double) -> () -> Event (SamplingStats Double)
forall a b. a -> b -> a
const (Event (SamplingStats Double)
 -> () -> Event (SamplingStats Double))
-> Event (SamplingStats Double)
-> ()
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event (SamplingStats Double)
forall s a b. Activity s a b -> Event (SamplingStats Double)
activityUtilisationTime Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityUtilisationTimeChanged_ Activity s a b
act =
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
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 :: Activity s a b -> Event (SamplingStats Double)
activityIdleTime Activity s a b
act =
  (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (SamplingStats Double))
 -> Event (SamplingStats Double))
-> (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef (SamplingStats Double)
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 :: Activity s a b -> Signal (SamplingStats Double)
activityIdleTimeChanged Activity s a b
act =
  (() -> Event (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event (SamplingStats Double) -> () -> Event (SamplingStats Double)
forall a b. a -> b -> a
const (Event (SamplingStats Double)
 -> () -> Event (SamplingStats Double))
-> Event (SamplingStats Double)
-> ()
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event (SamplingStats Double)
forall s a b. Activity s a b -> Event (SamplingStats Double)
activityIdleTime Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityIdleTimeChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Event (SamplingStats Double)
activityPreemptionTime Activity s a b
act =
  (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO (SamplingStats Double))
 -> Event (SamplingStats Double))
-> (Point -> IO (SamplingStats Double))
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point
p -> IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef (SamplingStats Double)
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 :: Activity s a b -> Signal (SamplingStats Double)
activityPreemptionTimeChanged Activity s a b
act =
  (() -> Event (SamplingStats Double))
-> Signal () -> Signal (SamplingStats Double)
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event (SamplingStats Double) -> () -> Event (SamplingStats Double)
forall a b. a -> b -> a
const (Event (SamplingStats Double)
 -> () -> Event (SamplingStats Double))
-> Event (SamplingStats Double)
-> ()
-> Event (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event (SamplingStats Double)
forall s a b. Activity s a b -> Event (SamplingStats Double)
activityPreemptionTime Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityPreemptionTimeChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Event Double
activityUtilisationFactor Activity s a b
act =
  (Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
x1 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
x2 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
x3 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     Double -> IO Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
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 :: Activity s a b -> Signal Double
activityUtilisationFactorChanged Activity s a b
act =
  (() -> Event Double) -> Signal () -> Signal Double
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event Double -> () -> Event Double
forall a b. a -> b -> a
const (Event Double -> () -> Event Double)
-> Event Double -> () -> Event Double
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event Double
forall s a b. Activity s a b -> Event Double
activityUtilisationFactor Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityUtilisationFactorChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Event Double
activityIdleFactor Activity s a b
act =
  (Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
x1 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
x2 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
x3 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     Double -> IO Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x2 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
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 :: Activity s a b -> Signal Double
activityIdleFactorChanged Activity s a b
act =
  (() -> Event Double) -> Signal () -> Signal Double
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event Double -> () -> Event Double
forall a b. a -> b -> a
const (Event Double -> () -> Event Double)
-> Event Double -> () -> Event Double
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event Double
forall s a b. Activity s a b -> Event Double
activityIdleFactor Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityIdleFactorChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Event Double
activityPreemptionFactor Activity s a b
act =
  (Point -> IO Double) -> Event Double
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO Double) -> Event Double)
-> (Point -> IO Double) -> Event Double
forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
x1 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
x2 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
x3 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     Double -> IO Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x3 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
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 :: Activity s a b -> Signal Double
activityPreemptionFactorChanged Activity s a b
act =
  (() -> Event Double) -> Signal () -> Signal Double
forall a b. (a -> Event b) -> Signal a -> Signal b
mapSignalM (Event Double -> () -> Event Double
forall a b. a -> b -> a
const (Event Double -> () -> Event Double)
-> Event Double -> () -> Event Double
forall a b. (a -> b) -> a -> b
$ Activity s a b -> Event Double
forall s a b. Activity s a b -> Event Double
activityPreemptionFactor Activity s a b
act) (Activity s a b -> Signal ()
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_ :: Activity s a b -> Signal ()
activityPreemptionFactorChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Signal a
activityUtilising = SignalSource a -> Signal a
forall a. SignalSource a -> Signal a
publishSignal (SignalSource a -> Signal a)
-> (Activity s a b -> SignalSource a) -> Activity s a b -> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Activity s a b -> SignalSource a
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 :: Activity s a b -> Signal (a, b)
activityUtilised = SignalSource (a, b) -> Signal (a, b)
forall a. SignalSource a -> Signal a
publishSignal (SignalSource (a, b) -> Signal (a, b))
-> (Activity s a b -> SignalSource (a, b))
-> Activity s a b
-> Signal (a, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Activity s a b -> SignalSource (a, b)
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 :: Activity s a b -> Signal a
activityPreemptionBeginning = SignalSource a -> Signal a
forall a. SignalSource a -> Signal a
publishSignal (SignalSource a -> Signal a)
-> (Activity s a b -> SignalSource a) -> Activity s a b -> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Activity s a b -> SignalSource a
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 :: Activity s a b -> Signal a
activityPreemptionEnding = SignalSource a -> Signal a
forall a. SignalSource a -> Signal a
publishSignal (SignalSource a -> Signal a)
-> (Activity s a b -> SignalSource a) -> Activity s a b -> Signal a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Activity s a b -> SignalSource a
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_ :: Activity s a b -> Signal ()
activityChanged_ Activity s a b
act =
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
forall s a b. Activity s a b -> Signal a
activityUtilising Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal (a, b) -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal (a, b)
forall s a b. Activity s a b -> Signal (a, b)
activityUtilised Activity s a b
act) Signal () -> Signal () -> Signal ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal a -> Signal ()
forall a b. (a -> b) -> Signal a -> Signal b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Activity s a b -> Signal a
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 :: Activity s a b -> Int -> Event ShowS
activitySummary Activity s a b
act Int
indent =
  (Point -> IO ShowS) -> Event ShowS
forall a. (Point -> IO a) -> Event a
Event ((Point -> IO ShowS) -> Event ShowS)
-> (Point -> IO ShowS) -> Event ShowS
forall a b. (a -> b) -> a -> b
$ \Point
p ->
  do Double
tx1 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef Activity s a b
act)
     Double
tx2 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef Activity s a b
act)
     Double
tx3 <- IORef Double -> IO Double
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef Double
forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef Activity s a b
act)
     let xf1 :: Double
xf1 = Double
tx1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3)
         xf2 :: Double
xf2 = Double
tx2 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3)
         xf3 :: Double
xf3 = Double
tx3 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3)
     SamplingStats Double
xs1 <- IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef (SamplingStats Double)
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef Activity s a b
act)
     SamplingStats Double
xs2 <- IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef (SamplingStats Double)
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef Activity s a b
act)
     SamplingStats Double
xs3 <- IORef (SamplingStats Double) -> IO (SamplingStats Double)
forall a. IORef a -> IO a
readIORef (Activity s a b -> IORef (SamplingStats Double)
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef Activity s a b
act)
     let tab :: [Char]
tab = Int -> Char -> [Char]
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     ShowS -> IO ShowS
forall (m :: * -> *) a. Monad m => a -> m a
return (ShowS -> IO ShowS) -> ShowS -> IO ShowS
forall a b. (a -> b) -> a -> b
$
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total utilisation time = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx1 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total idle time = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx2 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total preemption time = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx3 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"utilisation factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf1 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"idle factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf2 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf3 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"utilisation time:\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs1 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"idle time:\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs2 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption time:\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs3 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent)

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