Xdebug documentation (vi) parsing PHP scripts

Source: Internet
Author: User
Tags perl script

Parsing PHP script Xdebug built-in parser allows you to find bottlenecks in your scripts and visualize them with additional tools such as Kcachegrind or Wincachegrind tools.

Introduced

The Xdebug parser is a powerful parser that parses PHP code and identifies bottlenecks or determines where code runs too slowly to use accelerators. The parser output information of the XDEBUG2 is formed in a cachegrind compatible file. This allows you to analyze data using a good kcachegrind tool (LINUX,KDE). If you use Linux you can install it in your Setup Manager.

There is also a precompiled Qcachegrind binary installation package available under Windows (Qcachegrind is Kcachegrind version not bundled with KDE)

If you are using a Mac system, here are some details on how to install Qcachegrind.

Windows users can also choose to use Wincachegrind. But its function is not the same as Kcachegrind so this article does not introduce this software. Wincachegrind currently does not support Cachegrind compression features and files when Xdebug2.3 is published.

If you do not use KDE (or do not want to), the Kcachegrind package also carries the Perl script "Ct_annotate" to parse the trace file output ASCII.

Start analysis

The php.ini setting xdebug.profiler_enable is set to 1 to enable analysis. This setting command Xdebug enables parsing and writes to the directory specified by Xdebug.profiler_output_dir. The resulting file name usually begins with "Cachegrind.out" and then ends with the PHP (or Apache) process PID (process ID) or the CRC32 hash that contains the initial debug script directory. Make sure your Xdebug.profiler_output_dir settings directory has enough space to store analytics to generate huge analytical data for complex script analysis. For example, there are more than 500MB of complex applications EZ Publish.

You can also manually turn on the parser via Xdebug.profiler_enable_trigger set to 1. When it is set to 1, you can have the parser use a variable named Xdebug_profile to take advantage of the Get/post or COOKIE value. The FireFox 2 extension can be used to turn on debugger (refer to HTTP Debug Sessions) and can be used with this setting. In order for the trigger to run reasonably, the xdebug.profiler_enable needs to be set to 0.

Analysis output

When the results of the analysis are generated, you can open it with Kcachegrind:

Once the file is opened, Kcachegrind will have a different panel to provide you with sufficient information for your reference. On the left you can see that the Flat profile panel lists all the script functions and takes time to order, and also includes its child function time. The second column, "Self," shows the time spent by the function (excluding child functions), the third column "called" refers to the frequency of the call, and the last column "functions" displays the function name. Xdebug changes the internal function name of PHP and prefixes "PHP::" In the function name, and the reference file is processed in the specified manner. The call include command follows "::" and the referenced file name. On the left you can see "include::/home/httpd/ez_34/v ..." and the Memory function example "Php::mysql_query". The number of the first two columns can be expressed as a percentage of the total elapsed time (see example) or absolute time (unit 1 represents one second of 1/1.000.000). You can use the button on the right to switch between the two modes.

The right panel contains both upper and lower panels. The upper panel shows which function called the currently selected function (medium "eztemplatedesignresource->executecompiledtemplate"). The lower panel displays a list of functions that have been selected for the function call.

The cost column of the upper panel shows how long the currently selected function spends when it is called within the list. The number in the cost column is usually 100%. The lower panel cost column shows the time spent in the function called in the list. In this column of numbers, you never see a function that reaches 100% execution time.

The "all callers" and "all Calls" display are more than just direct calls performed by the function, but also show a more hierarchical relationship between functions. The upper panel in shows all the function columns of the currently selected function call, and the other functions of the direct and indirect relationships are in the middle of the stack. (limited translation capacity ...) The original sentence is this: the upper pane in the screenshot on the left shows all functions calling the current selected one, both directly an D indirectly with other functions inbetween them on the stack.) the "Distance" column represents how many function calls are in the list, and the current selection is (-1). If there is a different distance between the two functions, a range value (for example: "5-24") is displayed. The numbers in parentheses represent the average. The lower panel is similarly displayed, but the difference is that it displays all the function information for the currently selected function call, either directly or indirectly.

Related Settings

Xdebug.profiler_append

Type: integer, default value: 0

When set to 1 o'clock, the analysis file work is mapped to the same file under the new request (depending on xdebug.profiler_output_name) does not cover the analysis results, but the analysis information is appended to the trailer to form a new analysis file.

Xdebug.profiler_enable

Type: integer, default value: 0

The parser that opens Xdebug can create an analysis file in the profile output directory directory. These files can be read by Kcachegrind and visualized to analyze data. This setting cannot be set using Ini_set () in the script. If you want to selectively turn on the parser, you can use the Xdebug.profiler_enable_trigger setting set to 1 instead.

Xdebug.profiler_enable_trigger

Type: integer, default value: 0

Set to 1 o'clock, you can use the Xdebug_profile get/post parameter or set the Xdebug_rpofile cookie value to trigger the analysis file generation. These write analyses count to a predefined directory, so that you need to set xdebug.profiler_enable to a value of 0 in order not to generate the parsing file in each request. Access triggers may be over-xdebug.profiler_enable_trigger_value configured.

Xdebug.profiler_enable_trigger_value

Type: string, default value: " ", starting with Xdebug > 2.3

As described in Xdebug.profiler_enable_trigger, this setting is used to restrict who can take advantage of xdebug_profile functionality. When the original empty string default value is changed, the Cookie,get or post parameter values need to match the shared secret collection and open the parser with the settings.

Xdebug.profiler_output_dir

Type: string, default value:/ tmp

This directory is where the file output is analyzed, make sure that the account running PHP can have write access to the directory. This setting cannot be set in the script with Ini_set ().

Xdebug.profiler_output_name

Type: string, default value: cachegrind.out.%p

This setting determines the name of the parsing file, which can be specified using the format identifier, similar to sprintf () and strftime (). There are several identifiers that can format filenames. See the reference xdebug.trace_output_name for details.

Related functions

string xdebug_get_profiler_filename ()

Returns the file name of the currently saved profiling information.

Xdebug documentation (vi) parsing PHP scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.