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 { Activity s a b -> s
activityInitState :: s,
Activity s a b -> IORef s
activityStateRef :: IORef s,
Activity s a b -> s -> a -> Process (s, b)
activityProcess :: s -> a -> Process (s, b),
Activity s a b -> Bool
activityProcessPreemptible :: Bool,
Activity s a b -> IORef Double
activityTotalUtilisationTimeRef :: IORef Double,
Activity s a b -> IORef Double
activityTotalIdleTimeRef :: IORef Double,
Activity s a b -> IORef Double
activityTotalPreemptionTimeRef :: IORef Double,
Activity s a b -> IORef (SamplingStats Double)
activityUtilisationTimeRef :: IORef (SamplingStats Double),
Activity s a b -> IORef (SamplingStats Double)
activityIdleTimeRef :: IORef (SamplingStats Double),
Activity s a b -> IORef (SamplingStats Double)
activityPreemptionTimeRef :: IORef (SamplingStats Double),
Activity s a b -> SignalSource a
activityUtilisingSource :: SignalSource a,
Activity s a b -> SignalSource (a, b)
activityUtilisedSource :: SignalSource (a, b),
Activity s a b -> SignalSource a
activityPreemptionBeginningSource :: SignalSource a,
Activity s a b -> SignalSource a
activityPreemptionEndingSource :: SignalSource a
}
newActivity :: (a -> Process b)
-> 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
newStateActivity :: (s -> a -> Process (s, b))
-> s
-> 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
newPreemptibleActivity :: Bool
-> (a -> Process b)
-> 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)
newPreemptibleStateActivity :: Bool
-> (s -> a -> Process (s, b))
-> s
-> 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 }
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
(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))
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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))
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)
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)
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))
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)
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)
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))
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)
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)
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
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
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
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
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)
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)
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