Main Content


Aggregate stack usage profiling results from multiple SIL, PIL, or external mode simulations

Since R2023b


Use a coder.profile.ExecutionStackSet object for the aggregation of stack usage profiling results from multiple software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulations of a model. Then, you can use the Code Profile Analyzer to identify the most demanding execution for each task in the generated code. You can also identify the code or model path that produces the most demanding execution.




myResults = coder.profile.ExecutionTimeSet(modelName); creates an object for storing stack usage profiling results produced by multiple SIL or PIL simulations of modelName.

Input Arguments

expand all

Name of simulation model.


expand all

Specifies the number of most demanding task executions to consider for each model simulation.

Example: resultsObject.ResultsPerTest=10;

Object Functions

addAggregate stack usage profiles
getExtract specific execution-time profile from aggregate of profiles
removeRemove execution-time profile from aggregate of profiles


collapse all

In this example:

  • Using specific test inputs, run SIL simulations that exercise different paths in a model and generated code.

  • Aggregate stack usage profiles produced by the SIL simulations.

  • Identify the test input and code path that require the most stack memory.

Configure a SIL simulation model that generates a workspace variable containing stack-usage measurements.

openExample('ecoder/SILPILVerificationExample', ...
model = bdroot;

Disable Simulink® Coverage™ and third-party code coverage analysis.

          'CovEnable', 'off');
covSettings = get_param(model, 'CodeCoverageSettings');
covSettings.CoverageTool = 'None';
set_param(model, 'CodeCoverageSettings', covSettings);

Disable code execution time profiling.

          'CodeExecutionProfiling', 'off');
          'CodeProfilingInstrumentation', 'off');

Enable stack usage profiling.

          'CodeStackProfiling', 'on');

Create an object for storing results from model simulations.

resultsObject = coder.profile.ExecutionStackSet(model);

The example model contains two triggered subsystems. The third and fourth inputs, counter_mode and count_enabled, control the execution of the triggered subsystems. To simplify the analysis, assume that the first and second inputs, ticks_to_count and reset, contain values that exercise all associated code paths.

To analyze stack usage metrics for different test cases, run multiple simulations, storing results after each simulation.

First, run a simulation that allows you to analyze stack usage for the case where CounterTypeA is triggered and CounterTypeB is disabled.

counter_mode.signals.values = false(1,101)';
simOut = sim(model, 'ReturnWorkspaceOutputs', 'on');
resultsObject.add('CounterA Test', simOut.stackProfile);

Next, run a simulation where only CounterTypeB is triggered.

counter_mode.signals.values = true(1,101)';
simOut = sim(model, 'ReturnWorkspaceOutputs', 'on');
resultsObject.add('CounterB Test', simOut.stackProfile);

Finally, run a simulation to observe the effect of the count_enable input. For this simulation, create a test case that:

  • After each step, enables or disables the counters.

  • In the first half of the simulation, uses CounterTypeA.

  • In the second half of the simulation, uses CounterTypeB.

count_enable.signals.values(1:2:end) = false;
counter_mode.signals.values(1:50) = false;
counter_mode.signals.values(51:end) = true;
simOut = sim(model, 'ReturnWorkspaceOutputs', 'on');
resultsObject.add('Count Enable Test', simOut.stackProfile);

If you want to extract specific simulation results from the object, use the get function. For example:

stackUsageProfileForRun2 = resultsObject.get('Run 2')

To analyze results that are contained in the profile aggregate, run:;

On the Cumulative Results panel, the Task Summary view displays profiled tasks. For this model, only a single task, step, is generated. To investigate the task, click the row that contains step.

The columns provide this information:

  • Test Name — Name of test. For example, CounterA Test, CounterB Test, or Count Enable Test.

  • Highest Stack Usage (bytes) — Maximum stack memory that the task execution uses. In this example, the column provides stack usage values for the five most demanding executions of each simulation.

  • Highest Stack Usage At — Simulation time at which maximum stack usage occurred.

  • Average Stack Usage (bytes) — Average value of task stack usage over simulation.

  • Calls — Number of task calls.

If you want to view details for a different number of task executions, modify the ResultsPerTest property of the coder.profile.ExecutionStackSet object. For example, in the Command Window, enter:


To identify the corresponding code or model path for the most demanding execution:

  1. In the Test Details view, click the row that contains the highest stack usage value. Because the value is constant at 112 bytes for all tests, the first row is chosen arbitrarily for this example.

  2. In the Results section of the toolstrip, click Open Test Result. The Code Profile Analyzer displays the profile for Count Enable Test.

  3. In the Analysis section of the toolstrip, click Function-Call Stack.

  4. On the Function-Call Stack panel, from the Task to analyze drop-down list, select step [0.1 0].

  5. Click Display. The panel displays the function-call stack, which indicates the code or model path for the simulation step.

Version History

Introduced in R2023b