Main Content

Solver Profiler

Identify solver performance bottlenecks

Description

Use the Solver Profiler to examine solver and model behavior to identify issues that can contribute to poor simulation performance.

Use the Solver Profiler to analyze a model for patterns that affect its simulation. The Solver Profiler presents graphical and statistical information about the simulation, solver settings, events, and errors. You can use this data to identify locations in the model that caused simulation bottlenecks.

In addition, there are multiple factors that can limit the simulation speed. The Solver Profiler logs and reports all the major events that occur when simulating a model:

  • Zero-crossing events

  • Solver exception events

  • Solver reset events

  • Jacobian computation events

These events are common and necessary for an accurate simulation. However, they do incur computational cost and frequent occurrences can slow down or even stall the simulation.

Available actions

  • Trace

  • Configure

  • Explore

Information Panes

  • Statistics

  • Step Size

  • Suggestions

Open the Solver Profiler

  • Simulink® Toolstrip: On the Debug tab, in the Performance section, click Performance Advisor , then select Solver Profiler.

    On the Debug tab, the Performance advisor list is expanded with the pointer paused on the Solver Profiler option.

  • Solver information menu: To open the Solver information menu, click the hyperlink on the right of the status bar at the bottom of the Simulink Editor. Then, click Solver Profiler .

    The Solver information menu has the pointer paused on the button that opens the Solver Profiler.

Examples

expand all

Use the Solver Profiler to locate the source of zero crossings that occur in simulation for a model of a bouncing ball.

Open the model BouncingBallWithSwitch.

Open the Solver Profiler. In the Simulink™ Toolstrip, on the Debug tab, in the Performance section, click the Performance Advisor button arrow. Then, select Solver Profiler.

In the Solver Profiler, click Run. The Solver Profiler simulates the model and collects information about solver events that occur. When the simulation completes, the Solver Profiler displays information in the Statistics pane and a plot of the step size calculated for each step of the simulation.

In the Statistics pane, scroll down to view the event information, which shows that 45 zero-crossing events occurred during simulation from one source.

To view information about the source of the zero-crossing events, select the Zero Crossing tab. The zero crossing events come from the Switch block.

To annotate the plot of the step sizes with the zero-crossing events, in the Statistics pane, click the value for the Total Zero Crossings row. The yellow dots indicate when each zero crossing occurred. Where the zero crossings occurred, the step size decreased significantly.

To highlight in the block diagram the Switch block that produced the zero crossings, in the Zero Crossing tab, select the block path. Then, in the States Explorer Toolstrip, in the Trace section, click Highlight Block.

Related Examples

Parameters

expand all

Configure

Time, in seconds, of the simulation that the profiler starts analyzing the model. This is not the same as the start time of the simulation.

Time, in seconds, of the simulation to which the profiler should profile the model. By default, the analysis continues until the end of the simulation. Changing this parameter does not change the stop time of the model which you specify in the Model Configuration Parameters.

A value less than the configured stop time of the model stops the profiling and simulation at StopTime.

Maximum number of events that are logged. If the number of logged events reaches this value and memory is available, increase BufferSize. If memory is limited, consider lowering the value.

By default, the profiler does not save the states of the model. Enabling this parameter configures the profiler to save the states to the profiler data MAT file.

If you select this parameter, it will enable the States explorer.

Enable this parameter to save Simscape states to the profiler data MAT file.

If you select this parameter, it will enable the Simscape explorer.

Enable this parameter to save zero crossing information to the profiler data MAT file

If you select this parameter, it will enable the Zero-Crossing explorer.

Option to log the solver Jacobian matrices to memory. This option is useful for simulations that use implicit solvers. For a comparison of solvers, see Compare Solvers.

For a more detailed explanation of the solver Jacobian, see Choose a Jacobian Method for an Implicit Solver.

Log stiffness analysis Simscape states, specified as an array. This parameter provides an array of time points that you want to log the Simscape Stiffness states to the profiler data MAT file. Enable this parameter to show Simscape Stiffness tab in the Suggestion Pane. 

Enable this parameter to log the stiffness analysis of Simscape states to the profiler data MAT file. For more information on Simscape representation of stiffness and other physical system concepts, see How Simscape Models Represent Physical Systems (Simscape)

Click Rule Customization in the Solver Profiler to access the rule set. You can change the thresholds for most of these rules and also select which rules you want to apply selectively during a simulation run.

To modify a rule, enable its customization and then enter a desired threshold value.

Custom Rule Set

You can override the settings on the Rule Set dialog box by specifying a custom rule set.

Create a rule set as a MATLAB® script and specify the path to the script in the Custom Rule Set section of the Rule Set dialog box.

A simple rule set example looks as follows:

function diagnosticsString = customRule(profilerData)
		if isempty(profilerData.zcEvents)
			diagnosticsString{1} = 'No zero crossing event detected.';
		else
			diagnosticsString{1} = 'Zero-crossing events detected.';
		end
end
The input to the function is an array of structures called profilerData. This array of structures organizes all the information that the Solver Profiler collects during a profiling run. It contains the following substructures.

SubstructureFields
stateInfo: Stores information on block states
  • name: Block name

  • value: State values

  • blockIdx: Block ID

blockInfo: Cross-reference of blocks and state IDs
  • name: Block name

  • stateIdx: State ID

zcSrcInfo: Stores information on blocks causing zero crossing events
  • name: Block name

  • blockIdx: Block ID

zcEvents: Cross-reference of the time stamps of zero crossing events and the corresponding state IDs
  • t: Event timestamp

  • srcIdx: Block ID

exceptionEvents: Cross-reference of exception event timestamps, the ID of the corresponding state that caused the event, and the cause.
  • t: Event timestamp

  • stateIdx: State ID

  • cause: Cause of exception

resetTime: Stores timestamps of solver resets.None
tout: Stores simulation times.None

View

Enable this parameter to highlight solver exception events in the Step Size plot of the Solver Profiler.

Enable this parameter to highlight solver reset events in the Step Size plot of the Solver Profiler.

Enable this parameter to highlight Jacobian update events in the Step Size plot of the Solver Profiler.

Enable this parameter to highlight zero crossing events in the Step Size plot of the Solver Profiler.

Version History

Introduced in R2016a