Insert Event into Execution Profiling Stream
This example shows how to use the Log Event block to insert a user-defined event into the execution profiling event stream. For more information about execution profiling, see Execution Profiling for Real-Time Applications.
Open Model
To open the model, in the MATLAB Command Window, type:
open_system('slrt_ex_log_event');
mdl = 'slrt_ex_log_event'; mdlOpened = 0; systems = find_system('type', 'block_diagram'); if ~any(strcmp(mdl, systems)) mdlOpened = 1; open_system(mdl); end
Set Parameters to Measure Function Execution Times
Open the Configuration Parameters dialog box. Select Code Generation > Verification.
For Measure function execution times, select Detailed (all function call sites). The Measure task execution time check box is checked and locked. Click OK.
Or, in the MATLAB command window, type:
set_param('slrt_ex_log_event','CodeProfilingInstrumentation','Detailed'); set_param('slrt_ex_log_event','StopTime','30');
Build and Load Real-Time Application
Build the model and download to the target computer.
evalc('slbuild(mdl)');
tg = slrealtime;
load(tg,mdl);
Profile Execution
Start the profiler and then execute the real-time application.
startProfiler(tg); start(tg); pause(20) stopProfiler(tg); stop(tg);
Display Execution Profile
Retrieve the Profiler data. Display the user-defined event in a table.
profiler_data = getProfilerData(tg); profiler_data.EventTrace.etData
Processing data on target computer ... Transferring data from target computer ... Processing data on host computer ... ans = 2×6 table Channel Timestamp Event Value CPU ModelTime _______ ________________ _____ _____ ___ _________ 500 4391953547601008 200 200 1 2 1000 4391953547601008 100 700 1 6.5
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.
Close Model
Close the model if it is opened.
if (mdlOpened) bdclose(mdl); end