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.
Open the rtwdemo_sil_topmodel
model, which has two subsystems
CounterTypeA
and CounterTypeB
.
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 — Top
model
SIL/PIL Mode — Software-in-the-Loop
(SIL)
To measure code execution times for the subsystems:
Click .
In the Configuration Parameters dialog box, select Measure task
execution time, which provides execution-time metrics for the task
generated from the top model rtwdemo_sil_topmodel
.
Set Measure function execution times to Coarse
(referenced models and subsystems only)
, which provides
execution-time metrics for the functions generated from the subsystems
CounterTypeA
and CounterTypeB
.
Specify a Workspace variable, for example,
executionProfile
.
From the Save options drop-down list, select
All
data
.
Click OK.
Click Settings. Under Coverage, click the Coverage Collection button off.
In the Run section, click Run SIL/PIL.
The simulation generates the variable executionProfile
in the
MATLAB® base workspace.
If you select the Data Import/Export > Single simulation output check box, the simulation creates the variable in your specified
Simulink.SimulationOutput
object.
To view streamed execution times during the simulation, open the Simulation Data
Inspector. In the Results section, click .
When the simulation is complete, the profiled model components are colored blue. To view
execution-time metrics for a profiled component, click the component. For example, subsystem
CounterTypeB
.
The display window also has links to:
The complete profiling report, which provides execution-time metrics for all profiled code sections.
The profiled code section in the code generation report.
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.
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.
If you close the model or display window, you can reopen the colored model and display window with this line command:
>> annotate(executionProfile)
At the end of the simulation, you can open this report through the metrics display window or with this line command:
>> report(executionProfile)
Part 1 provides a summary. Part 2 contains information about profiled code sections. Expand and collapse profiled sections in part 2 by clicking [+] and [–] respectively. This graphic shows fully expanded sections.
The report contains time measurements for:
The model initialization function
rtwdemo_sil_topmodel_initialize
.
A task represented by the step function rtwdemo_sil_topmodel_step [0.1
0]
.
Functions generated from the subsystems CounterTypeA
and
CounterTypeB
.
You can go to a profiled code section in the Generated Code view of the Code Generation
Report. In the Code Execution Profiling Report, on a code section row, click the icon . For example, if you click the icon for the
rtwdemo_sil_topmodel_initialize
task, you see the measurement probes
around the call site in the SIL application.
If you click the icon for a function, the call site is highlighted.
From the Code Execution Profiling Report, you can trace the model component that
produces a set of metrics. For example, in the Section column, if you
click the CounterTypeA
hyperlink, the Simulink Editor identifies the subsystem.
By default, the report displays time in nanoseconds (10-9 seconds). You can specify the time unit and numeric display format. For example, to display time in microseconds (10-6 seconds), use the following command:
report(executionProfile,... 'Units', 'Seconds', ... 'ScaleFactor', '1e-06', ... 'NumericFormat', '%0.3f')
The report displays time in seconds only if the timer is calibrated, that is, the number of timer ticks per second is known. On a Windows® machine, the software determines this value for a SIL simulation. On a Linux® machine, calibrate the timer manually. For example, if your processor speed is 1 GHz, specify the number of timer ticks per second:
executionProfile.TimerTicksPerSecond = 1e9;
To view execution-time metrics for a task or function in the Command Window, on the
corresponding row, click .
>> executionProfile.Sections(5) ExecutionTimeCodeSection with properties: Name: 'CounterTypeA' Number: 5 ExecutionTimeInTicks: [1×101 uint64] SelfTimeInTicks: [1×101 uint64] TurnaroundTimeInTicks: [1×101 uint64] TotalExecutionTimeInTicks: 12998 TotalSelfTimeInTicks: 12998 TotalTurnaroundTimeInTicks: 12998 MaximumExecutionTimeInTicks: 374 MaximumExecutionTimeCallNum: 60 MaximumSelfTimeInTicks: 374 MaximumSelfTimeCallNum: 60 MaximumTurnaroundTimeInTicks: 374 MaximumTurnaroundTimeCallNum: 60 NumCalls: 101 ExecutionTimeInSeconds: [1×101 double] Time: [101×1 double]
To display measured execution times in the Simulation Data Inspector, click the icon . Use the Simulation Data Inspector to manage and compare
plots from various simulations.
To display the execution-time distribution, click the icon .
In this example, to create the histogram, the software uses these commands:
section=executionProfile.Sections(5); data=section.ExecutionTimeInSeconds; histogram(data, 30,'Normalization','probability');
To observe how code sections are invoked over the execution timeline, use the
timeline
function.
The following table describes the information provided in the code section profiles.
Column | Description |
---|---|
Section | Name of task, top model, subsystem, or Model block. Click the link to go to the model. With a task, the sample period
and sample offset are listed next to the task name. For example, |
Maximum Turnaround Time (Simulink Real-Time™ and support packages in real-time mode) | Longest time between start and end of code section. Includes preemption time. |
Average Turnaround Time (Simulink Real-Time and support packages in real-time mode) | Average time between start and end of code section. Includes preemption time. |
Maximum Execution Time | Longest time between start and end of code section. |
Average Execution Time | Average time between start and end of code section. |
Maximum Self Time | Maximum execution time, excluding time in child sections. |
Average Self Time | Average execution time, excluding time in child sections. |
Calls | Number of calls to the code section. |
![]() | Icon that you click to see the profiled code section in the Generated Code view of the Code Generation Report. The code section can be a task or a function. The specified workspace variable, for example,
|
![]() | Icon that you click to display the profiled code section in the Command
Window. Equivalent to executing the command
The
specified workspace variable, for example, |
![]() | Icon that you click to display measured execution times with Simulation Data Inspector. The specified workspace variable, for example,
|
![]() | Icon that you click to display the execution-time distribution for the profiled code section. The specified workspace variable, for
example, |
To help you to decide whether you can run the generated code on your target hardware, part 3 of the code execution profiling report provides CPU workload information:
Average and maximum CPU time required by each task during a sample period.
Total CPU usage in a sample period.
The software computes the percentage of CPU time assigned to a task by dividing task execution time by sample time.
The software generates CPU Utilization only if the number of timer ticks per second is specified.
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
baseline for rtwdemo_sil_topmodel
.
In the Workspace browser, rename executionProfile
to
executionProfileBaseline
.
Run another SIL simulation.
To create a report that compares the latest performance against the baseline, in the Command Window, run:
report(executionProfile,'baseline', executionProfileBaseline)
In part 3 (Comparison with Baseline Performance) and part 4 (CPU Utilization), the report provides a comparison 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.