MATLAB Examples


Sequence Diagram Demo

UML Sequence Diagrams are a good way to express flow control in a program, or show the lifetime of objects in an OO system.

This script shows the usage of a sequence diagram API I wrote specifically for instrumenting C source code to help identify lifetime behaviors of objects in HG2.

% Author: Eric Ludlam
% Copyright (c) 2006 The MathWorks Inc.

Starting a new diagram

New diagrams are started with an initialization function including the diagram name.

sequencestart('Demo Sequence');

Objects and Links

An object is represented as a vertical bar with a name on top. A link represents control flow from one object to another, usually with some name associated with the activity.

This sequence diagram tool has no API for creating nodes, only links to nodes. This makes it very easy to write scripts from C code. New nodes are created when needed, with lifetime start occuring when first referenced.





When exiting an object (from a named link) you can use a return function which calculates the return trip. This also makes it easy to add the code to a C function since you do not need to know where you were called from when writing the script.




Objects that are destroyed end with an X at the time of the last returnlink. Objects that are not destroyed end in a red triangle indicating that they probably continue to live, but the box ends when last reference to avoid a messy diagram.