GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing xdebug.org — Xdebug: Documentation » Profiling ProfilingXdebug's built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or QCacheGrind. Introduction #Xdebug's Profiler is a powerful tool that gives you the ability to analyse your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler also collects information about how much memory is being used, and which functions and methods increase memory usage. The profiler in Xdebug 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. If you are on Linux you can install KCacheGrind with your favourite package manager. If you are on Windows, there are precompiled QCacheGrind binaries available. (QCacheGrind is KCacheGrind without KDE bindings). If you are on Mac OSX, homebrew has a formula for QCacheGrind. There is also a web based front-end called Webgrind. 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 #In your This instructs Xdebug to start writing profiling information into the directory configured with the xdebug.output_dir directive. The name of the generated file always starts with "cachegrind.out." and ends by default with the PID (process ID) of the PHP (or Apache) process. You can change the filename format with xdebug.profiler_output_name. Make sure you have enough space in your xdebug.output_dir as the amount of information generated by the profiler can be enormous for complex scripts. You can also selectively enable the profiler by setting
xdebug.start_with_request#trigger to Xdebug adds the HTTP header 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 spent 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 spent 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 spent 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 calls from
Related Content #
Related Settings and Functions #
Settings #string xdebug.log = #Configures Xdebug's log file. Xdebug will log to this file all file creations issues, Step Debugging connection attempts, failures, and debug communication. Enable this functionality by setting the value to a absolute path. Make sure
that the system user that PHP runs at (such as The file is opened in append-mode, and will therefore not be overwritten by default. There is no concurrency protection available. The log file will include any attempt that Xdebug makes to connect to an IDE: [2693358] Log opened at 2020-09-02 07:19:09.616195 [2693358] [Step Debug] INFO: Connecting to configured address/port: localhost:9003. [2693358] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). [2693358] [Profiler] ERR: File '/foo/cachegrind.out.2693358' could not be opened. [2693358] [Profiler] WARN: /foo: No such file or directory [2693358] [Tracing] ERR: File '/foo/trace.1485761369' could not be opened. [2693358] [Tracing] WARN: /foo: No such file or directory [2693358] Log closed at 2020-09-02 07:19:09.617510 It includes the opening time ( It includes:
For Step Debugging: INFO: Connecting to configured address/port: localhost:9003. ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). For Profiling: ERR: File '/foo/cachegrind.out.2693358' could not be opened. WARN: /foo: No such file or directory For Function Trace and Flame Graphs: ERR: File '/foo/trace.1485761369' could not be opened. WARN: /foo: No such file or directory All warnings and errors are described on the Description of errors page, with
detailed instructions on how to resolve the problem, if possible. All errors are always logged through
PHP's internal logging mechanism (configured with error_log
in Step Debugger CommunicationThe debugging log can also log the communication between Xdebug and an IDE.
This communication is in XML, and starts with the <init
xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
fileuri="file:///home/httpd/www.xdebug.org/html/router.php"
language="PHP" xdebug:language_version="7.4.11-dev"
protocol_version="1.0" appid="2693358" idekey="XDEBUG_ECLIPSE">
<engine version="3.0.0-dev"><![CDATA[Xdebug]]></engine>
<author><![CDATA[Derick Rethans]]></author>
<url><![CDATA[https://xdebug.org]]></url>
<copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright>
</init>
The Beyond the <- feature_set -i 4 -n extended_properties -v 1
-> <response
xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
command="feature_set" transaction_id="4" feature="extended_properties" success="1">
</response>
<- step_into -i 9
-> <response
xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
command="step_into" transaction_id="9"
status="break" reason="ok">
<xdebug:message filename="file:///home/httpd/www.xdebug.org/html/router.php" lineno="3">
</xdebug:message>
</response>
You can read about DBGP - A common debugger protocol specification at its dedicated documation page. The xdebug.log_level setting controls how much information is logged. Many Linux distributions now use systemd, which
implements private tmp directories. This means that when PHP
is run through a web server or as PHP-FPM, the This setting can additionally be configured through the
integer xdebug.log_level = 7 #Configures which logging messages should be added to the log file. The log file is configured with the xdebug.log setting. The following levels are supported:
Criticals, errors, and warnings always show up in the diagnostics log that you can view by calling xdebug_info(). Criticals and errors are additionally logged through
PHP's internal logging mechanism (configured with error_log
in This setting can additionally be configured through the
string xdebug.mode = develop #This setting controls which Xdebug features are enabled. This setting can only be set in The following values are accepted:
You can enable multiple modes at the same time by comma separating their
identifiers as value to xdebug.mode: XDEBUG_MODE environment variableYou can also set Xdebug's mode by setting the Some web servers have a configuration option to
prevent environment variables from being propagated to PHP and Xdebug.
string xdebug.output_dir = /tmp #The directory where Xdebug will write tracing, profiling, and garbage collection statistics to. This directory needs to be writable for the system user with which PHP is running. This setting can be changed in In some cases (when profiling, or when
xdebug.start_with_request= This setting can additionally be configured through the
Many Linux distributions now use systemd, which
implements private tmp directories. This means that when PHP
is run through a web server or as PHP-FPM, the integer xdebug.profiler_append = 0 #When this setting is set to 1, profiler files will not be overwritten when a new request would map to the same file (depending on the xdebug.profiler_output_name setting. Instead the file will be appended to with the new profile. string xdebug.profiler_output_name = 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. This setting can additionally be configured through the
string xdebug.start_with_request = default #Step Debugging, a Function Trace, Flame Graphs, Garbage Collection Statistics, or Profiling can be activated at the start of a PHP request. Whether this happens depends on the value of this setting:
string xdebug.trigger_value = "" #This setting can be used when xdebug.start_with_request is set to
In The legacy names Normally, Xdebug does not look at which value is actually used. If this setting is set to a non-empty string, then Xdebug will only trigger if the value matches the value of this setting. With the following settings: xdebug.mode=profile xdebug.start_with_request=trigger xdebug.trigger_value=StartProfileForMe Xdebug's profiler will only start when either the environment variable
From Xdebug 3.1, it is possible to configure multiple values by using a comma separated list. In that case, Xdebug will trigger if the supplied value matches any of the entries that are configured through this setting: xdebug.trigger_value=StartDebuggerForMe,StartDebuggerForYou See also:
boolean xdebug.use_compression = true #Introduced in Xdebug >= 3.1 If enabled, the Function Trace and Profiling features will create GZip compressed files as output. This reduces diskspace. If GZip compression is not supported by Xdebug, because it was not compiled in, then Xdebug will add a warning to its log and xdebug_info() diagnostics section. It is enabled by default if Xdebug has GZip support, and disable if Xdebug does not have GZip support. The QCacheGrind tool that you can use to visualise profiling information
does not support reading GZip compressed profile files, whereas KCacheGrind and
PhpStorm do. If you are a QCacheGrind user, you should set
xdebug.use_compression to Functions #xdebug_get_profiler_filename() : mixed #Returns the profile information filename
Returns the name of the file which is used to save profile information to, or
xdebug_info( ?string $category = null ) : mixed #Show and retrieve diagnostic information This function presents APIs to retrieve information about Xdebug itself. Which information gets returned, or displayed, depends on which arguments, or none at all, are given.
| |||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |