Code Execution Profiling on Texas Instruments C2000
Sample times you specify in a Simulink® model determine the time schedule for running generated code on target hardware. If the target hardware has sufficient computing power, the code runs according to specified sample times in real-time. With real-time execution profiling, you can check if the generated code meets your real-time performance requirements.
You can also use code execution profiling results to enhance the design of your system. For example, if the code easily meets the real-time requirements, you can consider adding more functionality to your system to exploit available processing power. If the code does not meet real-time requirements, you can look for ways to reduce execution time. For example, you can identify tasks that require the most time and then investigate whether trade-off between functionality and speed is possible.
This topic introduces a workflow for real-time code execution profiling by showing you how to:
Configure the model for code execution profiling, and generate code.
Run generated code on target hardware.
Analyze performance through code execution profiling plots and reports.
Profiling in XCP External Mode
You can obtain real time profiling data by using the XCP External Mode infrastructure. To configure a Simulink model for real-time profiling perform these steps:
In the Simulink Editor, select Modeling > Model Configuration. In the Configuration Parameter dialog box, click External mode.
Note
Real-time profiling is supported only with
XCP on Serial
andXCP on TCP/IP
external communication modes.Profiling for
XCP on CAN
is now supported only with Metrics only.
Navigate to Code generation > Verification and select Measure task execution time.
Select the required option for Measure function execution time.
Off
– Select this option to disable function Profiling. Only Task profiling is available in this option.Coarse (referenced models and subsystems only)
– Select this option to analyse generated function code for the main model components.Detailed (all function call sites)
– Select this option to analyse generated function code for all blocks in the modelNote
Selecting
Detailed (all function call sites)
option introduces a lot of overhead due to the profiling functions.
Enter the required value for Workspace variable. It is the variable in the MATLAB® workspace used for storing data received from the target.
Select the required option for Save options. For help on selecting the save options, see Save Options.
Click Monitor & Tune from the Hardware tab of Simulink toolstrip to generate the profiling report.
After the simulation ends, a profiling report is generated with profiling metrics of different tasks/functions that are being profiled. For more information, see Code Execution Profiling on Texas Instruments C2000 Targets in XCP External Mode.
For information on code execution profiling with SIL and PIL, see Code Execution Profiling with SIL and PIL.
Save Options
Select a save option based on the type of report you want to generate. This table explains the differences between the available save options.
Summary data only | All data | Metrics only | |
---|---|---|---|
Real-time data | Available | Available | Not available. Target sends profiling data only at the end of the simulation. |
Host memory requirement | This option requires less memory as the host stores only the summary metrics
of the profiling data. For example, 11 KB data for a model running for 50 seconds. | This option requires large memory as the host stores all the data sent by the
target. For example, 1500 KB data for a model running for 50 seconds. | This option requires less memory as the host stores only the metrics data
sent by the target. For example, 12 KB of data for a model running for 50 seconds. |
SDI streaming | Available | Available | Not available |
Bandwidth requirement | Requires additional bandwidth. | Requires additional bandwidth. | Does not require additional bandwidth. |
Selecting Save Options. This section helps you to select the recommended save options in different scenarios.
All data
– Select this option, if the host has enough memory and the target has the required bandwidth to stream data.Summary data only
– Select this option, if the simulation is running for a long time and host does not have a lot of memory.Metrics only
– Select this option, if the target does not have enough time/bandwidth to stream profiling data.
Limitations
XCP stack takes up high amount of RAM and flashes on the target. This issue might occur if the target has a less amount of memory (F2802x) and a complex model is being simulated. In this case, use Profiling with Build as it has lighter memory footprint
You need a serial connection to establish an external mode connection. If Serial connection is not available on the boards, then use FTDI chips.
Profiling with Build
You can use the Profiling with Build feature when the target hardware does not have enough memory to run a Simulink model for real-time profiling in XCP External Mode
This section helps to get profiling data from the target hardware. Perform the following steps.
In the Configuration Parameter dialog box, navigate to Code generation > Verification and select Measure task execution time.
Set the number of profiling samples to be collected on the target using this command.
codertarget.tic2000.setExecutionProfileBufferLength(<modelName>, 100)
In the above command, name of the model is the first argument and number of profiling samples is the second argument.
Click Build or Build, Deploy & Start from the Hardware tab of Simulink toolstrip.
Get profiling data from the target by executing the following command.
codertarget.profile.getData(<modelName>)
Execute the following code in MATLAB Command Window to obtain the Profiling Timeline for the session you just ran. Analyze the execution timeline of different tasks and functions. Notice where the faster task pre-empts the slower one and where different functions start and end. Close the timeline when you are done.
executionProfile.timeline
For information on using C2000™ Microcontroller Blockset for real-time execution profiling of generated code, see Real-Time Code Execution Profiling.
Limitations
Real-time streaming of profiling data and SDI visualization are not supported.
Number of profiling samples to be collected on the targets must be set manually. Also, the MATLAB command must be run manually to get the data from the target.
Memory available on the target will limit the number of profiling samples that can be collected on the target.
Troubleshooting
Data Drop in Signal Logging or Code Execution Profiling
Description
Data drops can occur either in signal logging or profiling.
Action
Both Signal Logging and Profiling data streaming use the same communication channel to send data from the target. As channel bandwidth is limited, there could be data drops at high sample rates. This issue can be mitigated by performing these steps.
Stream only the data you need. If only profiling data is required, disable signal logging by clearing all the check boxes in Configuration Parameters > Data Import/Export > Save to workspace or file.
Increase the desired baud rate from SCI_x tab of Target hardware resources to get additional bandwidth to stream data at higher sample rates.