Analyze Execution Time Data
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
Run SIL execution to generate execution time data
Open this example to obtain the files for this tutorial:
kalman01.m
— MATLAB® function for the Kalman estimatortest01_ui.m
— MATLAB file to testkalman01.m
plot_trajectory.m
— File that plots actual target trajectory and Kalman estimator outputposition.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.
On a Mac operating system, SIL and PIL execution does not support execution-time profiling for functions that are called within entry-point functions.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
withkalman01_sil
.kalman01_sil
is the SIL interface forkalman01
.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.The software displays the number of code sections and a list of properties.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.
The software displays profile data for the code section.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.
The software displays the name.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.
Related Topics
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)