Analyze Code Execution Data
After a software-in-the-loop (SIL), processor-in-the-loop (PIL), or XCP-based external mode
simulation, you can analyze execution-time data using methods from the
coder.profile.ExecutionTime
and
coder.profile.ExecutionTimeSection
classes.
Open the model
SILTopModel
.openExample('ecoder/SILPILVerificationExample', ... supportingFile='SILTopModel.slx')
In the Mode section, select SIL/PIL Simulation Only.
In the Settings gallery, specify options to enable profiling:
Under SIL/PIL Settings, click Portable Word Sizes on.
Under Time Profiling, click Task Profiling on, click Save Options to
ALL DATA
, and click Functions off.Under Coverage, click Coverage Collection off.
In the Run section, click Run SIL/PIL.
The software generates out, a Simulink.SimulationOutput
object that
contains executionProfile
, a coder.profile.ExecutionTime
object.
To get the total number of code sections that have profiling data, use the Sections
method:
no_of_Sections = out.executionProfile.Sections
no_of_Sections = 1×2 ExecutionTimeTaskSection array with properties: Name Number ExecutionTimeInTicks SelfTimeInTicks TurnaroundTimeInTicks TotalExecutionTimeInTicks TotalSelfTimeInTicks TotalTurnaroundTimeInTicks MaximumExecutionTimeInTicks MaximumExecutionTimeCallNum MaximumSelfTimeInTicks MaximumSelfTimeCallNum MaximumTurnaroundTimeInTicks MaximumTurnaroundTimeCallNum NumCalls ExecutionTimeInSeconds Time
coder.profile.ExecutionTimeSection
object for a profiled code
section, use the method Sections
.FirstSectionProfile = out.executionProfile.Sections(1) SecondSectionProfile = out.executionProfile.Sections(2)
FirstSectionProfile = ExecutionTimeTaskSection with properties: Name: 'initialize' Number: 1 ExecutionTimeInTicks: 154 SelfTimeInTicks: 154 TurnaroundTimeInTicks: 154 TotalExecutionTimeInTicks: 154 TotalSelfTimeInTicks: 154 TotalTurnaroundTimeInTicks: 154 MaximumExecutionTimeInTicks: 154 MaximumExecutionTimeCallNum: 1 MaximumSelfTimeInTicks: 154 MaximumSelfTimeCallNum: 1 MaximumTurnaroundTimeInTicks: 154 MaximumTurnaroundTimeCallNum: 1 NumCalls: 1 ExecutionTimeInSeconds: 4.2778e-08 Time: 0 SecondSectionProfile = ExecutionTimeTaskSection with properties: Name: 'step [0.1 0]' Number: 2 ExecutionTimeInTicks: [262 216 176 174 174 174 178 172 … ] SelfTimeInTicks: [262 216 176 174 174 174 178 172 … ] TurnaroundTimeInTicks: [262 216 176 174 174 174 178 172 … ] TotalExecutionTimeInTicks: 22366 TotalSelfTimeInTicks: 22366 TotalTurnaroundTimeInTicks: 22366 MaximumExecutionTimeInTicks: 748 MaximumExecutionTimeCallNum: 68 MaximumSelfTimeInTicks: 748 MaximumSelfTimeCallNum: 68 MaximumTurnaroundTimeInTicks: 748 MaximumTurnaroundTimeCallNum: 68 NumCalls: 101 ExecutionTimeInSeconds: [7.2778e-08 6.0000e-08 4.8889e-08 4.8333e-08 … ] Time: [101×1 double]
Use coder.profile.ExecutionTimeSection
methods to extract profiling
information for a particular code section. For example, use Name
to obtain the name of a profiled
task.
name_of_section = SecondSectionProfile.Name
name_of_section = 'step [0.1 0]'
If the timer is uncalibrated and you know the timer rate, for example 2.2 GHz, you can use the
coder.profile.ExecutionTime
method TimerTicksPerSecond
to calibrate the
timer.
out.executionProfile.TimerTicksPerSecond = 2.2e9; SecondSectionProfile = out.executionProfile.Sections(2);