How Profiler Captures Performance Data

How Profiler Works

Profiler captures performance data while your model simulates. It identifies the parts of your model that require the most time to simulate. Use the profiling information to decide where to focus your model optimization efforts.

Note

You cannot use Profiler in Rapid Accelerator mode.

Simulink® stores performance data in the simulation profile report. The data shows the time spent executing each function in your model.

The basis for Profiler is an execution model that this pseudocode summarizes.

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, Simulink runs a model by invoking the following functions zero, one, or many times, depending on the function and the model.

FunctionPurposeLevel
sim

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.

System

ModelInitialize

Set up the model for simulation.

System

ModelExecute

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.

System

Output

Compute the outputs of a block at the current time step.

Block

Update

Update the state of a block at the current time step.

Block

Integrate

Compute the continuous states of a block by integrating the state derivatives at the current time step.

Block

MinorOutput

Compute block output at a minor time step.

Block

MinorDeriv

Compute the state derivatives of a block at a minor time step.

Block

MinorZeroCrossings

Compute zero-crossing values of a block at a minor time step.

Block

ModelTerminate

Free memory and perform any other end-of-simulation cleanup.

System

Nonvirtual Subsystem

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.

Block

Profiler measures the time required to execute each invocation of these functions. After the model simulates, Profiler generates a report that describes the amount of simulation time spent on each function.

Start Profiler

  1. Open the model.

  2. Select Analysis > Performance Tools > Show Profiler Report.

  3. Simulate the model.

When simulation is complete, Simulink generates and displays the simulation profile for the model in a MATLAB® web browser.

Summary Section

The summary file displays the following performance totals.

ItemDescription

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

Clock Precision

Precision of the profiler's time measurement

Clock Speed

Speed of the profiler's time measurement

The function list shows summary profiles for each function invoked to simulate the model. For each function listed, the summary profile specifies this information.

ItemDescription

Name

Name of function. This item is a hyperlink. Click it to display a detailed profile of this function.

Time

Total time spent executing all invocations of this function as an absolute value and as a percentage of the total simulation time.

Calls

Number of times this function was invoked.

Time/Call

Average time required for each invocation of this function, including the time spent in functions invoked by this function.

Self Time

Total time required to execute this function, excluding time spent in functions called by this function.

Location

Specifies the block or model executed for which this function is invoked. This item is a hyperlink. Click it to highlight the corresponding element in the model diagram.

Detailed Profile Section

This section of the report contains detailed profiles for each function that Simulink invoked to simulate the model. In addition to the information in the summary profile for the function, the detailed profile displays the function (parent function) that invoked the profiled function and the functions (child functions) invoked by the profiled function. Click the name of the parent or a child function to see the detailed profile for that function.

Note

Enabling 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.

Reports for the referenced models are different from that of the parent model.

Save Profiler Results

You can save the Profiler report to a variable in the MATLAB workspace, and after that, to a mat file. At a later time, you can regenerate and review the report.

Save the Profiler report for a model vdp to the variable profile1 and to the data file report1.mat.

  1. In the Simulink Profiler Report window, in the Summary section, click click here link. Simulink saves the report data to the variable vdpProfileData.

  2. Review the report. At the MATLAB command prompt, enter:

    slprofreport(vdpProfileData)
  3. Save the data to a variable named profile1 in the base workspace.

    profile1 = vdpProfileData;
  4. Save the data to a mat file named report1.

    save report1 profile1

To view the report later, at the MATLAB command prompt, enter:

load report1
slprofreport(profile1);

Related Examples

More About