Main Content

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:

  1. Create an attribute on the entity that can hold the time value.

  2. 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.

  3. 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.

Snapshot of example Simulink model that creates entities from the Entity Generator block, and passes them to the Entity Replicator block for duplication. Two output ports lead duplicated entities to two Entity Queue blocks of FIFO order and prioritized entity order, each connected to an Entity Server block, and subsequently an Entity Terminator block. The model also contains two Simulink functions that compute timing values, and two other Simulink functions that calculate average time spent by an entity in its respective queue. These calculated values are shown in the respective Display blocks.

This example has four Simulink Function blocks. Two define timer functions, startTimer and readTimer. The other functions calculate average times.

  1. In a new model, drag the blocks shown in the example and relabel and connect them as shown.

  2. For the startTimer block, define:

    Snapshot of startTimer Simulink function block with function interface, t = startTimer(), that contains a Digital Clock block.

  3. For the readTimer block, define:

    Snapshot of readTimer Simulink function block with function interface, y = readTimer(t), that subtracts time read at start from the current Digital Clock reading using the Subtract block.

  4. For the avg_time_fifo(t) and avg_time_priority Simulink Function blocks, insert a Mean block, for example:

    Snapshot of avg_time_fifo Simulink function block with function interface, avg_time_fifo(t), that connects input to the Mean block. The Mean block, in turn, is connected to output port Out1.

  5. For the Entity Generator block:

    1. In the Entity type tab, add two attributes, ServiceTime and Timer.

    2. In the Entity actions tab, set the two attribute values:

      entity.ServiceTime = exprnd(3);
      entitySys.priority = randi(2);
  6. In Entity Queue:

    1. In the Main tab, set Queue type to FIFO.

    2. In the Event actions tab, call the startTimer function for the Entry action:

      entity.Timer = startTimer();
  7. In Entity Queue1:

    1. In the Main tab, configure the block to be a priority queue with a priority source of entitySys.priority:

      The Block Parameters dialog box of the Entity Queue1 block with Main tab highlighted. In the Main tab, the Capacity text field is set to 100, Queue type drop-down field is set to Priority, Priority source drop-down field is set to entitySys.priority, Sorting direction drop-down field is set to Ascending, and Entity arrival source drop-down field is set to Input port.

    2. In the Event actions tab, call the startTimer function for the Entry action:

      entity.Timer = startTimer();
  8. For both Entity Server blocks:

    1. Set Service time source to Attribute.

    2. Set Service time attribute name to ServiceTime.

  9. For Entity Terminator, call the readTimer and avg_time_fifo functions for the Entry event:

    % Read timer
    elapsedTime = readTimer(entity.Timer);
    
    % Compute average
    avg_time_fifo(elapsedTime);
  10. For Entity Terminator1, call the readTimer and avg_time_priority functions for Entry event:

    % Read timer
    elapsedTime = readTimer(entity.Timer);
    
    % Compute average
    avg_time_priority(elapsedTime);
  11. Save and run the model.

    Snapshot of the saved and run example Simulink model. The Display block connected to the avg_time_fifo(t) Simulink function block shows a value of 26.54, while the Display block connected to the avg_time_priority(t) Simulink function block shows a value of 11.37.

See Also

| |

Related Topics