Main Content

Investigate Execution-Time Issues Using PMU Metrics

Execution-time profiling captures code execution times, which can help you to identify bottlenecks – see Generate Execution Time Profile and View Execution Times. If you are unable to explain the observed execution times by examining the generated code, for Linux-based hardware, you can investigate further by analyzing metrics from the Performance Monitoring Unit (PMU) of the hardware.

For example, if the generated code multiplies two matrices, you might notice that the execution time increases significantly with matrix size. In this case, if you use the number of data cache misses as the metric for profiling generated code, you might observe how the cache size for the chosen algorithm affects its operation on the selected hardware. You can use the information to tailor the algorithm, improving its performance on the selected hardware.

Generate PMU Metric Profile

Before running a software-in-the-loop (SIL) or processor-in-the-loop (PIL) execution, enable profiling:

  1. To open the MATLAB® Coder™ app, on the MATLAB Toolstrip Apps tab, under Code Generation, click the app icon.

  2. To open your project, click and then click Open existing project. Select the project.

  3. On the Generate Code page, click the Generate arrow.

  4. Click More Settings.

  5. Click All Settings.

  6. From the SIL/PIL profiling metrics drop-down list, select the required PMU metric. For example, L1 Data Cache Misses.

  7. Click Verify Code.

  8. Select the Enable entry point execution profiling for SIL/PIL check box.

  9. If you also want to generate execution time profiles for functions that are called within entry-point functions, select the Enable function execution profiling check box.

    Note

    Function profiling does not support the OpenMP library. Before you generate code, on the Generate Code page, click the arrow next to Generate. Then, click More Settings. Under Advanced, set Enable OpenMP library if possible to No.

    On a Mac operating system, SIL and PIL execution does not support execution-time profiling for functions that are called within entry-point functions.

Or, from the Command Window, specify properties of your coder.EmbeddedCodeConfig object. For example:

% Enable entry point execution profiling
config.CodeExecutionProfiling = true;

% Enable function execution profiling
config.CodeProfilingInstrumentation = true;

% Specify metric to extract from PMU
config.CodeProfilingCodeMetrics = 'l1dcm';

% Disable OpenMP
config.EnableOpenMP = false;

To view results in the Code Profile Analyzer when the SIL or PIL execution is complete:

  1. In the Test Output tab in the MATLAB Coder app or in the Command Window, terminate the SIL/PIL execution.

  2. The code generator produces a message in the Command Window that contains a link to the execution profiling report. Click that link.

See Also

|

Related Topics