module Simulation.Aivika.Trans.Operation
(
Operation,
newOperation,
newPreemptibleOperation,
operationProcess,
operationTotalUtilisationTime,
operationTotalPreemptionTime,
operationUtilisationTime,
operationPreemptionTime,
operationUtilisationFactor,
operationPreemptionFactor,
resetOperation,
operationSummary,
operationTotalUtilisationTimeChanged,
operationTotalUtilisationTimeChanged_,
operationTotalPreemptionTimeChanged,
operationTotalPreemptionTimeChanged_,
operationUtilisationTimeChanged,
operationUtilisationTimeChanged_,
operationPreemptionTimeChanged,
operationPreemptionTimeChanged_,
operationUtilisationFactorChanged,
operationUtilisationFactorChanged_,
operationPreemptionFactorChanged,
operationPreemptionFactorChanged_,
operationUtilising,
operationUtilised,
operationPreemptionBeginning,
operationPreemptionEnding,
operationChanged_) where
import Data.Monoid
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Trans.Ref.Base
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Event
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.Cont
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Activity
import Simulation.Aivika.Trans.Server
import Simulation.Aivika.Trans.Statistics
data Operation m a b =
Operation { Operation m a b -> a -> Process m b
operationInitProcess :: a -> Process m b,
Operation m a b -> Bool
operationProcessPreemptible :: Bool,
Operation m a b -> Ref m Double
operationStartTimeRef :: Ref m Double,
Operation m a b -> Ref m Double
operationLastTimeRef :: Ref m Double,
Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef :: Ref m Double,
Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef :: Ref m Double,
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef :: Ref m (SamplingStats Double),
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef :: Ref m (SamplingStats Double),
Operation m a b -> SignalSource m a
operationUtilisingSource :: SignalSource m a,
Operation m a b -> SignalSource m (a, b)
operationUtilisedSource :: SignalSource m (a, b),
Operation m a b -> SignalSource m a
operationPreemptionBeginningSource :: SignalSource m a,
Operation m a b -> SignalSource m a
operationPreemptionEndingSource :: SignalSource m a
}
newOperation :: MonadDES m
=> (a -> Process m b)
-> Event m (Operation m a b)
{-# INLINABLE newOperation #-}
newOperation :: (a -> Process m b) -> Event m (Operation m a b)
newOperation = Bool -> (a -> Process m b) -> Event m (Operation m a b)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
False
newPreemptibleOperation :: MonadDES m
=> Bool
-> (a -> Process m b)
-> Event m (Operation m a b)
{-# INLINABLE newPreemptibleOperation #-}
newPreemptibleOperation :: Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible a -> Process m b
provide =
do Double
t0 <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
Ref m Double
r' <- Simulation m (Ref m Double) -> Event m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Event m (Ref m Double))
-> Simulation m (Ref m Double) -> Event m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
Ref m Double
r0 <- Simulation m (Ref m Double) -> Event m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Event m (Ref m Double))
-> Simulation m (Ref m Double) -> Event m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
Ref m Double
r1 <- Simulation m (Ref m Double) -> Event m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Event m (Ref m Double))
-> Simulation m (Ref m Double) -> Event m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
Ref m Double
r2 <- Simulation m (Ref m Double) -> Event m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Event m (Ref m Double))
-> Simulation m (Ref m Double) -> Event m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
Ref m (SamplingStats Double)
r3 <- Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
Ref m (SamplingStats Double)
r4 <- Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
SignalSource m a
s1 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
SignalSource m (a, b)
s2 <- Simulation m (SignalSource m (a, b))
-> Event m (SignalSource m (a, b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation Simulation m (SignalSource m (a, b))
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
SignalSource m a
s3 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
SignalSource m a
s4 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
Operation m a b -> Event m (Operation m a b)
forall (m :: * -> *) a. Monad m => a -> m a
return Operation :: forall (m :: * -> *) a b.
(a -> Process m b)
-> Bool
-> Ref m Double
-> Ref m Double
-> Ref m Double
-> Ref m Double
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> SignalSource m a
-> SignalSource m (a, b)
-> SignalSource m a
-> SignalSource m a
-> Operation m a b
Operation { operationInitProcess :: a -> Process m b
operationInitProcess = a -> Process m b
provide,
operationProcessPreemptible :: Bool
operationProcessPreemptible = Bool
preemptible,
operationStartTimeRef :: Ref m Double
operationStartTimeRef = Ref m Double
r',
operationLastTimeRef :: Ref m Double
operationLastTimeRef = Ref m Double
r0,
operationTotalUtilisationTimeRef :: Ref m Double
operationTotalUtilisationTimeRef = Ref m Double
r1,
operationTotalPreemptionTimeRef :: Ref m Double
operationTotalPreemptionTimeRef = Ref m Double
r2,
operationUtilisationTimeRef :: Ref m (SamplingStats Double)
operationUtilisationTimeRef = Ref m (SamplingStats Double)
r3,
operationPreemptionTimeRef :: Ref m (SamplingStats Double)
operationPreemptionTimeRef = Ref m (SamplingStats Double)
r4,
operationUtilisingSource :: SignalSource m a
operationUtilisingSource = SignalSource m a
s1,
operationUtilisedSource :: SignalSource m (a, b)
operationUtilisedSource = SignalSource m (a, b)
s2,
operationPreemptionBeginningSource :: SignalSource m a
operationPreemptionBeginningSource = SignalSource m a
s3,
operationPreemptionEndingSource :: SignalSource m a
operationPreemptionEndingSource = SignalSource m a
s4 }
operationProcess :: MonadDES m => Operation m a b -> a -> Process m b
{-# INLINABLE operationProcess #-}
operationProcess :: Operation m a b -> a -> Process m b
operationProcess Operation m a b
op a
a =
do Double
t0 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Operation m a b -> SignalSource m a
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource Operation m a b
op) a
a
(b
b, Double
dt) <- if Operation m a b -> Bool
forall (m :: * -> *) a b. Operation m a b -> Bool
operationProcessPreemptible Operation m a b
op
then Operation m a b -> a -> Process m (b, Double)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> a -> Process m (b, Double)
operationProcessPreempting Operation m a b
op a
a
else do b
b <- Operation m a b -> a -> Process m b
forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess Operation m a b
op a
a
(b, Double) -> Process m (b, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, Double
0)
Double
t1 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
do Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op) (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))
Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
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)
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t1
SignalSource m (a, b) -> (a, b) -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Operation m a b -> SignalSource m (a, b)
forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource Operation m a b
op) (a
a, b
b)
b -> Process m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
operationProcessPreempting :: MonadDES m => Operation m a b -> a -> Process m (b, Double)
{-# INLINABLE operationProcessPreempting #-}
operationProcessPreempting :: Operation m a b -> a -> Process m (b, Double)
operationProcessPreempting Operation m a b
op a
a =
do ProcessId m
pid <- Process m (ProcessId m)
forall (m :: * -> *). MonadDES m => Process m (ProcessId m)
processId
Double
t0 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
Ref m Double
rs <- Simulation m (Ref m Double) -> Process m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Process m (Ref m Double))
-> Simulation m (Ref m Double) -> Process m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
Ref m Double
r0 <- Simulation m (Ref m Double) -> Process m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Process m (Ref m Double))
-> Simulation m (Ref m Double) -> Process m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
DisposableEvent m
h1 <- Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (DisposableEvent m) -> Process m (DisposableEvent m))
-> Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$
Signal m () -> (() -> Event m ()) -> Event m (DisposableEvent m)
forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (ProcessId m -> Signal m ()
forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionBeginning ProcessId m
pid) ((() -> Event m ()) -> Event m (DisposableEvent m))
-> (() -> Event m ()) -> Event m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$ \() ->
do Double
t0 <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef Ref m Double
r0 Double
t0
SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Operation m a b -> SignalSource m a
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource Operation m a b
op) a
a
DisposableEvent m
h2 <- Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (DisposableEvent m) -> Process m (DisposableEvent m))
-> Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$
Signal m () -> (() -> Event m ()) -> Event m (DisposableEvent m)
forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (ProcessId m -> Signal m ()
forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionEnding ProcessId m
pid) ((() -> Event m ()) -> Event m (DisposableEvent m))
-> (() -> Event m ()) -> Event m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$ \() ->
do Double
t0 <- Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
r0
Double
t1 <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
let dt :: Double
dt = Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0
Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m Double
rs (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
dt)
Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
dt)
Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall a b. (a -> b) -> a -> b
$
Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
dt
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t1
SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Operation m a b -> SignalSource m a
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource Operation m a b
op) a
a
let m1 :: Process m (b, Double)
m1 =
do b
b <- Operation m a b -> a -> Process m b
forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess Operation m a b
op a
a
Double
dt <- Event m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m Double -> Process m Double)
-> Event m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
rs
(b, Double) -> Process m (b, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, Double
dt)
m2 :: Process m ()
m2 =
Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
do DisposableEvent m -> Event m ()
forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h1
DisposableEvent m -> Event m ()
forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h2
Process m (b, Double) -> Process m () -> Process m (b, Double)
forall (m :: * -> *) a b.
MonadDES m =>
Process m a -> Process m b -> Process m a
finallyProcess Process m (b, Double)
m1 Process m ()
m2
operationTotalUtilisationTime :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationTotalUtilisationTime #-}
operationTotalUtilisationTime :: Operation m a b -> Event m Double
operationTotalUtilisationTime Operation m a b
op =
(Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
operationTotalUtilisationTimeChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationTotalUtilisationTimeChanged #-}
operationTotalUtilisationTimeChanged :: Operation m a b -> Signal m Double
operationTotalUtilisationTimeChanged Operation m a b
op =
(() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Operation m a b -> Event m Double
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalUtilisationTime Operation m a b
op) (Operation m a b -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalUtilisationTimeChanged_ Operation m a b
op)
operationTotalUtilisationTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationTotalUtilisationTimeChanged_ #-}
operationTotalUtilisationTimeChanged_ :: Operation m a b -> Signal m ()
operationTotalUtilisationTimeChanged_ Operation m a b
op =
((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m (a, b)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op)
operationTotalPreemptionTime :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationTotalPreemptionTime #-}
operationTotalPreemptionTime :: Operation m a b -> Event m Double
operationTotalPreemptionTime Operation m a b
op =
(Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
operationTotalPreemptionTimeChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationTotalPreemptionTimeChanged #-}
operationTotalPreemptionTimeChanged :: Operation m a b -> Signal m Double
operationTotalPreemptionTimeChanged Operation m a b
op =
(() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Operation m a b -> Event m Double
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalPreemptionTime Operation m a b
op) (Operation m a b -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalPreemptionTimeChanged_ Operation m a b
op)
operationTotalPreemptionTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationTotalPreemptionTimeChanged_ #-}
operationTotalPreemptionTimeChanged_ :: Operation m a b -> Signal m ()
operationTotalPreemptionTimeChanged_ Operation m a b
op =
(a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m a
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationUtilisationTime :: MonadDES m => Operation m a b -> Event m (SamplingStats Double)
{-# INLINABLE operationUtilisationTime #-}
operationUtilisationTime :: Operation m a b -> Event m (SamplingStats Double)
operationUtilisationTime Operation m a b
op =
(Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op)
operationUtilisationTimeChanged :: MonadDES m => Operation m a b -> Signal m (SamplingStats Double)
{-# INLINABLE operationUtilisationTimeChanged #-}
operationUtilisationTimeChanged :: Operation m a b -> Signal m (SamplingStats Double)
operationUtilisationTimeChanged Operation m a b
op =
(() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Operation m a b -> Event m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationUtilisationTime Operation m a b
op) (Operation m a b -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationTimeChanged_ Operation m a b
op)
operationUtilisationTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationUtilisationTimeChanged_ #-}
operationUtilisationTimeChanged_ :: Operation m a b -> Signal m ()
operationUtilisationTimeChanged_ Operation m a b
op =
((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m (a, b)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op)
operationPreemptionTime :: MonadDES m => Operation m a b -> Event m (SamplingStats Double)
{-# INLINABLE operationPreemptionTime #-}
operationPreemptionTime :: Operation m a b -> Event m (SamplingStats Double)
operationPreemptionTime Operation m a b
op =
(Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op)
operationPreemptionTimeChanged :: MonadDES m => Operation m a b -> Signal m (SamplingStats Double)
{-# INLINABLE operationPreemptionTimeChanged #-}
operationPreemptionTimeChanged :: Operation m a b -> Signal m (SamplingStats Double)
operationPreemptionTimeChanged Operation m a b
op =
(() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Operation m a b -> Event m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationPreemptionTime Operation m a b
op) (Operation m a b -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionTimeChanged_ Operation m a b
op)
operationPreemptionTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationPreemptionTimeChanged_ #-}
operationPreemptionTimeChanged_ :: Operation m a b -> Signal m ()
operationPreemptionTimeChanged_ Operation m a b
op =
(a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m a
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationUtilisationFactor :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationUtilisationFactor #-}
operationUtilisationFactor :: Operation m a b -> Event m Double
operationUtilisationFactor Operation m a b
op =
(Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
t0 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
Double
t1 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
Double
x <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
operationUtilisationFactorChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationUtilisationFactorChanged #-}
operationUtilisationFactorChanged :: Operation m a b -> Signal m Double
operationUtilisationFactorChanged Operation m a b
op =
(() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Operation m a b -> Event m Double
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationUtilisationFactor Operation m a b
op) (Operation m a b -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationFactorChanged_ Operation m a b
op)
operationUtilisationFactorChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationUtilisationFactorChanged_ #-}
operationUtilisationFactorChanged_ :: Operation m a b -> Signal m ()
operationUtilisationFactorChanged_ Operation m a b
op =
((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m (a, b)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
(a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m a
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationPreemptionFactor :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationPreemptionFactor #-}
operationPreemptionFactor :: Operation m a b -> Event m Double
operationPreemptionFactor Operation m a b
op =
(Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
t0 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
Double
t1 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
Double
x <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
operationPreemptionFactorChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationPreemptionFactorChanged #-}
operationPreemptionFactorChanged :: Operation m a b -> Signal m Double
operationPreemptionFactorChanged Operation m a b
op =
(() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Operation m a b -> Event m Double
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationPreemptionFactor Operation m a b
op) (Operation m a b -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionFactorChanged_ Operation m a b
op)
operationPreemptionFactorChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationPreemptionFactorChanged_ #-}
operationPreemptionFactorChanged_ :: Operation m a b -> Signal m ()
operationPreemptionFactorChanged_ Operation m a b
op =
((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m (a, b)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
(a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m a
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationUtilising :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationUtilising #-}
operationUtilising :: Operation m a b -> Signal m a
operationUtilising = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m a -> Signal m a)
-> (Operation m a b -> SignalSource m a)
-> Operation m a b
-> Signal m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Operation m a b -> SignalSource m a
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource
operationUtilised :: MonadDES m => Operation m a b -> Signal m (a, b)
{-# INLINABLE operationUtilised #-}
operationUtilised :: Operation m a b -> Signal m (a, b)
operationUtilised = SignalSource m (a, b) -> Signal m (a, b)
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m (a, b) -> Signal m (a, b))
-> (Operation m a b -> SignalSource m (a, b))
-> Operation m a b
-> Signal m (a, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Operation m a b -> SignalSource m (a, b)
forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource
operationPreemptionBeginning :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationPreemptionBeginning #-}
operationPreemptionBeginning :: Operation m a b -> Signal m a
operationPreemptionBeginning = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m a -> Signal m a)
-> (Operation m a b -> SignalSource m a)
-> Operation m a b
-> Signal m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Operation m a b -> SignalSource m a
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource
operationPreemptionEnding :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationPreemptionEnding #-}
operationPreemptionEnding :: Operation m a b -> Signal m a
operationPreemptionEnding = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m a -> Signal m a)
-> (Operation m a b -> SignalSource m a)
-> Operation m a b
-> Signal m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Operation m a b -> SignalSource m a
forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource
operationChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationChanged_ #-}
operationChanged_ :: Operation m a b -> Signal m ()
operationChanged_ Operation m a b
op =
(a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m a
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationUtilising Operation m a b
op) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m (a, b)
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
(a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Operation m a b -> Signal m a
forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
operationSummary :: MonadDES m => Operation m a b -> Int -> Event m ShowS
{-# INLINABLE operationSummary #-}
operationSummary :: Operation m a b -> Int -> Event m ShowS
operationSummary Operation m a b
op Int
indent =
(Point m -> m ShowS) -> Event m ShowS
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ShowS) -> Event m ShowS)
-> (Point m -> m ShowS) -> Event m ShowS
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do Double
t0 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
Double
t1 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
Double
tx1 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
Double
tx2 <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
let xf1 :: Double
xf1 = Double
tx1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
xf2 :: Double
xf2 = Double
tx2 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
SamplingStats Double
xs1 <- Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op)
SamplingStats Double
xs2 <- Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op)
let tab :: [Char]
tab = Int -> Char -> [Char]
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
ShowS -> m ShowS
forall (m :: * -> *) a. Monad m => a -> m a
return (ShowS -> m ShowS) -> ShowS -> m 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 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
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]
"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]
"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
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]
"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]
"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
xs2 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent)
resetOperation :: MonadDES m => Operation m a b -> Event m ()
{-# INLINABLE resetOperation #-}
resetOperation :: Operation m a b -> Event m ()
resetOperation Operation m a b
op =
do Double
t0 <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op) Double
t0
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t0
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op) Double
0
Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m Double
forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op) Double
0
Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op) SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Operation m a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op) SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats