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:
To open the MATLAB® Coder™ app, on the MATLAB Toolstrip Apps tab, under Code Generation, click the app icon. The app opens the Create MATLAB Coder Project dialog box.
To open your project, click Open, navigate to the folder that contains your MATLAB Coder project file, and select the file. For example,
kalman_filter01.coderprj
.From the SIL/PIL profiling metrics drop-down list, select the required PMU metric. For example,
L1 Data Cache Misses
.Select the Enable entry point execution profiling check box.
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, clear the Enable OpenMP library if possible check box.
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;
When the SIL or PIL execution is complete, the code generator produces a message in the Command Window that contains a link to the execution profiling report. To view results in the Code Profile Analyzer, click that link.
See Also
coder.EmbeddedCodeConfig
| getCoderExecutionProfile