Main Content

Execution-Time Profiling for Generated Code

Use execution-time 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 simulate your algorithm.

  2. Configure the model for code execution profiling, generate code, and execute generated code on target hardware. For information about choosing a simulation mode, see the table below.

  3. Analyze execution speed using code execution profiling plots and reports. For example, you can:

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

  5. 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. For each task, identify the longest execution time and corresponding test case.

The following table provides information about execution-time profiling with Simulink products.

Type of ExecutionTarget Relevant Products Goals
Software-in-the-loop (SIL) Development computer Embedded Coder®

Run generated code on your development computer. Although your development computer may be different from the target hardware, SIL profiling can give an indication about performance trends. For example, if execution times double in SIL simulations, they are also likely to increase on the target hardware.

During development, use SIL profiling to:

  • Measure execution times for generated tasks by enabling only task profiling.

  • Measure execution time for a critical function of your algorithm by enabling function profiling.

  • Identify performance bottlenecks by enabling function profiling.

  • Compare performance with previous runs to detect regressions arising from changes.

See Create Execution-Time Profile for Generated Code (Embedded Coder) and View and Compare Code Execution Times (Embedded Coder).

On a Linux® development computer, you can generate profiles using metrics from the Performance Monitoring Unit (PMU) of the computer. See Generate Profiles Using PMU Metrics (Embedded Coder).

Processor-in-the-loop (PIL) Embedded hardware or instruction set simulator Embedded Coder

Run generated code on your target hardware and determine whether the generated code meets execution-time requirements for real-time deployment.

You can use PIL profiling to perform the same tasks that you perform with SIL profiling during development. You get more accurate results with PIL profiling. See Create Execution-Time Profile for Generated Code (Embedded Coder) and View and Compare Code Execution Times (Embedded Coder).

At the release stage of development, you can use PIL profiling to assess performance. When you have a sufficient number of test cases, you can use coder.profile.test.runTests (Embedded Coder) to automate model execution and determine the longest task execution times for the inputs used.

PIL results can differ between emulators and the final target hardware. However, the more deterministic the target hardware is, the more reproducible the PIL results are.

Although instrumentation adds overhead, on highly deterministic target hardware (small cache size), you can filter the overhead, providing accurate results. See Remove Instrumentation Overheads from Execution Time Measurements (Embedded Coder).

On Linux hardware, you can generate profiles using metrics from the Performance Monitoring Unit (PMU) of the hardware. See Generate Profiles Using PMU Metrics (Embedded Coder).

XCP external modeDevelopment computer or custom hardwareEmbedded Coder

Run generated code in real-time and perform execution-time profiling. See Create Execution-Time Profile for Generated Code (Embedded Coder) and Analyze Code Execution Data (Embedded Coder).

Use XCP external mode profiling for task analysis. You can:

Although you can enable function profiling, instrumentation overhead is not filtered during an external mode simulation and is higher than the overhead for a PIL simulation. If you want to obtain accurate function execution times, use PIL simulations.

Real-time executionSimulink Real-Time™Simulink Coder™, Simulink Real-Time

Perform execution-time profiling of generated code, running in real-time on a Speedgoat® computer. See Execution Profiling for Real-Time Applications (Simulink Real-Time).

See Also

Topics