module Simulation.Aivika.Activity
(
Activity,
newActivity,
newStateActivity,
newPreemptibleActivity,
newPreemptibleStateActivity,
activityNet,
activityInitState,
activityState,
activityTotalUtilisationTime,
activityTotalIdleTime,
activityTotalPreemptionTime,
activityUtilisationTime,
activityIdleTime,
activityPreemptionTime,
activityUtilisationFactor,
activityIdleFactor,
activityPreemptionFactor,
resetActivity,
activitySummary,
activityStateChanged,
activityStateChanged_,
activityTotalUtilisationTimeChanged,
activityTotalUtilisationTimeChanged_,
activityTotalIdleTimeChanged,
activityTotalIdleTimeChanged_,
activityTotalPreemptionTimeChanged,
activityTotalPreemptionTimeChanged_,
activityUtilisationTimeChanged,
activityUtilisationTimeChanged_,
activityIdleTimeChanged,
activityIdleTimeChanged_,
activityPreemptionTimeChanged,
activityPreemptionTimeChanged_,
activityUtilisationFactorChanged,
activityUtilisationFactorChanged_,
activityIdleFactorChanged,
activityIdleFactorChanged_,
activityPreemptionFactorChanged,
activityPreemptionFactorChanged_,
activityUtilising,
activityUtilised,
activityPreemptionBeginning,
activityPreemptionEnding,
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
data Activity s a b =
Activity { forall s a b. Activity s a b -> s
activityInitState :: s,
forall s a b. Activity s a b -> IORef s
activityStateRef :: IORef s,
forall s a b. Activity s a b -> s -> a -> Process (s, b)
activityProcess :: s -> a -> Process (s, b),
forall s a b. Activity s a b -> Bool
activityProcessPreemptible :: Bool,
forall s a b. Activity s a b -> IORef Double
activityTotalUtilisationTimeRef :: IORef Double,
forall s a b. Activity s a b -> IORef Double
activityTotalIdleTimeRef :: IORef Double,
forall s a b. Activity s a b -> IORef Double
activityTotalPreemptionTimeRef :: IORef Double,
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef :: IORef (SamplingStats Double),
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef :: IORef (SamplingStats Double),
forall s a b. Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef :: IORef (SamplingStats Double),
forall s a b. Activity s a b -> SignalSource a
activityUtilisingSource :: SignalSource a,
forall s a b. Activity s a b -> SignalSource (a, b)
activityUtilisedSource :: SignalSource (a, b),
forall s a b. Activity s a b -> SignalSource a
activityPreemptionBeginningSource :: SignalSource a,
forall s a b. Activity s a b -> SignalSource a
activityPreemptionEndingSource :: SignalSource a
}
newActivity :: (a -> Process b)
-> 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
newStateActivity :: (s -> a -> Process (s, b))
-> s
-> 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
newPreemptibleActivity :: Bool
-> (a -> Process b)
-> 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)
newPreemptibleStateActivity :: Bool
-> (s -> a -> Process (s, b))
-> s
-> 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 }
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
(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))
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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))
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)
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)
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))
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)
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)
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))
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)
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)
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
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
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
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
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)
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)
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