Documentation Center

  • Trial Software
  • Product Updates

Observe Events

Techniques for Observing Events

The SimEvents® debugger can help you observe events and the relative sequencing of simultaneous events. For details, see .

The next table describes some additional observation techniques. Each technique focuses on a particular kind of event. These techniques indicate the simulation time at which events occur but do not indicate relative sequencing of simultaneous events. Key tools are the Instantaneous Event Counting Scope block, Signal Scope block, and Discrete Event Signal to Workspace block.

EventObservation Technique
Counter resetIn the counter block #d output signal, observe falling edges. Alternatively, use a branch line to connect the input signal to an Instantaneous Event Counting Scope block.
Delayed restart 
Entity advancementIn the block from which the entity departs, observe increases in the #d output signal.
Entity destructionIn the Entity Sink block, observe increases in the #a output signal. The Instantaneous Entity Counting Scope block provides a plot in place of a #a signal.
Entity generation

In the entity generator block, observe values of the pe and #d output signals. Upon entity generation, you see one of the following outcomes:

  • The generated entity departs immediately. #d increases and pe does not change.

  • The generated entity cannot depart immediately. pe increases.

To build a concrete example, adapt the technique described in Observe Service Completions.

Entity request 
Function callIf the block issuing the function call provides a #f1 output signal, observe its increases. Otherwise, add a Function-Call Split block from the Simulink® library to your model. Connect the input port of the Function-Call Split block to the block issuing the function call. Connect one output port of the Function-Call Split block to the block reacting to the function-call. Connect the second output port of the Function-Call Split block to an Instantaneous Event Counting Scope block.
Gate (opening or closing)In the Enabled Gate block, use a branch line to connect the en input signal to an Instantaneous Event Counting Scope block. Rising trigger edges of the input signal indicate gate-opening events, while falling trigger edges of the input signal indicate gate-closing events.
Memory readIn the Signal Latch block, observe sample time hits in the out output signal.
Memory writeIn the Signal Latch block, observe sample time hits in the mem output signal.
Port selectionIf the block has a p input signal, use a branch line to connect the p signal to an Instantaneous Event Counting Scope block that is configured to plot value changes. For the Input Switch or Output Switch block, an alternative is to observe the last output signal.
PreemptionIn the server block, observe increases in the #p output signal.
ReleaseIn the Release Gate block, use a branch line to connect the input signal to an Instantaneous Event Counting Scope block.
Sample time hitUse a branch line to connect the signal to an Instantaneous Event Counting Scope block.
Service completion

For Single Server blocks, observe values of the pe and #d output signals. Upon service completion, you see one of the following outcomes:

  • The entity departs immediately. #d increases, and pe does not change.

  • The entity cannot depart immediately. pe increases.

To build a concrete example, adapt the technique described in Observe Service Completions.

For Infinite Server and N-Server blocks, observe values of the #pe and #d output signals. Upon service completion, you see one of the following outcomes:

  • The entity departs immediately. #d increases, and #pe does not change.

  • The entity cannot depart immediately. #pe increases.

For a concrete example, see Observe Service Completions.

Storage completion

In the switch block, observe values of the pe and #d output signals. Upon storage completion, you see one of the following outcomes:

  • The entity departs immediately. #d increases, and pe does not change.

  • The entity cannot depart immediately. pe increases.

To build a concrete example, adapt the technique in Observe Service Completions.

SubsystemIn any output signal from the subsystem, observe sample time hits. Alternatively, connect a Discrete Event Signal to Workspace block to any signal inside the subsystem. Then observe the times at which the variable in the workspace indicates a sample time hit of the signal.
TimeoutIn the storage block from which the entity times out, observe increases in the #to output signal.
TriggerUse a branch line to connect the signal to an Instantaneous Event Counting Scope block.
Value changeUse a branch line to connect the signal to an Instantaneous Event Counting Scope block.

For examples that use one or more of these techniques, see:

Also, Detect Collisions by Comparing Events describes how to use a Signal Latch block to observe which of two types of events are more recent.

Observe Service Completions

The following example (open modelmodel) creates a stem plot showing when an N-Server block completes service on each entity. The example also writes a signal, num_svc, to the MATLAB® workspace that indicates when each service completion occurred.

Results

The model produces a plot in which each stem indicates a service completion. The timing depends on the entity generation, service completion, gate opening, and gate closing times in the model.

After the simulation is over, to form a vector of service completion times, enter the following code:

t_svcp = num_svc.time

The output is:

t_svcp =

         0
    0.4542
    0.9077
    1.1218
    1.3868
    2.3430
    2.3570
    2.9251
    2.9370
    3.5592
    4.3933
    4.8554

The first value in the t_svcp vector represents the initial value of the #f1 signal. Subsequent values represent service completion times.

Computation Details

In this model, the Signal-Based Function-Call Generator block determines when service completions in the N-Server block occur.

The Signal-Based Function-Call Generator block executes when either #d or #pe increases (thus increasing the output of the Add block) because a service completion has one of these consequences:

  • The entity departs immediately. #d increases, while #pe does not change.

  • The entity cannot depart immediately, so it becomes a pending entity. #pe increases, while #d does not change. At a particular time instant, an entity cannot depart the server if the Enabled Gate block is not currently enabled by the output of the Pulse Generator block.

Each time a service completion occurs, the Signal-Based Function-Call Generator block:

  • Generates a function call at the f1 output port

  • Increases the value of the #f1 output signal

Detect Collisions by Comparing Events

The example below (open modelmodel) aims to determine whether an entity is the only entity in an infinite server for the entire duration of service. The model uses the Signal Latch block to compare the times of two kinds of events and report which kind occurred more recently. This usage of the Signal Latch block relies on the block's status output signal, st, rather than the default in and out ports.

In the model, entities arrive at an infinite server, whose #n output signal indicates how many entities are in the server. The Signal Latch block responds to these signal-based events involving the integer-valued #n signal:

  • If #n increases from 0 to a larger integer, then

    • rtr has a rising edge.

    • The Signal Latch block processes a read event.

    • The Signal Latch block's st output signal becomes 0.

  • If #n increases from 1 to a larger integer, then

    • wtr has a rising edge.

    • The Signal Latch block processes a write event.

    • The Signal Latch block's st output signal becomes 1.

  • If #n increases from 0 to 2 at the same value of the simulation clock, then it also assumes the value 1 as a zero-duration value. As a result,

    • rtr and wtr both have rising edges, in that sequence.

    • The Signal Latch block processes a read event followed by a write event.

    • The Signal Latch block's st output signal becomes 1.

By the time the entity departs from the Infinite Server block, the Signal Latch block's st signal is 0 if and only if that entity has been the only entity in the server block for the entire duration of service. This outcome is considered a success for that entity. Other outcomes are considered collisions between that entity and one or more other entities.

This example is similar to the CSMA/CD subsystem in the Communication Protocol Modeling in an Ethernet LANCommunication Protocol Modeling in an Ethernet LAN example.

Was this topic helpful?