View and Compare Code Execution Times
You run a software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation that produces execution-time metrics for tasks and functions in your generated code. During the simulation, you can use the Simulation Data Inspector to observe streamed execution times. At the end of the simulation, you can:
View execution-time metrics for a profiled model component.
Open a report of execution-time metrics for all profiled components. Through report icons, you can view, for example, the profiled code section and the execution-time distribution for each profiled function.
Use the Simulation Data Inspector to plot and compare execution times from various simulations.
Run SIL Simulation That Generates Execution-Time Metrics
rtwdemo_sil_topmodel model, which has two subsystems
CounterTypeB. At the command line,
To run a SIL simulation that generates execution-time metrics, on the SIL/PIL tab:
In the Mode section, select SIL/PIL Simulation Only.
In the Prepare section, specify these settings:
System Under Test —
SIL/PIL Mode —
To measure code execution times for the subsystems, in the Prepare section:
Click the Task Profiling button on. This action selects the Measure task execution time configuration parameter, which provides execution-time metrics for the task generated from the top model
Click the Save Options button until it displays
ALL DATA. This action sets the Save options configuration parameter to
Click the Functions button until it displays
COARSE. This action sets the Measure function execution times configuration parameter to
Coarse (referenced models and subsystems only), which provides execution-time metrics for the functions generated from the subsystems
Under Coverage, click the Coverage Collection button off, which disables code coverage analysis. You collect code coverage data separately from profiling data.
Click the Settings button to open the Configuration Parameters dialog box. On the Data Import/Export pane, clear Single simulation output.
To view streamed execution times during the simulation, open the Simulation Data Inspector. In the Results section, click .
In the Run section, click Run SIL/PIL.
In the MATLAB® base workspace, the simulation generates a variable with the default name,
executionProfile, which stores the execution profiling data. You can
specify an alternative name through the Workspace variable
If the Data Import/Export > Single simulation output check box is selected, the simulation creates the variable in your specified
When the simulation is complete, the profiled model components are colored blue and the
Code view displays the generated code. To view execution-time metrics for a profiled
component, click the component. For example, subsystem
For top-model SIL or PIL simulations, the Simulink® Editor background is also colored blue. When you click the background, the display window shows execution-time metrics for top-model tasks.
You can trace from a model component to the profiled code section in the Code view. In
the Profiling display window, on a code section row, click the icon . For example, if you click the model background and then
click the icon for the
rtwdemo_sil_topmodel_initialize task, you see the
measurement probes around the call site in the SIL application. To see the profiling metrics
for the component, place your cursor on the call site.
If you click the icon for a function, the call site is highlighted. The Code view displays the average execution time and number of function calls to the left of the code line. In this example, the maximum and average times are the same because the initialization function was called only one time.
The Profiling display window also has links to:
The complete profiling report, which provides execution-time metrics for all profiled code sections.
The Simulation Data Inspector, which allows you to plot and compare execution-time measurements for the profiled code section.
The execution-time distribution for the profiled code section.
Pie charts that show the relative execution times of caller and called functions
If you close the model or display window, you can reopen the colored model and display window with this line command:
Code Execution Profiling Report Sections
At the end of the simulation, you can open the report through the Profiling display window or by using this line command:
View Code Execution Profiles for Multiple Model Blocks
You can configure a top-model simulation that runs multiple Model blocks in SIL or PIL mode with code execution profiling enabled. When you run the simulation, it generates separate code execution profiling reports for the referenced models.
Open the top model that contains Model blocks. For example, at the command line, type
On the SIL/PIL tab, in the Mode section, specify SIL/PIL Simulation Only.
In the Prepare section, specify these settings:
System Under Test ––
Model blocks in SIL/PIL mode
Top Model Mode ––
Counter Ais already configured to run in SIL mode. For Model block
Counter B, set the block parameter Simulation mode to
Both Model blocks reference the model
rtwdemo_sil_counter. To generate execution times for the Model blocks:
On the Model Block tab, in the Actions section, click Open as Top Model.
On the SIL/PIL tab, in the Settings gallery, click Functions to
COARSE, which sets the Measure function execution times configuration parameter for
Coarse (referenced models and subsystems only).
To run a top-model simulation:
On the SIL/PIL tab, in the Run section, click Run SIL/PIL.
Since the Single simulation output check box is selected, the simulation creates the variable
When the simulation is complete, to show the number of Model blocks that are profiled, in the Command Window, enter:
NumOfReports = 2
To open the report for
CounterA, the first Model block, run:
In the Summary section, the report provides a link to the second Model block report. To open the report for
CounterB, click Open report or run:
For more information about generating function execution times for model reference hierarchies, see Control Profiling Granularity.
Compare Code Execution-Time Performance Against Baseline
You can create a code execution profiling report that compares the performance of the
generated code against the performance of a reference version. For example, suppose you want
to use the current execution-time metrics in
executionProfile as the
In the Workspace browser, rename
Run another SIL simulation.
To create a report that compares the latest performance against the baseline, in the Command Window, run:
In the report, the Comparison with Baseline Performance and CPU Utilization sections provide comparisons of execution-time metrics. The differences in execution-time metrics are color-coded:
Red — An increase in execution times or CPU usage.
Green — A decrease in execution times or CPU usage.
Black — No change.
Visualize Task Scheduling
You can use the Simulation Data Inspector to visualize task scheduling and the order of function calls. At the end of the simulation, perform one of these actions: