![]() |
||||
|
XDEBUG EXTENSION FOR PHP | DOCUMENTATION
home |
updates |
download |
documentation |
license |
support
» Documentation for: Xdebug 2 » Feature: Profiling PHP Scripts Xdebug's built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind. IntroductionXdebug'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. Users of the Windows operating system can use WinCacheGrind, the functionality is different from KCacheGrind so the section that documents the use of KCacheGrind on this page doesn't apply to this program. There is also a standalone client for Mac OSX called MacCallGrind, as well as an upcoming web front end called Carica CacheGrind. 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 ProfilerProfiling 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 directory containing the initially debugged script. Make sure you have enough space in your xdebug.profiler_output_dir 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 ProfilesAfter 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 pane on the right contains an upper and lower pane. The upper one
shows information about which functions called the current selected function
("eztemplatedesignresource->executecompiledtemplate in the screenshot).
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
Related Settingsxdebug.profiler_append
Type: integer, Default value: 0
When this setting is set to 1, profiler files will not be overwritten when
a new request would map to the same file (depnding on the xdebug.profiler_output_name setting.
Instead the file will be appended to with the new profile.
xdebug.profiler_enable
Type: integer, Default value: 0
Enables Xdebug's profiler which creates files in the
profile output directory. Those files can be
read by KCacheGrind to visualize your data. This setting can not be set in
your script with ini_set().
xdebug.profiler_enable_trigger
Type: integer, Default value: 0
When this setting is set to 1, you can trigger the generation of profiler
files by using the XDEBUG_PROFILE GET/POST parameter. This will then write the
profiler data to defined directory.
xdebug.profiler_output_dir
Type: string, Default value: /tmp
The directory where the profiler output will be written to, make sure that
the user who the PHP will be running as has write permissions to that
directory. This setting can not be set in your script with ini_set().
xdebug.profiler_output_name
Type: string, Default value: cachegrind.out.%p
This setting determines the name of the file that is used to dump traces into. The setting specifies the format with format specifiers, very similar to sprintf() and strftime(). There are several format specifiers that can be used to format the file name. See the xdebug.trace_output_name documentation for the supported specifiers. Related Functionsstring xdebug_get_profiler_filename( )
Returns the profile information filename
Returns the name of the file which is used to save profile information to. |
||||
|
This site and all of its contents are
Copyright © 2002-2009 by Derick Rethans.
All rights reserved. |
||||
