MATLAB Examples

Real-Time Code Execution Profiling

This example shows you how to use Embedded Coder™ Support Package for Texas Instruments C2000 Processors and Embedded Coder Support Package for Texas Instruments C2000 F28M3x Concerto Processors for real-time execution profiling of generated code.


Available versions of this model:


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 Model Configuration Parameters on the toolbar, select Code Generation and the Verification.

3. Click both Measure task execution time and Measure function execution time checkboxes. These options enable you to profile executiontime for each task and each function in generated code. Click OK.

4. Click Deploy to Hardware in the toolbar. This action starts generating and building code for your model. The generated executable will be downloaded into the target only if Build, load and run is selected in the Build Options tab under Hardware Implementation. This will start running the code inside the target hardware.

5. Run the following code in MATLAB Command Window to get the profiling data into MATLAB workspace. The variable executionProfile will be available in the MATLAB workspace at the end of execution of this command.


6. 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.

7. 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.


This example introduced the workflow for real-time profiling of generated code. It showed you how to profile execution of both tasks and functions in generated code.