Working with the Profiler

 

The purpose of this tutorial is to teach you how to profile files and applications in order to gain maximal efficiency in the execution of your script. 

Purpose and Usage

Zend Profiler detects bottlenecks in scripts by locating problematic sections of code. These are scripts that consume excessive loading-time. The Profiler provides you with detailed reports that are essential to optimizing the overall performance of your application.

Zend Studio includes five types of profiling:

  • Locally Profiling PHP Scripts - Profiling PHP files using Zend Studio's internal PHP Executable debugger.

  • Remotely Profiling PHP Scripts - Profiling PHP files using your server's debugger.

  • Profiling PHP Web Pages - Profiling files, applications and projects on your server, using the local or server copies of your files.

  • Profiling URLs - Debug applications on your server by entering a URL.

  • Toolbar Profiling - Debug files and applications directly from your browser.

Profiling PHP Scripts

Files can be profiled using Zend Studio's internal debugger. or your external (remote) server.

Use the remote profiling function if you want to test the execution of the file on your server's environment. This is especially relevant if your server's loaded extensions are different to Zend Studio's internal server.

Note:

Your server must be running the Zend Debugger or Xdebug in order for remote debugging and profiling capabilities to function.
The Zend Debugger comes bundled with Zend Studio and Zend Server. For instructions on installing and configuring Xdebug, see Installing Xdebug and Configuring Xdebug.

 

 

 

 

Instructions on how to complete a procedure

The following procedure demonstrates how to profile a PHP Script, either locally or remotely:

  1. Create a file, called Person, and copy-paste the example code into it. (Click herefor the example code)
    (See the "Working with the Profiler" Tutorial in Zend Studio's Online Help for the example code.)

  2. Create a second file, called tryPerson, and copy-paste the example code into it. (Click herefor the example code).
    See the "Working with the Profiler" Tutorial in Zend Studio 's Online Help for the example code.

  3. Save both files.

  4. Click the arrow next to the Profile button on the toolbar and select Profile Configurations... -or- from the main menu go to Run | Profile Configurations... -or- right-click in PHP Explorer view and select Profile Configurations....

  5. A Profile dialog will appear.

Profile Configuration Dialog

  1. Double-click the PHP Script option to create a new Profile configuration.

  2. Enter a name for the new configuration.

  3. To profile the file locally using Zend Studio's internal debugger, select the PHP Executable setting under the Debugger Location category and select the required PHP executable (PHP 4, 5, or 5.3).
    To profile the file remotely on your server using the Zend Debugger installed on your server, select the PHP Web Server option and select your server from the drop-down list. (If you have not yet configured a server, click the PHP Servers link and follow the instructions under Adding PHP Servers.)

  4. Under PHP File, click Browse and select the "TryPerson" file.

  5. Click Apply and then Profile.

  6. A confirmation dialog will be displayed asking whether you want to open the Profiling Perspective.
    Click Yes. (If you would like the Profiling Perspective to open by default in the future, mark the 'Remember my decision' checkbox.)

The Profiling Perspective will open, displaying the Profiling Monitor window with the following information:

  • Profiler Information - provides general information on the profiling duration and date, number of files constructing the requested URL and more. In addition, it displays a Time Division Pie Chart for the files in the URL.
    The right side displays time division in a pie chart and the left side provides the following information:

    • URL - The URL analyzed

    • Query - The specific query parameters

    • Path - The exact location of the first file called

    • Total Request Time - Total process time of the entire page

    • Number of Files - Number of files composing the page

    • Date - Date and time that the profiling took place

Profiler Information

  • Execution Statistics - Displays the list of files constructing the URL and detailed information on functions in the files. The window contains statistics relevant to each function:

    • Function - The name and location of the function.

    • Calls Count - The number of times that the function was called.

    • Average Own Time - The average duration without internal calls.

    • Own Time(s) - The net process duration without internal calls.

    • Others Time(s) - Time spent on calling other files.

    • Total Time(s) - The total process duration including internal calls.

Execution Statistics

Note:

Click the 'Show as percentage' button on the toolbar to see the statistics as percentages rather than times.

  • Execution Flow - Shows the flow of the execution process and summarizes percentages and times spent on each function.

    • Function - Function name

    • File - The file in which the function is located

    • Total Execution Time - Percent of time taken per function.

    • Duration Time - Time taken per function. In milliseconds.

Profiler Execution Flow

  • Code Coverage Summary - Summary of how many lines of code were covered.

    • Element - The file / folder that was called.

    • Covered Lines (Visited / Significant / Total) - Percentage of lines covered within each file. (Visited = Number of lines covered / Significant = number of lines excluding comments and declarations/ Total = Total number of lines in the file.)

Code Coverage Summary

Clicking on the 'Covered lines' percentages will open an editor containing the debug file, with the covered lines highlighted:

Covered Lines Editor

Back to Top

Profiling PHP Web Pages

Zend Studio also allows you to profile whole applications, projects or collections of files that are already on the server.

Note:

Your server must be running the Zend Debugger or Xdebug in order for remote debugging and profiling capabilities to function.
The Zend Debugger comes bundled with Zend Studio and Zend Server. For instructions on installing and configuring Xdebug, see Installing Xdebug and Configuring Xdebug.

 

 

Instructions on how to complete a procedure

The following steps demonstrate how to profile a file on an external server:

  1. Create a file, called Person, and copy-paste the example code into it. (Click herefor the example code).
    See the "Working with the Profiler" Tutorial in Zend Studio's Online Help for the example code.

  2. Create a second file, called tryPerson, and copy-paste the example code into it. (Click herefor the example code).
    See the "Working with the Profiler" Tutorial in Zend Studio's Online Help for the example code.

  3. Save both files.

  4. Copy them to your server.

  5. Click the arrow next to the Profile button  on the toolbar and select Profile Configurations... –or- right-click the file in PHP explorer or within the file's editor window and select Profile As | Open Debug dialog.
    A Profile dialog will appear.

  6. Double-click on the PHP Web Page option to create a new profile configuration.

  7. Enter a name for the new configuration.

  8. Select the Zend Debugger to from the Server Debugger drop-down list.

  9. Ensure that your server is selected from the list.
    If you have not configured a server, click New and enter:

    1. Your server's name.

    2. The URL of its document root.

  10. Under the File/Project category, click Browse and select the "tryPerson" file. This will be the file from which the profiling process will start.

  11. Click Apply and then Profile.
    A confirmation dialog will be displayed asking whether you want to open the Profiling Perspective.

  12. Click Yes. (If you would like the Profiling Perspective to open by default in the future, mark the 'Remember my decision' checkbox.)

The Profiling Perspective will open, displaying the Profiling Monitor window with profiling information.
See PHP Perspectives and Views for details on the information displayed in the profiling perspective.

Back to Top

 

 

Related Links:

Using the Profiler
Profiling a PHP Script

Locally Profiling a PHP Script

Remotely Profiling a PHP Script

Profiling a PHP Web Page

Profiling a URL

Profiling

Profiler Preferences