MATLAB Function Reference    
profile

Start the M-file profiler, a utility for debugging and optimizing M-file code

Syntax

Description

The profiler utility helps you debug and optimize M-files by tracking their execution time. For each function in the M-file, the profiler records information about execution time, number of calls, parent functions, child functions, code line hit count, and code line execution time.

profile on starts the profiler, clearing previously recorded profile statistics.

profile on -detail level starts the profiler for the set of functions specified by level, clearing previously recorded profile statistics.

Value for level
Functions Profiler Gathers Information About
mmex
M-functions, M-subfunctions, and MEX-functions; mmex is the default value
builtin
Same functions as for mmex plus built-in functions such as eig
operator
Same functions as for builtin plus built-in operators such as +

profile on -history starts the profiler, clearing previously recorded profile statistics, and recording the exact sequence of function calls. The profiler records up to 10,000 function entry and exit events. For more than 10,000 events, the profiler continues to record other profile statistics, but not the sequence of calls.

profile off suspends the profiler.

profile resume restarts the profiler without clearing previously recorded statistics.

profile clear clears the statistics recorded by the profiler.

profile report suspends the profiler, generates a profile report in HTML format, and displays the report in the Help browser.

profile report basename suspends the profiler, generates a profile report in HTML format, saves the report in the file basename in the current directory, and displays the report in your system's default Web browser. Because the report consists of several files, do not provide an extension for basename.

profile plot suspends the profiler and displays in a figure window a bar graph of the functions using the most execution time.

s = profile('status') displays a structure containing the current profiler status. The structure's fields are shown below.

Field
Values
ProfilerStatus
'on' or 'off'
DetailLevel
'mmex', 'builtin', or 'operator'
HistoryTracking
'on' or 'off'

stats = profile('info') suspends the profiler and displays a structure containing profiler results. Use this function to access the data generated by the profiler. The structure's fields are

FunctionTable
Array containing list of all functions called.
FunctionHistory
Array containing function call history.
ClockPrecision
Precision of profiler's time measurement.

Remarks

To see an example of a profile report and profile plot, as well as to learn more about the results and how to use profiling, see Improving M-File Performance: the Profiler.

Examples

Example

  1. Run the profiler for code that computes the Lotka-Volterra predator-prey population model.

    The profile report appears in your system's default Web browser, providing information for all M-functions, M-subfunctions, MEX-functions, and built-in functions. The report includes the function call history.

  1. Generate the profile plot.

    The profile plot appears in a figure window.

  1. Because the report and plot features suspend the profiler, resume its operation without clearing the statistics already gathered.

    The profiler will continue gathering statistics when you execute the next M-file.

See Also

profreport, tic

Improving M-File Performance - the Profiler" in Using MATLAB


 prod profreport