Measure Point-to-Point Delays
Determine how long each entity takes to advance from one block to another, or how much time each entity spends in a particular region of your model. To compute these durations, you can measure time durations on each entity that reaches a particular spot in the model. A general workflow is:
Create an attribute on the entity that can hold the time value.
When the entity reaches a particular point in the model, set the current value of time on the attribute. Call a Simulink® function that contains a Digital Clock block.
When the entity reaches the destination, compute the time interval by passing the attribute value to another Simulink function that compares it to the current simulation time.
Basic Example Using Timer Blocks
This example lets you see if a FIFO order or prioritized queue for customers results
in a shorter wait time. The startTimer
and
readTimer
Simulink functions jointly perform the timing computation. This example uses the
Mean block from the DSP System Toolbox™ to calculate average times.
This example has four Simulink Function blocks. Two define timer functions, startTimer and readTimer. The other functions calculate average times.
In a new model, drag the blocks shown in the example and relabel and connect them as shown.
For the startTimer block, define:
For the readTimer block, define:
For the
avg_time_fifo(t)
andavg_time_priority
Simulink Function blocks, insert a Mean block, for example:For the Entity Generator block:
In the Entity type tab, add two attributes,
ServiceTime
andTimer
.In the Entity actions tab, set the two attribute values:
entity.ServiceTime = exprnd(3); entitySys.priority = randi(2);
In Entity Queue:
In the Main tab, set Queue type to FIFO.
In the Event actions tab, call the
startTimer
function for the Entry action:entity.Timer = startTimer();
In Entity Queue1:
In the Main tab, configure the block to be a priority queue with a priority source of
entitySys.priority
:In the Event actions tab, call the
startTimer
function for the Entry action:entity.Timer = startTimer();
For both Entity Server blocks:
Set Service time source to
Attribute
.Set Service time attribute name to
ServiceTime
.
For Entity Terminator, call the
readTimer
andavg_time_fifo
functions for the Entry event:% Read timer elapsedTime = readTimer(entity.Timer); % Compute average avg_time_fifo(elapsedTime);
For Entity Terminator1, call the
readTimer
andavg_time_priority
functions for Entry event:% Read timer elapsedTime = readTimer(entity.Timer); % Compute average avg_time_priority(elapsedTime);
Save and run the model.
See Also
Entity Generator | Entity Replicator | Simulink Function