Real-Time Code Execution Profiling
This example shows you how to use Embedded Coder™ Support Package for Texas Instruments™ C2000™ Processors for real-time execution profiling of generated code.
Available Versions of This Model:
C2000 LaunchPadXL TMS320F28377S (LAUNCHXL-F28377S): f28377S_RTProfiler.slx
The following figure shows the example model:
Sample times specified 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.
You can use real-time execution profiling to check whether generated code meets real-time performance requirements. Execution Profiling results can also be used to take actions to enhance design of your system. For example, if the code easily meets the real-time requirements, you may consider adding more functionality to your system to exploit available processing power. If, on the other hand, the code does not meet real-time requirements, you may look for ways to reduce execution time. For example, you can identify the tasks that require the most time and then investigate whether trade-off between functionality and speed is possible.
This example 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.
To Run the Example on the Board
1. Open the model. This model is configured for C2000 LaunchPadXL TMS320F28377S (LAUNCHXL-F28377S) target hardware.
2. Open the Modeling tab and click Model Settings or press Ctrl+E to open Configuration Parameters dialog box. Go to Code Generation > Verification.
3. Select Measure task execution time, and select Measure function execution times > Detailed (all function call sites) option. These options enable you to profile execution time for each task and function in generated code. Click OK.
4. Check that Hardware Implementation > Build Options > Build, load and run is selected. This option must be selected, or the generated executable does not download into the target.
5. Set the number of profiling samples to be collected on the target using this command.
6. Open the Hardware tab and click Build, Deploy & Start to run the code inside the target hardware.
7. Run the following code in MATLAB® Command Window to get the profiling data into MATLAB workspace:
The variable executionProfile is available in the MATLAB workspace at the end of execution of this command.
8. Run the following code in MATLAB Command Window to obtain the Profiling Report for the session you just ran. Analyze the report on different turnaround and execution times for each task and function. Close the report when you are done.
9. 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.
The code execution profiler uses an on-chip timer. If you use a processor simulator, select one that can simulate processor timers.
The model needs to run long enough to collect sufficient profiling data. This time depends on the number of profiling samples specified and the sample rates of the model. If you use a simulator, data collection can take considerably longer than when you use hardware.
The shipped target configuration file (ccxml) removes RAM initializations done by the debugger while connecting to the target. Please make sure of this behavior on using a custom target configuration file.
For asynchronously executed subsystems, code execution profiling is supported only for Hardware Interrupt block.
Profiling probe functions add the finite amount of time in actual execution time.