This example shows how you can profile the task execution time and function execution time of your real-time application running on the target computer. Using that information, you can then tune its performance.
Profiling is especially useful if the real-time application is configured to take advantage of multicore processors on the target computer. To profile the real-time application:
In the Configuration Parameters 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.
Profiling slightly increases the execution time of the real-time application.
In this section, the model is
slrt_ex_mds_and_tasks. To open this model, open the subsystem models first:
1. Open model
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 checked and locked. Or, in the MATLAB command window, type:
4. Click OK. Save model
slrt_ex_mds_and_tasks in a local folder.
In this section, generate profile data for model
slrt_ex_mds_and_tasks on a multicore target computer.
This procedure assumes that you have configured the target computer to take advantage of multiple cores. It also assumes that you previously 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); rtwbuild(mdl); tg = slrealtime; load(tg,mdl);
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)
The Execution Profile plot shows the allocation of execution cycles across the four processors, indicated by the colored horizontal bars. The model sections are listed in the Code Execution Profiling Report. The cores are indicated by the numbers underneath the bars.
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.