|On this page…|
The profiler captures data while your model runs and identifies the parts of your model requiring the most time to simulate. You use this information to decide where to focus your model optimization efforts.
Performance data showing the time spent executing each function in your model is placed in a report called the simulation profile.
The following pseudocode summarizes the execution model on which the Profiler is based.
Sim() ModelInitialize(). ModelExecute() for t = tStart to tEnd Output() Update() Integrate() Compute states from derivs by repeatedly calling: MinorOutput() MinorDeriv() Locate any zero crossings by repeatedly calling: MinorOutput() MinorZeroCrossings() EndIntegrate Set time t = tNew. EndModelExecute ModelTerminate EndSim
According to this conceptual model, your model is executed by invoking the following functions zero, one, or more times, depending on the function and the model.
Simulate the model. This top-level function invokes the other functions required to simulate the model. The time spent in this function is the total time required to simulate the model.
Set up the model for simulation.
Execute the model by invoking the output, update, integrate, etc., functions for each block at each time step from the start to the end of simulation.
Compute the outputs of a block at the current time step.
Update a block's state at the current time step.
Compute a block's continuous states by integrating the state derivatives at the current time step.
Compute a block's output at a minor time step.
Compute a block's state derivatives at a minor time step.
Compute a block's zero-crossing values at a minor time step.
Free memory and perform any other end-of-simulation cleanup.
Compute the output of a nonvirtual subsystem at the current time step by invoking the output, update, integrate, etc., functions for each block that it contains. The time spent in this function is the time required to execute the nonvirtual subsystem.
The Profiler measures the time required to execute each invocation of these functions and generates a report at the end of the model that describes how much time was spent in each function.
To profile a model, open the model and select Show Profiler Report from the Analysis > Performance Tools menu. Then start the simulation. When the simulation finishes, the Simulink® code generates and displays the simulation profile for the model in the Help browser.
The summary file displays the following performance totals.
Total Recorded Time
Total time required to simulate the model
Number of Block Methods
Total number of invocations of block-level functions (e.g., Output())
Number of Internal Methods
Total number of invocations of system-level functions (e.g., ModelExecute)
Number of Model Methods
Number of methods called by the model
Number of Nonvirtual Subsystem Methods
Total number of invocations of nonvirtual subsystem functions
Precision of the profiler's time measurement
Speed of the profiler's time measurement
The summary section then shows summary profiles for each function invoked to simulate the model. For each function listed, the summary profile specifies the following information.
Name of function. This item is a hyperlink. Clicking it displays a detailed profile of this function.
Total time spent executing all invocations of this function as an absolute value and as a percentage of the total simulation time
Number of times this function was invoked
Average time required for each invocation of this function, including the time spent in functions invoked by this function
Average time required to execute this function, excluding time spent in functions called by this function
Specifies the block or model executed for which this function is invoked. This item is a hyperlink. Clicking it highlights the corresponding icon in the model diagram. The link works only if you are viewing the profile in the Help browser.
This section contains detailed profiles for each function invoked to simulate the model. Each detailed profile contains all the information shown in the summary profile for the function. In addition, the detailed profile displays the function (parent function) that invoked the profiled function and the functions (child functions) invoked by the profiled function. Clicking the name of the parent or a child function takes you to the detailed profile for that function.
Note: Enabling the Profiler on a parent model does not enable profiling for referenced models. You must enable profiling separately for each referenced model. Profiling occurs only if the referenced model executes in Normal mode. See Normal Mode for more information.
You can save the Profiler report to a variable in the MATLAB® workspace, and subsequently, to a mat file. At a later time, you can regenerate and review the report.
To save the Profiler report for a model vdp to the variable profile1 and to the data file report1.mat, complete the following steps:
In the Simulink Profiler Report window, click click here. Simulink saves the report data to the variable vdpProfileData.
Navigate to the MATLAB command window.
To review the report, at the command line enter:
To save the data to a variable named profile1 in the base workspace, enter:
profile1 = vdpProfileData;
To save the data to a mat file named report1, enter:
save report1 profile1
To view the report at a later time, from the MATLAB command window, enter:
% Load the mat file and recreate the profile1 object load report1 % Recreate the html report from the object slprofreport(profile1);