Main Content

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';
modelOpened = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp(model, systems))
  modelOpened = 1;
  open_system(model);
end
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('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(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      4391975937658171     200      200      1          2   
     1000      4391975937658171     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 (modelOpened)
  bdclose(model);
end