Analyze Execution Time Data
R2026bAfter 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
Open this example to obtain the files for this tutorial:
kalman01.m— MATLAB® function for the Kalman estimatortest01_ui.m— MATLAB file to testkalman01.mplot_trajectory.m— File that plots actual target trajectory and Kalman estimator outputposition.mat— Input data
openExample('ecoder/KalmanFilterExample')Create a
coder.EmbeddedCodeConfigobject.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
kalman01MATLAB function and the SIL interface.codegen('-config', config, '-args', {zeros(2,1)}, 'kalman01');
Run the MATLAB test file
test01_uiwithkalman01_sil.kalman01_silis 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 releasedTerminate the SIL execution process. Click the link
clear kalman01_sil.### Stopping SIL execution for 'kalman01' Execution profiling report: report(getCoderExecutionProfile('kalman01'))Use the
getCoderExecutionProfilefunction to create a workspace variable that holds execution time profiling data.executionProfile=getCoderExecutionProfile('kalman01');Use the
Sectionsmethod.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 TimeSpecify 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 NameName of entry-point function NumberCode section number ExecutionTimeInTicksVector 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. SelfTimeInTicksVector 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. TurnaroundTimeInTicksVector 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. TotalExecutionTimeInTicksTotal number of timer ticks recorded for the code section over the entire execution. TotalSelfTimeInTicksTotal 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. TotalTurnaroundTimeInTicksTotal 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. MaximumExecutionTimeInTicksMaximum number of timer ticks recorded for a single invocation of the code section over the execution. MaximumExecutionTimeCallNumNumber of call in which MaximumExecutionTimeInTicksoccurs.MaximumSelfTimeInTicksMaximum number of timer ticks recorded for a single code section invocation, but excluding the time spent in calls to child functions. MaximumSelfTimeCallNumNumber of call in which MaximumSelfTimeInTicksoccurs.MaximumTurnaroundTimeInTicksMaximum 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. MaximumTurnaroundTimeCallNumNumber of call in which MaximumTurnaroundTimeInTicksoccurs.NumCallsTotal number of calls to the code section over the entire execution. ExecutionTimeInSecondsVector 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 TimerTicksPerSecondis set.TimeVector of execution time measurements for the code section.
Automate Execution-Time Analysis of Code Generated From MATLAB Functions
You can use the coder.profile.test.runTests function to run software-in-the-loop
(SIL) or processor-in-the-loop (PIL) tests of a MATLAB function and produce execution-time metrics for the generated code. To
view and analyze the metrics, use the Code Profile Analyzer app.
For more information, see Automate Execution-Time and Stack Usage Profiling of MATLAB Function.
See Also
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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)