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.

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:

  3. For the readTimer block, define:

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

  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:

    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.

See Also

| |

Related Topics