Prev Next

State Analyzer

The State Analyzer is a feature that can analyze, detect and record states for instances of a class. The feature works by combining a state definition, defined on a class as a constraint, and markers called State points. It is supported on any languages supported by the Execution Analyzer, including Microsoft. NET, Mono, Java and native C++.

We begin by selecting a class and composing our state definition.

We can get a picture of all the state definitions we've defined by placing the class on a diagram and linking notes to the class that themselves link to a particular state definition constraint. We explain how to do that in a following section.

State points are set by placing one or more markers in relevant source code.

The program to be analyzed is ran using the State Analyzer control. When the Execution Analyzer encounters any State point, the current instance of the class is analyzed.  Where the value domain of the instance matches the state definition, a state is recorded. Each time the instance varies new states are thus detected.  The control lists each state as they are discovered. Under each state the control lists the discrete set of transitions to other states made by instances of the class.

The information can be used to create a State Machine.

Using the same information we can easily produce a Heat Map  The example below shows a Train class, its 'Bulletin' State Definition (as a linked,note), and the Heat Map it produced. The Figures in the map are  percentages. From the map we can observe that trains where in the 'In Transit' state 46% of the time.

This is the analysis for the 'Bulletin' State Definition that produced the above Heat Map.

Access

Ribbon

Execute > Analyze > Recorder > Open Recorder > State Analyzer

Start > Properties > Constraints

State Definitions

State definitions are composed in the constraints properties of a class element. The constraint type should be named StateDefinition.name, where name is your choice of title for the definition. These titles are listed in the combo box of the State Analyzer whenever a class is selected. You select a single definition from this combo prior to running the program. The State definition In the above example is named StateDefinition.Location. It defines states based on the location of instances of the  CTrain class.

State Definitions are composed of one or more specifications. Each state specification begins with the keyword 'statedef' whicb is then followed  by one or more statements. Statements define the constraints that describe the state, and a optionally a variable whose value can be used to name the state. Statements are enclosed in curly brackets and are terminated with a semi colon like so:

statedef {

      Location=0;

      Departing.Name;

}

Naming states using variables

In this example, Location is a constant and Departing.name is a variable. An additional statement follows the constraints and instructs the name of the State to be assigned from the variable value.  Here is the definition with the naming directive.

statedef {

      Location=0;

      Departing.Name;

}

name=Departing.Name;

Naming states using literals

In this example the state definition only contains constants and the state is named using a literal.

statedef {

    Location=100;

}

name='Central';

A single State Definition defining multiple State specifications.

statedef {

    Passengers > 100;

}

name=Busy;

statedef {

    Passengers >= 50;

}

name=Quiet;

statedef {

    Passengers < 50;

}

name=Very Quiet;

statedef {

    Passengers = 0;

}

name=Idle;

Default State

A State definition can specify a default 'catch all' state that will describe the state of an instance when no other state holds true. You define a default state for the definition with a similar statement illustrated below.

statedef {

      Location=0;

      Departing.Name;

}

name=Departing.Name;

default=Moving;

In the above example, while executing, any instance detected having a non zero 'Location' attribute will be recorded as being in the 'Moving' state.

You can choose to exclude the recording of the default state by disabling the 'Include default state' option on the drop down menu of the State Analyzer toolbar. This would exclude transitions to any 'default' state being recorded.

Creating Notes on a Class element that display State Definitions

This section describes how to create the class diagram above, that shows all the State Definitions defined for the class.

Actions

Display a class diagram

Open an existing class diagram or create a new one.

Create a link to the class element

Drag the class of interest on to the diagram as a link.

Create a note element

Create a note element on the diagram and link it to the class.

Link the note to the State Definition

Select the link between the note and the class and using it's context menu select the 'Link Note to Element Feature' option.

Choose the definition to display on the Note

From the element dialog, choose 'Constraints' from the drop combo. Any defined State Definitions will be listed for you to choose from.

Repeat

Repeat the procedure for any other State Definitions on the class.