Main Content

View Execution Times

R2026b

You can run a software-in-the-loop (SIL) or processor-in-the-loop (PIL) execution that produces execution-time metrics for tasks and functions in your generated code. During execution, you can use the Simulation Data Inspector to observe streamed execution times. When execution is complete, you can:

  • View execution-time metrics for a profiled entry-point function.

  • Open a report of execution-time metrics for all profiled functions. Through report icons, you can view, for example, the profiled code section and the execution-time distribution for each profiled function.

  • Use the Simulation Data Inspector to plot and compare execution times from various execution runs.

Code Execution Profiling Report

When you run a SIL or PIL execution with execution time profiling enabled, the software generates a message in the Command Window. For example:

Current plot held
### 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.

To observe streamed execution times while the execution runs, click the Simulation Data Inspector link.

To open the code execution profiling report:

  1. Click the clear euclidean_sil link.

    The software terminates the execution process and displays a new link.

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

  2. Click the new link.

The report contains these sections:

  1. This section gives information about the creation of the report.

    Summary section provides information about report creation.

  2. This section contains information about profiled code sections. In the Section column, expand and collapse profiled sections by clicking [+] and [–] respectively. This graphic shows fully expanded sections.

    Expanded code sections display execution-time metrics for profiled functions.

    The report contains time measurements for:

    • The entry_point_fn_initialize function, for example, euclidean_initialize.

    • The entry-point function, for example, euclidean.

    • The entry_point_fn_terminate function, for example, euclidean_terminate.

    By default, the report displays time in nanoseconds (10-9 seconds). You can specify the time unit and numeric display format. For example, to display time in microseconds (10-6 seconds), use the report command:

    % Create workspace variable
    executionProfile=getCoderExecutionProfile('kalman01');
    
    report(executionProfile, ...
           'Units', 'Seconds', ...
           'ScaleFactor', '1e-06', ...
           'NumericFormat', '%0.3f')

    The report displays time in seconds only if the timer is calibrated, that is, the number of timer ticks per second is known. On a Windows® machine, the software determines this value for a SIL simulation. On a Linux® machine, you must manually calibrate the timer. For example, if your processor speed is 1 GHz, specify the number of timer ticks per second:

    executionProfile.TimerTicksPerSecond = 1e9;
    

    To view execution-time metrics for a code section in the Command Window, on the corresponding row, click the icon .

    To display measured execution times, click the Simulation Data Inspector icon . You can use the Simulation Data Inspector to manage and compare plots from various executions.

    To display the execution-time distribution, click the icon .

    Plot shows execution-time distribution for code section.

    In this example, to create the histogram, the software uses these commands:

    executionProfile=getCoderExecutionProfile('kalman01')
    section=executionProfile.Sections(2);
    data=section.ExecutionTimeInSeconds;
    histogram(data, 30,'Normalization','probability');
    
    The software creates the histogram only if the number of calls to the function is greater than one.

    If the generated code contains nested functions, the execution generates pie charts that show the relative execution times of caller and called functions. To display the pie charts, click the icon for the caller function.

    The following table lists the information provided in the code section profiles.

    ColumnDescription
    SectionName of function from which code is generated.
    Maximum Execution TimeLongest time between start and end of code section.
    Average Execution TimeAverage time between start and end of code section.
    Maximum Self TimeMaximum execution time, excluding time in child sections.
    Average Self TimeAverage execution time, excluding time in child sections.
    CallsNumber of calls to the code section.
    Icon that you click to display the profiled code section.
    Icon that you click to display measured execution times with Simulation Data Inspector.
    Icon that you click to display the execution-time distribution for the profiled code section.
    Icon that you click to display pie charts that show the relative execution times of caller and called functions in the generated code.

  3. This section provides function execution times as percentages of caller function and total execution times, which can help you to identify performance bottlenecks in generated code.

    Report section shows function execution times as percentages of caller function and total execution times.

    This table describes the information that each column provides.

    ColumnComparison Performed
    Self Time / Caller FunctionFunction self time compared with the total execution time of the caller function.
    Self Time / TaskFunction self time compared with the total execution time of the task.
    Self Time / SimulationFunction self time compared with the total execution time.
    Function / SimulationFunction execution time, which includes self time and time spent in child functions, compared with the total execution time.

  4. This section provides descriptions of some metrics.

    Report section shows definitions for execution time and self time metrics.

Visualize Task Scheduling

You can use the Simulation Data Inspector to visualize task scheduling and the order of function calls. At the end of the execution, run the schedule function. For more information, see Visualize Task Scheduling.

See Also

Topics