Contenuto principale

Analyze Execution Time Data

R2026b

After a software-in-the-loop (SIL) or processor-in-the-loop (PIL) execution, you can analyze execution-time data using methods from the coder.profile.ExecutionTime and coder.profile.ExecutionTimeSection classes.

In the following example, you run a SIL execution and apply supplied methods to execution-time data.

Extract Execution Time Data for Kalman Estimator Code

  1. Open this example to obtain the files for this tutorial:

    • kalman01.m — MATLAB® function for the Kalman estimator

    • test01_ui.m — MATLAB file to test kalman01.m

    • plot_trajectory.m — File that plots actual target trajectory and Kalman estimator output

    • position.mat — Input data

    openExample('ecoder/KalmanFilterExample')

    Create a coder.EmbeddedCodeConfig object.

    config = coder.config('lib');
    config.GenerateReport = true; % HTML report
    

    Configure the object for SIL and enable execution time profiling.

    config.VerificationMode = 'SIL';
    config.CodeExecutionProfiling = true;

    If you want to generate execution time profiles for functions that are called within entry-point functions, you must also disable the OpenMP library.

    config.CodeProfilingInstrumentation = true;
    config.EnableOpenMP = false;
    On a Mac operating system, SIL and PIL execution does not support execution-time profiling for functions that are called within entry-point functions.

    Generate library code for the kalman01 MATLAB function and the SIL interface.

    codegen('-config', config, '-args', {zeros(2,1)}, 'kalman01');

    Run the MATLAB test file test01_ui with kalman01_sil. kalman01_sil is the SIL interface for kalman01.

    coder.runTest('test01_ui', ['kalman01_sil.' mexext]);

    You see the following message.

    ### Starting SIL execution for 'kalman01'
        To terminate execution: clear kalman01_sil
        Execution profiling data is available for viewing. Go to Simulation Data Inspector.
        Execution profiling report available after termination.
    Current plot released

    Terminate the SIL execution process. Click the link clear kalman01_sil.

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

  2. Use the getCoderExecutionProfile function to create a workspace variable that holds execution time profiling data.

    executionProfile=getCoderExecutionProfile('kalman01');

  3. Use the Sections method.

    allSections = executionProfile.Sections
    
    The software displays the number of code sections and a list of properties.
    allSections = 
    
      1x3 ExecutionTimeTaskSection array with properties:
    
        Name
        Number
        ExecutionTimeInTicks
        SelfTimeInTicks
        TurnaroundTimeInTicks
        TotalExecutionTimeInTicks
        TotalSelfTimeInTicks
        TotalTurnaroundTimeInTicks
        MaximumExecutionTimeInTicks
        MaximumExecutionTimeCallNum
        MaximumSelfTimeInTicks
        MaximumSelfTimeCallNum
        MaximumTurnaroundTimeInTicks
        MaximumTurnaroundTimeCallNum
        NumCalls
        ExecutionTimeInSeconds
        Time

  4. Specify the code section that you want to examine.

    secondSectionProfile = executionProfile.Sections(2)
    The software displays profile data for the code section.
    secondSectionProfile = 
    
      ExecutionTimeTaskSection with properties:
    
                                Name: 'kalman01'
                              Number: 2
                ExecutionTimeInTicks: [1x300 uint64]
                     SelfTimeInTicks: [1x300 uint64]
               TurnaroundTimeInTicks: [1x300 uint64]
           TotalExecutionTimeInTicks: 6641016
                TotalSelfTimeInTicks: 6641016
          TotalTurnaroundTimeInTicks: 6641016
         MaximumExecutionTimeInTicks: 48864
         MaximumExecutionTimeCallNum: 158
              MaximumSelfTimeInTicks: 48864
              MaximumSelfTimeCallNum: 158
        MaximumTurnaroundTimeInTicks: 48864
        MaximumTurnaroundTimeCallNum: 158
                            NumCalls: 300
              ExecutionTimeInSeconds: [1x300 double]
                                Time: [300x1 double]

    You can extract specific properties, for example, the name of a profiled function.

    nameOfSection = secondSectionProfile.Name
    The software displays the name.
    nameOfSection =
    
    'kalman01'

    The following table lists the information that you can extract from each code section.

    PropertyDescription
    NameName of entry-point function
    NumberCode section number
    ExecutionTimeInTicksVector of execution times, measured in timer ticks. Each element contains the difference between the timer reading at the start and at the end of the code section. The data type is the same data type as the data type of the timer used on the target, which allows you to infer the maximum range of the timer measurements.
    SelfTimeInTicksVector of timer tick numbers. Each element contains the number of ticks recorded for the code section, excluding the time spent in calls to child functions.
    TurnaroundTimeInTicksVector of timer tick numbers. Each element contains the number of ticks recorded between the start and the finish of the code section. Unless the code is preempted, this number is the same number as the execution time.
    TotalExecutionTimeInTicksTotal number of timer ticks recorded for the code section over the entire execution.
    TotalSelfTimeInTicksTotal number of timer ticks recorded for the profiled code section over the entire execution. However, this number excludes the time spent in calls to child functions.
    TotalTurnaroundTimeInTicksTotal number of timer ticks recorded between the start and the finish of the profiled code section over the entire execution. Unless the code is preempted, this number is the same as the total execution time.
    MaximumExecutionTimeInTicksMaximum number of timer ticks recorded for a single invocation of the code section over the execution.
    MaximumExecutionTimeCallNumNumber of call in which MaximumExecutionTimeInTicks occurs.
    MaximumSelfTimeInTicksMaximum number of timer ticks recorded for a single code section invocation, but excluding the time spent in calls to child functions.
    MaximumSelfTimeCallNumNumber of call in which MaximumSelfTimeInTicks occurs.
    MaximumTurnaroundTimeInTicksMaximum number of timer ticks recorded between the start and the finish of a single invocation of the profiled code section over the execution. Unless the code is preempted, this time is the same as the maximum execution time.
    MaximumTurnaroundTimeCallNumNumber of call in which MaximumTurnaroundTimeInTicks occurs.
    NumCallsTotal number of calls to the code section over the entire execution.
    ExecutionTimeInSecondsVector of execution times, measured in seconds. Each element contains the difference between the timer reading at the start and at the end of the code section. Produced only if TimerTicksPerSecond is set.
    TimeVector of execution time measurements for the code section.

Automate Execution-Time Analysis of Code Generated From MATLAB Functions

You can use the coder.profile.test.runTests function to run software-in-the-loop (SIL) or processor-in-the-loop (PIL) tests of a MATLAB function and produce execution-time metrics for the generated code. To view and analyze the metrics, use the Code Profile Analyzer app.

For more information, see Automate Execution-Time and Stack Usage Profiling of MATLAB Function.

See Also

Topics