Main Content

Insert Event into Execution Profiling Stream

This example shows how to use the Log Event block inserts 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(fullfile(matlabroot,'toolbox','slrealtime','examples','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(fullfile(matlabroot,'toolbox','slrealtime','examples',mdl));
end

Set Parameters for Measure Funtion 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');

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);
Warning: Profiler already stopped. Command ignored. 

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      3545275820041720     200      200      1          2   
     1000      3545280320044224     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