Reduce Bandwidth Usage During Code Execution Profiling
This topic shows how you can reduce communication channel bandwidth usage when running software-in-the-loop (SIL), processor-in-the-loop (PIL), or XCP-based external mode simulations with code execution profiling enabled.
Capture Main Profiling Metrics on Target Hardware
For code execution profiling, to reduce the communication channel bandwidth usage during a software-in-the-loop (SIL) simulation, processor-in-the-loop simulation (PIL), or XCP-based external mode simulation, you can capture and store only these profiling metrics on the target hardware:
Maximum execution time of code section
Average execution time of code section
Number of calls to code section
Enable the capture of the main profiling metrics by setting the configuration parameter
Save options to
Metrics only. At the end
of the simulation, Simulink® uploads the metrics from the target hardware to your development
To run a SIL simulation that generates only the main execution-time metrics:
Open the model
SILTopModel, which has two subsystems
openExample('ecoder/SILPILVerificationExample', ... supportingFile='SILTopModel.slx')
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 Configuration Parameters dialog box, select Measure task execution time, which provides execution-time metrics for the task generated from the top model
Set Measure function execution times to
Coarse (referenced models and subsystems only), which provides execution-time metrics for the functions generated from the subsystems
Specify a Workspace variable, for example,
executionProfile. If the Data Import/Export > Single simulation output check box is selected, the software creates the variable in the
Simulink.SimulationOutputobject that you specify.
From the Save options drop-down list, select
In the Prepare section, open the Settings gallery. Under Coverage, click the Coverage Collection button off.
In the Run section, click Run SIL/PIL.
To open the code execution profiling report, in the Profiling details panel, click the displayed link. In section 2, the report displays the profiled code sections as a flattened list.
The software cannot extract the hierarchy of calls to code sections because this information is not stored on the target hardware.
is not supported when Save options is set to
Specify Memory Allocation for Code Execution Profiling
You can specify memory allocation for code profiling with XCP-based external mode simulations. If you want to:
Limit the memory allocated for code profiling because your target hardware has limited resources, use the Simulink parameter
Reduce communication channel bandwidth usage, use the Simulink parameter
The parameters control memory allocation only when
CodeProfilingSaveOptions is set to
This table provides details.
Purpose — Specify the maximum amount of memory to use for code profiling.
Range — 0 to 232 - 1. Default
Data type —
set_param(gcs, CodeProfilingXCPMaxMemory="4000") get_param(gcs, 'CodeProfilingXCPMaxMemory')
Purpose — Specify maximum size of profiling data buffer that is uploaded from target hardware to development computer.
Range — 0 to
255. Default is
Data type —
set_param(gcs, CodeProfilingMaxBufferSize="200") get_param(gcs, 'CodeProfilingMaxBufferSize')
Display Absolute Time
During an XCP-based external mode simulation, the Simulation Data Inspector displays, by default, streamed signal values and execution-time metrics with respect to simulation time: after the execution of a task, the target application uploads data samples from the profiling buffer and associates all data samples from the profiling buffer with the same simulation time.
There are potential issues with streaming simulation time:
During data uploading, memory usage can be suboptimal if the target application uploads the whole profiling buffer even when the profiling buffer contains only a few data samples. The maximum size of the profiling buffer is 255 bytes.
Data uploading can slow down the execution of the target application.
If the communication channel for the external mode simulation has a low bandwidth or the target application runs tasks with high sampling rates, the generation of profiling data can exceed data uploading, which leads to data loss.
To improve bandwidth usage during data uploading, specify the display of absolute time:
set_param(modelName, 'CodeProfilingXCPUseAbsoluteTime', 'on')
When the external mode simulation runs, the target application uploads data samples only when the profiling buffer is full. The Simulation Data Inspector displays streamed values with respect to absolute time instead of simulation time.
Save options | Measure function execution times | Workspace variable | Measure task execution time