Main Content

Execution Profiling for Real-Time Applications

This example shows how you can profile the task execution time and function execution time of your real-time application that is running on the target computer. Using that information, you can then tune its performance.

Profiling is especially useful if you configure your real-time application to take advantage of multicore processors on the target computer. To profile the real-time application:

  • In the Configuration Parameters dialog box for the model, enable the collection of function execution time data during execution.

  • Build, download, and execute the model.

  • Start and stop the profiler.

  • Display the profiler data.

The Execution Profiler and SLRT Overload Options block use different mechanisms to measure TET and do not generate identical TET values.

Configure Real-Time Application for Function Execution Profiling

The model is slrt_ex_mds_and_tasks. To open this model, open the subsystem models first:

1. Open model slrt_ex_mds_and_tasks.

2. In the top model, open the Configuration Parameters dialog box. Select Code Generation >> Verification.

3. For Measure function execution times, select Coarse (reference models and subsystems only). The Measure task execution time check box is selected and locked. Or, in the MATLAB Command Window, type:

set_param('slrt_ex_mds_and_tasks','CodeProfilingInstrumentation','Coarse');

4. Click OK. Save model slrt_ex_mds_and_tasks in a local folder.

Generate Real-Time Application Execution Profile

Generate profile data for model slrt_ex_mds_and_tasks on a multicore target computer.

You must have previously configured the target computer to take advantage of multiple cores and configured the model for task and function execution profiling.

1. Open, build, and download the model.

mdl = 'slrt_ex_mds_and_tasks';
open_system(mdl);
slbuild(mdl);
tg = slrealtime;
load(tg,mdl);
my_app = slrealtime.Application('slrt_ex_mds_and_tasks');
my_app.Options.set("stoptime",20);
### Starting serial model reference simulation build
### Starting serial model reference code generation build
### Successful completion of build procedure for: slrt_ex_mds_subsystem1
### Successful completion of build procedure for: slrt_ex_mds_subsystem2
### Successful completion of build procedure for: slrt_ex_mds_and_tasks
Invalid Simulink object name: slrt_ex_mds_subsystem1.
### Created MLDATX ..\slrt_ex_mds_and_tasks.mldatx

Build Summary

Code generation targets built:

Model                   Action                       Rebuild Reason                              
=================================================================================================
slrt_ex_mds_subsystem1  Code generated and compiled  slrt_ex_mds_subsystem1.cpp does not exist.  
slrt_ex_mds_subsystem2  Code generated and compiled  slrt_ex_mds_subsystem2.cpp does not exist.  

Top model targets built:

Model                  Action                       Rebuild Reason                                    
======================================================================================================
slrt_ex_mds_and_tasks  Code generated and compiled  Code generation information file does not exist.  

3 of 3 models built (0 models already up to date)
Build duration: 0h 0m 45.003s

When you include profiling, the Code Generation Report is generated by default. It contains links to the generated C code and include files. By clicking these links, you can examine the generated code and interpret the Code Execution Profile Report.

2. Start the profiler, and then execute the real-time application.

startProfiler(tg);
start(tg);
pause(1)
stopProfiler(tg);
stop(tg);

3. Display the profiler data.

profiler_data = getProfilerData(tg)
plot(profiler_data)
report(profiler_data)
Processing data on target computer ...
Transferring data from target computer ...
Processing data on host computer ...
 
Code execution profiling data for model slrt_ex_mds_and_tasks.

The Execution Profile schedule display in the Simulation Data Inspector shows how scheduling is generated in real-time simulation. To open the schedule display in the Simulation Data Inspector after creating the executionProfile object, use the executionProfile.schedule() function.

The Code Execution Profiling Report displays model execution profile results for each task.

  • To display the profile data for a section of the model, in the Section column, click the Membrane button next to the task.

  • To display the TET data for the section in Simulation Data Inspector, click the Plot time series data button.

  • To view the section in Simulink Editor, click the link next to the Expand Tree button.

  • To view the lines of generated code corresponding to the section, click the Expand Tree button, and then click the View Source button.

See Also

(Embedded Coder) | | | | | | | | |

Related Topics