Main Content

Simulink Profiler

Analyze distribution of simulation execution time among model components

Description

The Simulink Profiler runs a profiling simulation of your model and produces a report you can use to analyze the distribution of simulation execution time among model components. Analyzing the report can help you:

  • Determine whether a close investigation of one or more model components might yield performance improvements for your model

  • Decide which components to investigate first

In the profiling simulation, the Simulink Profiler measures the total execution time for the simulation and the execution time for each model component, including blocks, subsystems, and model references. When the execution time for a component is unexpected, you might be able to improve the simulation performance by modifying the component implementation. For example, when an S-Function block accounts for most of the execution time, optimizing the S-function code could speed up the simulation.

The Simulink Editor has the Simulink Profiler open for the model sldemo_antiwindup.

Open the Simulink Profiler

Simulink® Toolstrip: On the Debug tab, in the Performance section, click the Performance button arrow and select Simulink Profiler.

The Debug tab of the Simulink Toolstrip has the Performance list expanded with the pointer paused on the Simulink Profiler option.

Examples

expand all

This example uses a modified version of the model sldemo_fuelsys_dd, which implements a fault-tolerant fuel control system, with a slowdown artificially inserted into the model. Use the Simulink Profiler to identify and resolve the performance issue.

Open the example, which contains the model profiling_example_fuelcontrol_model.

To open the Simulink Profiler and analyze the model execution, in the Simulink® Toolstrip, on the Debug tab, click the Performance button arrow and select Simulink Profiler. Opening the Simulink Profiler opens a tab named Profiler in the Simulink Toolstrip, a panel named Profiling Report at the bottom of the Simulink Editor, and the Property Inspector.

The Simulink Editor has the Profile tab selected for the model profiling_example_fuelcontrol_model. The Simulink Profiler is open, so the Profiler Report and Property Inspector panes are visible.

To profile the model execution, in the Profiler tab, click Profile. When the profiling simulation completes, the results appear in the Profiler Report pane. By default, the Profiler Report pane displays a table of the profiling results in the block hierarchy view. The structure and hierarchy of the data matches the structure of the model. Each row in the table provides information about the simulation execution time for a block. To view details in the results in the Profiler Report pane, click the arrow (>) next to the row in the table.

The results of the profiling simulation show that the block named Engine Gas Dynamics accounts for a large portion of the total execution time of the top model, which indicates that the block named Engine Gas Dynamics might be a good place to start looking for the source of the performance problem.

The Simulink Editor has the Profile tab selected. The Property Inspector and Profiler Report are visible. The Profiler Report pane has the top-level node of the profiling results expanded, with the row for the block named Engine Gas Dynamics selected.

Expand the row for the Engine Gas Dynamics block in the profiling results table to see how the simulation execution time is distributed across blocks inside the subsystem. Continue expanding the row in the profiling results table for the block at each level of hierarchy that accounts for the largest amount of simulation execution time. The subsystem named EGO Sensor contains a for-iterator subsystem that accounts for almost all of the execution time of the subsystem.

The Profiler Report pane has the profiling results expanded in the table to show the results for the subsystem named EGO Sensor and the for-iterator subsystem it contains.

To investigate, navigate inside the for-iterator subsystem. The block diagram inside the subsystem contains only a signal line that connects the subsystem input port to its output port. The for-iterator subsystem serves no functional purpose in the model despite accounting for so much execution time.

The contents of the for-iterator subsystem inside the subsystem named EGO Sensor.

To confirm that deleting the for-iterator subsystem block improves simulation time, navigate up the model hierarchy to the subsystem named EGO Sensor. Delete the for-iterator subsystem block, and connect the output of the MATLAB Function block named EGO Sensor to the output port.

To confirm that removing the for-iterator subsystem improved the performance, profile the modified model. In the Profiler tab, click Profile. To compare the results between the two profiling simulations, click Add Report Panel. By default, the new pane displays the most recent run. To view results from the previous run, from the Run list in the new pane, select the previous profiling simulation run.

The bottom of the Simulink Editor has two Profiler Report panes, arranged side by side. The left Profiler Report pane displays results from the first profiling simulation. The right Profiler Report pane displays the profiling results for the second run.

You can share the results of the selected profiling simulation run as an HTML report or as a MAT-file. To share the profiler report as an HTML report, from the Share menu, select Generate Report. To share the results as a MAT-file, from the Share menu, select Export. The HTML report or MAT-file is saved in the current working folder.

Tips

  • When you want to analyze and improve simulation performance, consider starting the analysis by analyzing your model and simulation configuration using the Performance Advisor.

  • After analyzing the model and simulation configuration using the Performance Advisor, you can perform deeper analysis by profiling simulations using the Solver Profiler and the Simulink Profiler.

    • The Solver Profiler analyzes the performance of the selected solver for the model and can be particularly helpful for analyzing the performance of simulations that use variable-step solvers. The profiling results help you identify when and why the step size is limited.

    • The Simulink Profiler helps you identify bottlenecks for simulation performance by analyzing the distribution of simulation execution time among model components.

Version History

Introduced in R2007b

expand all