Configure a SIL simulation model that generates a workspace variable containing
stack-usage measurements.
Disable Simulink®
Coverage™ and third-party code coverage analysis.
Disable code execution time profiling.
Enable stack usage profiling.
Create an object for storing results from model simulations.
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.
Next, run a simulation where only CounterTypeB
is
triggered.
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
.
If you want to extract specific simulation results from the object, use the
get
function. For example:
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:
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.
In the Results section of the toolstrip, click
Open Test Result. The Code Profile Analyzer
displays the profile for Count Enable Test
.
In the Analysis section of the toolstrip, click
Function-Call Stack.
On the Function-Call Stack panel, from the
Task to analyze drop-down list, select
step [0.1 0]
.
Click Display. The panel displays the
function-call stack, which indicates the code or model path for the
simulation step.