-- |
-- Module     : Simulation.Aivika.Trans.Operation
-- Copyright  : Copyright (c) 2009-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- It defines a stateless activity, some simplification of 'Server' and 'Activity'.
module Simulation.Aivika.Trans.Operation
       (-- * Operation
        Operation,
        newOperation,
        newPreemptibleOperation,
        -- * Processing
        operationProcess,
        -- * Operation Properties
        operationTotalUtilisationTime,
        operationTotalPreemptionTime,
        operationUtilisationTime,
        operationPreemptionTime,
        operationUtilisationFactor,
        operationPreemptionFactor,
        -- * Statistics Reset
        resetOperation,
        -- * Summary
        operationSummary,
        -- * Derived Signals for Properties
        operationTotalUtilisationTimeChanged,
        operationTotalUtilisationTimeChanged_,
        operationTotalPreemptionTimeChanged,
        operationTotalPreemptionTimeChanged_,
        operationUtilisationTimeChanged,
        operationUtilisationTimeChanged_,
        operationPreemptionTimeChanged,
        operationPreemptionTimeChanged_,
        operationUtilisationFactorChanged,
        operationUtilisationFactorChanged_,
        operationPreemptionFactorChanged,
        operationPreemptionFactorChanged_,
        -- * Basic Signals
        operationUtilising,
        operationUtilised,
        operationPreemptionBeginning,
        operationPreemptionEnding,
        -- * Overall Signal
        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

-- | Like 'Server' it models an activity that takes @a@ and provides @b@.
-- But unlike the former this kind of activity has no state. Also it is destined
-- to be used within 'Process' computations.
data Operation m a b =
  Operation { forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess :: a -> Process m b,
              -- ^ Provide @b@ by specified @a@.
              forall (m :: * -> *) a b. Operation m a b -> Bool
operationProcessPreemptible :: Bool,
              -- ^ Whether the process is preemptible.
              forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef :: Ref m Double,
              -- ^ The start time of creating the operation.
              forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef :: Ref m Double,
              -- ^ The last time of utilising the operation activity.
              forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef :: Ref m Double,
              -- ^ The counted total time of utilising the activity.
              forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef :: Ref m Double,
              -- ^ The counted total time when the activity was preempted. 
              forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef :: Ref m (SamplingStats Double),
              -- ^ The statistics for the utilisation time.
              forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef :: Ref m (SamplingStats Double),
              -- ^ The statistics for the time when the activity was preempted.
              forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource :: SignalSource m a,
              -- ^ A signal raised when starting to utilise the activity.
              forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource :: SignalSource m (a, b),
              -- ^ A signal raised when the activity has been utilised.
              forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource :: SignalSource m a,
              -- ^ A signal raised when the utilisation was preempted.
              forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource :: SignalSource m a
              -- ^ A signal raised when the utilisation was proceeded after it had been preempted earlier.
           }

-- | Create a new operation that can provide output @b@ by input @a@.
--
-- By default, it is assumed that the activity utilisation cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newOperation :: MonadDES m
                => (a -> Process m b)
                -- ^ provide an output by the specified input
                -> Event m (Operation m a b)
{-# INLINABLE newOperation #-}
newOperation :: forall (m :: * -> *) a b.
MonadDES m =>
(a -> Process m b) -> Event m (Operation m a b)
newOperation = forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
False

-- | Create a new operation that can provide output @b@ by input @a@.
newPreemptibleOperation :: MonadDES m
                           => Bool
                           -- ^ whether the activity can be preempted
                           -> (a -> Process m b)
                           -- ^ provide an output by the specified input
                           -> Event m (Operation m a b)
{-# INLINABLE newPreemptibleOperation #-}
newPreemptibleOperation :: forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Event m (Operation m a b)
newPreemptibleOperation Bool
preemptible a -> Process m b
provide =
  do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
     Ref m Double
r' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
     Ref m Double
r0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
     Ref m Double
r1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m Double
r2 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m (SamplingStats Double)
r3 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef forall a. SamplingData a => SamplingStats a
emptySamplingStats
     Ref m (SamplingStats Double)
r4 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef forall a. SamplingData a => SamplingStats a
emptySamplingStats
     SignalSource m a
s1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m (a, b)
s2 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s3 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s4 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     forall (m :: * -> *) a. Monad m => a -> m a
return 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 }

-- | Return a computation for the specified operation. It updates internal counters.
--
-- The computation can be used only within one process at any time.
operationProcess :: MonadDES m => Operation m a b -> a -> Process m b
{-# INLINABLE operationProcess #-}
operationProcess :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> a -> Process m b
operationProcess Operation m a b
op a
a =
  do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
     forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
       forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource Operation m a b
op) a
a
     -- utilise the activity
     (b
b, Double
dt) <- if forall (m :: * -> *) a b. Operation m a b -> Bool
operationProcessPreemptible Operation m a b
op
                then 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 <- forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess Operation m a b
op a
a
                        forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, Double
0)
     Double
t1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
     forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
       do forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op) (forall a. Num a => a -> a -> a
+ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0 forall a. Num a => a -> a -> a
- Double
dt))
          forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op) forall a b. (a -> b) -> a -> b
$
            forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t1 forall a. Num a => a -> a -> a
- Double
t0 forall a. Num a => a -> a -> a
- Double
dt)
          forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t1
          forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource Operation m a b
op) (a
a, b
b)
     forall (m :: * -> *) a. Monad m => a -> m a
return b
b

-- | Process the input with ability to handle a possible preemption.
operationProcessPreempting :: MonadDES m => Operation m a b -> a -> Process m (b, Double)
{-# INLINABLE operationProcessPreempting #-}
operationProcessPreempting :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> a -> Process m (b, Double)
operationProcessPreempting Operation m a b
op a
a =
  do ProcessId m
pid <- forall (m :: * -> *). MonadDES m => Process m (ProcessId m)
processId
     Double
t0  <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
     Ref m Double
rs  <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m Double
r0  <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t0
     DisposableEvent m
h1  <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
            forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionBeginning ProcessId m
pid) forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
               forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef Ref m Double
r0 Double
t0
               forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource Operation m a b
op) a
a
     DisposableEvent m
h2  <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
            forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionEnding ProcessId m
pid) forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t0 <- forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
r0
               Double
t1 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
               let dt :: Double
dt = Double
t1 forall a. Num a => a -> a -> a
- Double
t0
               forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m Double
rs (forall a. Num a => a -> a -> a
+ Double
dt)
               forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op) (forall a. Num a => a -> a -> a
+ Double
dt)
               forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op) forall a b. (a -> b) -> a -> b
$
                 forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
dt
               forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t1
               forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (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 <- forall (m :: * -> *) a b. Operation m a b -> a -> Process m b
operationInitProcess Operation m a b
op a
a
              Double
dt <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
rs
              forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, Double
dt)
         m2 :: Process m ()
m2 =
           forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent forall a b. (a -> b) -> a -> b
$
           do forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h1
              forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h2
     forall (m :: * -> *) a b.
MonadDES m =>
Process m a -> Process m b -> Process m a
finallyProcess Process m (b, Double)
m1 Process m ()
m2

-- | Return the counted total time when the operation activity was utilised.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'operationTotalUtilisationTimeChanged' and 'operationTotalUtilisationTimeChanged_'.
operationTotalUtilisationTime :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationTotalUtilisationTime #-}
operationTotalUtilisationTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalUtilisationTime Operation m a b
op =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
  
-- | Signal when the 'operationTotalUtilisationTime' property value has changed.
operationTotalUtilisationTimeChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationTotalUtilisationTimeChanged #-}
operationTotalUtilisationTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationTotalUtilisationTimeChanged Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalUtilisationTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalUtilisationTimeChanged_ Operation m a b
op)
  
-- | Signal when the 'operationTotalUtilisationTime' property value has changed.
operationTotalUtilisationTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationTotalUtilisationTimeChanged_ #-}
operationTotalUtilisationTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalUtilisationTimeChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op)

-- | Return the counted total time when the operation activity was preemted waiting for
-- the further proceeding.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'operationTotalPreemptionTimeChanged' and 'operationTotalPreemptionTimeChanged_'.
operationTotalPreemptionTime :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationTotalPreemptionTime #-}
operationTotalPreemptionTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalPreemptionTime Operation m a b
op =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
  
-- | Signal when the 'operationTotalPreemptionTime' property value has changed.
operationTotalPreemptionTimeChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationTotalPreemptionTimeChanged #-}
operationTotalPreemptionTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationTotalPreemptionTimeChanged Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationTotalPreemptionTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalPreemptionTimeChanged_ Operation m a b
op)
  
-- | Signal when the 'operationTotalPreemptionTime' property value has changed.
operationTotalPreemptionTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationTotalPreemptionTimeChanged_ #-}
operationTotalPreemptionTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationTotalPreemptionTimeChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)

-- | Return the statistics for the time when the operation activity was utilised.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'operationUtilisationTimeChanged' and 'operationUtilisationTimeChanged_'.
operationUtilisationTime :: MonadDES m => Operation m a b -> Event m (SamplingStats Double)
{-# INLINABLE operationUtilisationTime #-}
operationUtilisationTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationUtilisationTime Operation m a b
op =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op)
  
-- | Signal when the 'operationUtilisationTime' property value has changed.
operationUtilisationTimeChanged :: MonadDES m => Operation m a b -> Signal m (SamplingStats Double)
{-# INLINABLE operationUtilisationTimeChanged #-}
operationUtilisationTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (SamplingStats Double)
operationUtilisationTimeChanged Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationUtilisationTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationTimeChanged_ Operation m a b
op)
  
-- | Signal when the 'operationUtilisationTime' property value has changed.
operationUtilisationTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationUtilisationTimeChanged_ #-}
operationUtilisationTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationTimeChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op)

-- | Return the statistics for the time when the operation activity was preempted
-- waiting for the further proceeding.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'operationPreemptionTimeChanged' and 'operationPreemptionTimeChanged_'.
operationPreemptionTime :: MonadDES m => Operation m a b -> Event m (SamplingStats Double)
{-# INLINABLE operationPreemptionTime #-}
operationPreemptionTime :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationPreemptionTime Operation m a b
op =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p -> forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op)
  
-- | Signal when the 'operationPreemptionTime' property value has changed.
operationPreemptionTimeChanged :: MonadDES m => Operation m a b -> Signal m (SamplingStats Double)
{-# INLINABLE operationPreemptionTimeChanged #-}
operationPreemptionTimeChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (SamplingStats Double)
operationPreemptionTimeChanged Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m (SamplingStats Double)
operationPreemptionTime Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionTimeChanged_ Operation m a b
op)
  
-- | Signal when the 'operationPreemptionTime' property value has changed.
operationPreemptionTimeChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationPreemptionTimeChanged_ #-}
operationPreemptionTimeChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionTimeChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
  
-- | It returns the factor changing from 0 to 1, which estimates how often
-- the operation activity was utilised since the time of creating the operation.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'operationUtilisationFactorChanged' and 'operationUtilisationFactorChanged_'.
operationUtilisationFactor :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationUtilisationFactor #-}
operationUtilisationFactor :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationUtilisationFactor Operation m a b
op =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Double
t0 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
     Double
t1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
     Double
x  <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
     forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0))
  
-- | Signal when the 'operationUtilisationFactor' property value has changed.
operationUtilisationFactorChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationUtilisationFactorChanged #-}
operationUtilisationFactorChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationUtilisationFactorChanged Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationUtilisationFactor Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationFactorChanged_ Operation m a b
op)
  
-- | Signal when the 'operationUtilisationFactor' property value has changed.
operationUtilisationFactorChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationUtilisationFactorChanged_ #-}
operationUtilisationFactorChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationUtilisationFactorChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
  
-- | It returns the factor changing from 0 to 1, which estimates how often
-- the operation activity was preempted waiting for the further proceeding
-- since the time of creating the operation.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'operationPreemptionFactorChanged' and 'operationPreemptionFactorChanged_'.
operationPreemptionFactor :: MonadDES m => Operation m a b -> Event m Double
{-# INLINABLE operationPreemptionFactor #-}
operationPreemptionFactor :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationPreemptionFactor Operation m a b
op =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Double
t0 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
     Double
t1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
     Double
x  <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
     forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0))
  
-- | Signal when the 'operationPreemptionFactor' property value has changed.
operationPreemptionFactorChanged :: MonadDES m => Operation m a b -> Signal m Double
{-# INLINABLE operationPreemptionFactorChanged #-}
operationPreemptionFactorChanged :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m Double
operationPreemptionFactorChanged Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m Double
operationPreemptionFactor Operation m a b
op) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionFactorChanged_ Operation m a b
op)
  
-- | Signal when the 'operationPreemptionFactor' property value has changed.
operationPreemptionFactorChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationPreemptionFactorChanged_ #-}
operationPreemptionFactorChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationPreemptionFactorChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)
  
-- | Raised when starting to utilise the operation activity after a new input task is received.
operationUtilising :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationUtilising #-}
operationUtilising :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationUtilising = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationUtilisingSource

-- | Raised when the operation activity has been utilised after the current task is processed.
operationUtilised :: MonadDES m => Operation m a b -> Signal m (a, b)
{-# INLINABLE operationUtilised #-}
operationUtilised :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m (a, b)
operationUtilisedSource

-- | Raised when the operation activity utilisation was preempted.
operationPreemptionBeginning :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationPreemptionBeginning #-}
operationPreemptionBeginning :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionBeginning = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionBeginningSource

-- | Raised when the operation activity utilisation was proceeded after it had been preempted earlier.
operationPreemptionEnding :: MonadDES m => Operation m a b -> Signal m a
{-# INLINABLE operationPreemptionEnding #-}
operationPreemptionEnding :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding = forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Operation m a b -> SignalSource m a
operationPreemptionEndingSource

-- | Signal whenever any property of the operation changes.
operationChanged_ :: MonadDES m => Operation m a b -> Signal m ()
{-# INLINABLE operationChanged_ #-}
operationChanged_ :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m ()
operationChanged_ Operation m a b
op =
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationUtilising Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m (a, b)
operationUtilised Operation m a b
op) forall a. Semigroup a => a -> a -> a
<>
  forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (forall a b. a -> b -> a
const ()) (forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Signal m a
operationPreemptionEnding Operation m a b
op)

-- | Return the summary for the operation with desciption of its
-- properties using the specified indent.
operationSummary :: MonadDES m => Operation m a b -> Int -> Event m ShowS
{-# INLINABLE operationSummary #-}
operationSummary :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Int -> Event m ShowS
operationSummary Operation m a b
op Int
indent =
  forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Double
t0  <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op)
     Double
t1  <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op)
     Double
tx1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op)
     Double
tx2 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op)
     let xf1 :: Double
xf1 = Double
tx1 forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0)
         xf2 :: Double
xf2 = Double
tx2 forall a. Fractional a => a -> a -> a
/ (Double
t1 forall a. Num a => a -> a -> a
- Double
t0)
     SamplingStats Double
xs1 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op)
     SamplingStats Double
xs2 <- forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op)
     let tab :: [Char]
tab = forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total utilisation time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total preemption time = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
tx2 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"utilisation factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption factor (from 0 to 1) = " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Double
xf2 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"utilisation time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs1 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption time:\n\n" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs2 (Int
2 forall a. Num a => a -> a -> a
+ Int
indent)

-- | Reset the statistics.
resetOperation :: MonadDES m => Operation m a b -> Event m ()
{-# INLINABLE resetOperation #-}
resetOperation :: forall (m :: * -> *) a b.
MonadDES m =>
Operation m a b -> Event m ()
resetOperation Operation m a b
op =
  do Double
t0 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics forall (m :: * -> *). Monad m => Dynamics m Double
time
     forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationStartTimeRef Operation m a b
op) Double
t0
     forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationLastTimeRef Operation m a b
op) Double
t0
     forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalUtilisationTimeRef Operation m a b
op) Double
0
     forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b. Operation m a b -> Ref m Double
operationTotalPreemptionTimeRef Operation m a b
op) Double
0
     forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationUtilisationTimeRef Operation m a b
op) forall a. SamplingData a => SamplingStats a
emptySamplingStats
     forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (forall (m :: * -> *) a b.
Operation m a b -> Ref m (SamplingStats Double)
operationPreemptionTimeRef Operation m a b
op) forall a. SamplingData a => SamplingStats a
emptySamplingStats