Desktop Tools and Development Environment Previous page   Next Page

Example: Using the profile Function

This example demonstrates how to run profile:

  1. To start profile, type in the Command Window
  2. Execute an M-file. This example runs the Lotka-Volterra predator-prey population model. For more information about this model, type lotkademo, which runs a demonstration.
  3. Generate the profile report and display it in the Profiler window. This suspends profile.
  4. Restart profile, without clearing the existing statistics.
  1. The profile function is now ready to continue gathering statistics for any more M-files you run. It will add these new statistics to those generated in the previous steps.

  1. Stop profile when you finish gathering statistics.
  2. To view the profile data, call profile specifying the 'info' argument. The profile function returns data in a structure.
  3. To save the profile report, use the profsave function. This function stores the profile information in separate HTML files, for each function listed in the FunctionTable field of the structure, p.
  1. By default, profsave puts these HTML files in a subdirectory of the current directory named profile_results. You can specify another directory name as an optional second argument to profsave.

Accessing Profiler Results

The profile function returns results in a structure. This example illustrates how you can access these results:

  1. To start profile, specifying the detail and history options, type in the Command Window.
  1. The detail option specifies that built-ins should be included in the profile data. The history option specifies that the report include information about the sequence of functions as they are entered and exited during profiling.

  1. Execute an M-file. This example runs the Lotka-Volterra predator-prey population model. For more information about this model, type lotkademo, which runs a demonstration.
  2. Get the structure containing profile results.
  3. The FunctionTable field is an array of structures, where each structure represents an M-function, M-subfunction, MEX-function, or, because the builtin option is specified, a MATLAB built-in function.
  4. View one of the structures in the FunctionTable field.
  5. To view the history data generated by profile, view the FunctionHistory field. The history data is a 2-by-n array. The first row contains Boolean values where 1 means entrance into a function and 0 (zero) means exit from a function. The second row identifies the function being entered or exited by its index in the FunctionTable field. To see how to create a formatted display of history data, see the example on the profile reference page.

Saving Profile Reports

To save the profile report, use the profsave function.

This function stores the profile information in separate HTML files, for each function listed in the FunctionTable field of the structure, p.

profsave(p)

By default, profsave puts these HTML files in a subdirectory of the current directory named profile_results. You can specify another directory name as an optional second argument to profsave.

profsave(p,'mydir')

Previous page  The profile Function Publishing Results Next page

© 1994-2005 The MathWorks, Inc.