Main Content

schedule

Visualize task scheduling (MATLAB code generation)

Description

example

schedule(executionProfile), using the Simulation Data Inspector, helps you to visualize how code was executed on the target hardware in the last software-in-the-loop (SIL) or processor-in-the-loop (PIL) run.

schedule(executionProfile,Name,Value) uses name-value arguments to control the display of function execution and execution time.

Examples

collapse all

For a MATLAB® function, perform a software-in-the-loop execution that generates execution-time measurements and then use the data to visualize task scheduling.

Copy the euclidean example files to your local working folder. For more information about the euclidean example, see Generate C Code at the Command Line.

copyfile(fullfile(matlabroot,'help','toolbox','coder','examples','euclidean'));

To make the MATLAB code suitable for code generation, in euclidean.m, replace:

idx(1)=1;
idx(2)=1;

distance(1)=norm(x-cb(:,1));
distance(2)=norm(x-cb(:,1));

with:

idx = ones(1,2);

distance = ones(1,2)*norm(x-cb(:,1));

Configure SIL execution with profiling.

config = coder.config('lib');
config.GenerateReport = true;
config.VerificationMode = 'SIL';
config.CodeExecutionProfiling = true;
config.CodeProfilingInstrumentation = true;
config.EnableOpenMP = false;

In the current folder, create test_example.m, a MATLAB script that calls the compiled function twice.

[y_min,y_max,idx,distance] = euclidean(x,cb);
[y_min2,y_max2,idx2,distance2] = euclidean(x*2,cb*2);

Generate library code for the euclidean MATLAB function and the SIL interface and start the SIL execution.

load euclidean_data.mat
codegen -report -config config euclidean -args {x, cb} -test test_example
Code generation successful: View report

Running test file: 'test' with MEX function 'euclidean_sil.mexw64'.
### Starting SIL execution for 'euclidean'
    To terminate execution: clear euclidean_sil
    Execution profiling data is available for viewing. Go to Simulation Data Inspector.
    Execution profiling report available after termination.

...

Terminate the SIL execution process by clicking the link clear euclidean_sil.

### Application stopped
### Stopping SIL execution for 'euclidean'
    Execution profiling report: report(getCoderExecutionProfile('euclidean'))

Create a workspace variable that holds the execution time data.

executionProfile=getCoderExecutionProfile('euclidean');

To open the code execution report, run:

report(executionProfile)

To visualize how the tasks are scheduled and generated code is executed, run:

schedule(executionProfile)

The Simulation Data Inspector displays these plots.

In each task plot, the Y-axis lists tasks and functions called by each task. From the plots, you can infer the following information:

  • The order in which tasks run. For example, initialize runs before euclidean.

  • The time that is required to execute a task or a function, computed as the difference between the stop and start times. For example, observe that the initial calls to fabs and sqrt take more time to run than subsequent calls to the same functions. When a task is not running, the Y-axis value of the plot is NotRunning.

  • The order in which functions run within a task. For example, in the euclidean task, there are three calls to fabs before each call to sqrt.

    If function calls are nested, you can see the call stack for the functions.

The simulation time plot displays the call number for the euclidean function. In this example, there are two calls to euclidean.

Input Arguments

collapse all

Workspace variable that contains the code execution profiling data generated by the SIL or PIL execution.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: schedule(executionProfile, 'ShowTasksOnly', false, 'StartSimTime', 2, 'StopSimTime', 4)

Control display of function execution plots:

  • true –– Display task execution only. Do not display function execution.

  • false –– Display task and function execution.

Specify maximum number of points to display.

Specify execution time at the start of the display.

Specify execution time at the end of the display.

Version History

Introduced in R2021b