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.
Run SIL execution to generate execution time data
Copy MATLAB® code to your working folder.
src_dir = ... fullfile(docroot,'toolbox','coder','examples','kalman'); copyfile(fullfile(src_dir,'kalman01.m'), '.') copyfile(fullfile(src_dir,'test01_ui.m'), '.') copyfile(fullfile(src_dir,'plot_trajectory.m'), '.') copyfile(fullfile(src_dir,'position.mat'), '.')
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;
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'))
Create workspace variable that holds execution time data
Use the getCoderExecutionProfile
function
to create a workspace variable that holds execution time profiling
data.
executionProfile=getCoderExecutionProfile('kalman01');
Use the Sections
method.
allSections = executionProfile.Sections
allSections = 1x3 ExecutionTimeTaskSection array with properties: Name Number ExecutionTimeInTicks SelfTimeInTicks TurnaroundTimeInTicks TotalExecutionTimeInTicks TotalSelfTimeInTicks TotalTurnaroundTimeInTicks MaximumExecutionTimeInTicks MaximumExecutionTimeCallNum MaximumSelfTimeInTicks MaximumSelfTimeCallNum MaximumTurnaroundTimeInTicks MaximumTurnaroundTimeCallNum NumCalls ExecutionTimeInSeconds Time
Extract execution time data from specific code section
Specify the code section that you want to examine.
secondSectionProfile = executionProfile.Sections(2)
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
nameOfSection = 'kalman01'
The following table lists the information that you can extract from each code section.
Property | Description |
---|---|
Name | Name of entry-point function |
Number | Code section number |
ExecutionTimeInTicks | Vector 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. |
SelfTimeInTicks | Vector 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. |
TurnaroundTimeInTicks | Vector 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. |
TotalExecutionTimeInTicks | Total number of timer ticks recorded for the code section over the entire execution. |
TotalSelfTimeInTicks | Total 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. |
TotalTurnaroundTimeInTicks | Total 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. |
MaximumExecutionTimeInTicks | Maximum number of timer ticks recorded for a single invocation of the code section over the execution. |
MaximumExecutionTimeCallNum | Number of call in which MaximumExecutionTimeInTicks occurs. |
MaximumSelfTimeInTicks | Maximum number of timer ticks recorded for a single code section invocation, but excluding the time spent in calls to child functions. |
MaximumSelfTimeCallNum | Number of call in which MaximumSelfTimeInTicks occurs. |
MaximumTurnaroundTimeInTicks | Maximum 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. |
MaximumTurnaroundTimeCallNum | Number of call in which MaximumTurnaroundTimeInTicks occurs. |
NumCalls | Total number of calls to the code section over the entire execution. |
ExecutionTimeInSeconds | Vector 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. |
Time | Vector of execution time measurements for the code section. |