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.
Create Target Object and Connect
Create a Target object for the default target computer and connect to the target computer. In the MATLAB® Command Window, type:
tg = slrealtime; connect(tg);
Open Model
To open the model, in the MATLAB Command Window, type:
open_system('slrt_ex_log_event');
model = 'slrt_ex_log_event'; open_system(model); modelSTF = getSTFName(tg); set_param(model,"SystemTargetFile",modelSTF);
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(model,'CodeProfilingInstrumentation','Detailed'); set_param(model,'StopTime','30');
Build and Load Real-Time Application
Build the model and download to the target computer.
evalc('slbuild(model)');
load(tg,model);
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 1997622011996757 200 200 1 2 1000 1997626511997296 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
bdclose(model);