Main Content

Execution Profiling for Generated Code

Use code execution profiling to:

  • Determine whether the generated code meets execution time requirements for real-time deployment on your target hardware.

  • Identify code sections that require execution speed improvements.

The following tasks represent a general workflow that uses code execution profiling:

  1. With the Simulink® model, design and optimize your algorithm.

  2. Configure the model for code execution profiling, and generate code.

  3. Execute generated code on target hardware. For example, you can perform real-time execution with Simulink Real-Time™ or a target support package.

    If you are using Embedded Coder®, you can run software-in-the-loop (SIL), processor-in-the-loop (PIL), and XCP-based external mode simulations on your development computer or embedded target hardware.

  4. Analyze execution speed through code execution profiling plots and reports. For example, check that the algorithm code satisfies execution time requirements for real-time deployment:

    • If the algorithm code easily meets the requirements, consider enhancing your algorithm to exploit available processing power.

    • If the code cannot be executed in real time, look for ways to reduce execution time.

      Identify the tasks that require the most time. For these tasks, investigate whether trade-offs between functionality and speed are possible.

      If your target is a multicore processor, distribute the execution of algorithm code across available cores.

  5. If required, refine the model and return to step 2.

  6. Create an aggregate of execution-time profiles by running model simulations for your test cases. Use the Code Profile Analyzer to process the aggregate. For each task, identify the longest execution time and corresponding test case.

  7. When you have a sufficient number of test cases, you can use coder.profile.test.runTests (Embedded Coder) to automate the analysis of task execution times.

To find information about code execution profiling with Simulink products, use the following table.

Type of ExecutionTarget Relevant Products See
Software-in-the-loop (SIL) Development computer Embedded Coder
Processor-in-the-loop (PIL) Embedded hardware or instruction set simulator Embedded Coder
XCP external modeDevelopment computer or custom hardwareEmbedded Coder
Real-time executionSimulink Real-TimeSimulink Coder™, Simulink Real-Time

Related Topics