Xdebug  
  XDEBUG EXTENSION FOR PHP | DOCUMENTATION - PROFILER - XDEBUG 2
home | updates | installation | documentation | screenshots | license | support



INTRODUCTION

Xdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file. This allows you to use the excellent KCacheGrind tool (Linux, KDE) to analyse your profiling data.

In case you can not use KDE (or do not want to use KDE) the kcachegrind package also comes with a perl script "ct_annotate" which produces ASCII output from the profiler trace files.

STARTING THE PROFILER

Profiling is enabled by setting the xdebug.profiler_enable setting to 1 in php.ini. This instructs Xdebug to start writing profiling information into the dump directory configured with the xdebug.profiler_output_dir directive. The name of the generated file always starts with "cachegrind.out." and ends with either the PID (process ID) of the PHP (or Apache) process or the crc32 hash of the current working directory. Make sure you have enough space in your dump directory as the amount of information generated by the profiler can be enormous for complex scripts, for example up to 500MB for a complex application like eZ publish.

ANALYSING PROFILES

After a profile information file has been generated you can open it with KCacheGrind:

Once the file is opened you have plenty of information available in the different panes of KCacheGrind. On the left side you find the "Flat Profile" pane showing all functions in your script sorted by time spend in this function, and all its children. The second column "Self" shows the time spend in this function (without its children), the third column "Called" shows how often a specific function was called and the last column "Function" shows the name of the function. Xdebug changes internal PHP function names by prefixing the function name with "php::" and include files are handled in a special way too. Calls to include (and include_one, require and require_once) are followed by "::" and the filename of the included file. In the screenshot on the left you can see this for "include::/home/httpd/ez_34/v..." and an example of an internal PHP function is "php::mysql_query". The numbers in the first two columns can be either percentages of the full running time of the script (like in the example) or absolute time (1 unit is 1/10.000.000th of a second). You can switch between the two modes with the button you see on the right.

The pane on the left exist of an upper and lower pane. The upper one shows information about which functions called the current selected function ("eztemplatedesignresource->executecompiledtemplate in the screenshot). The lower pane shows information about the functions that the current selected function called.

The "Cost" column in the upper pane shows the time spend in the current selected function while being called from the function in the list. The numbers in the Cost column added up will always be 100%. The "Cost" column in the lower pane shows the time spend while calling the function from the list. While adding the numbers in this list up, you will most likely never reach 100% as the selected function itself will also takes time to execute.

The "All Callers" and "All Calls" tabs show not only the direct call from which the function was called respectively all directly made function calls but also function calls made more levels up and down. The upper pane in the screenshot on the left shows all functions calling the current selected one, both directly and indirectly with other functions inbetween them on the stack. The "Distance" column shows how many function calls are between the listed and the current selected one (-1). If there are different distances between two functions, it is shown as a range (for example "5-24". The number in parentheses is the median distance. The lower pane is similar except that it shows information on functions called from the current selected one, again either direct or indirect.

more will follow soon

 
RELEASES
[29-11-2004]
Source:
Debug client 0.8.0 (binary):
[15-09-2004]
Windows modules:
[30-06-2004]
Source:
Modules for 4.3.x (binary):
Debug client 0.7.0 (binary):

DEVELOPMENT VERSION (2.0dev)
Instructions to get Xdebug 2.0dev from CVS can be found here. This version compiles on PHP 4.3.0 and higher.

BINARY SNAPSHOTS (2.0dev)
Modules for 4.3.x-dev:
Modules for 5.0.x-dev:
Modules for 5.1.x-dev:

OLDER RELEASES
Source:

 
 
This site and all of its contents are Copyright © 2002, 2003, 2004 by Derick Rethans.
All rights reserved.