Xdebug document (6) analysis of PHP scripts, _ PHP Tutorial

Source: Internet
Author: User
Tags perl script
Xdebug document (6) analyzes the PHP script ,. Xdebug document (6) analyzes PHP scripts and analyzes PHP scripts. the Xdebug built-in Analyzer allows you to find bottlenecks in scripts and visualize them with additional tools such as KcacheGrind or WinCacheGrind. Xdebug document (6) analysis of PHP scripts,

The analysis of PHP script Xdebug built-in Analyzer allows you to locate the bottleneck in the script and visualize it with additional tools such as KcacheGrind or WinCacheGrind.

Introduction

Xdebug analyzer is a powerful analyzer that analyzes PHP code and determines the bottleneck or determines where the code runs too slowly. The output information of the Xdebug2 analyzer is expressed by the cachegrind-compatible file. This allows you to use the excellent KcacheGrind tool (Linux, KDE) to analyze data. If you use Linux, you can install it in your installation manager.

A pre-compiled QcacheGrind binary installation package is available in Windows (QCacheGrind is a KcacheGrind version not bound to KDE)

If you use a Mac system, we will introduce how to install QcacheGrind.

Windows users can also choose to use WinCacheGrind. However, its functions are different from those of KcacheGrind, so this article does not introduce this software here. When Xdebug2.3 was published, WinCacheGrind still does not support cachegrind compression and files.

If you do not use KDE (or do not want to use it), the kcachegrind package also carries the perl script "ct_annotate" to analyze the tracing file output ASCII.

Start analysis

Set xdebug. profiler_enable in Php. ini to 1 to enable analysis. Run the xdebug command to enable analysis and write it to the directory specified by xdebug. profiler_output_dir. The generated file name generally starts with "cachegrind. out", and ends with the crc32 hash value in the PHP (or apache) process PID (process ID) or including the initial debugging script directory. Make sure that your xdebug. profiler_output_dir Directory has enough space to save and analyze complex scripts to generate huge analysis data. For example, eZ Publish, a complex application with more than MB.

You can also set xdebug. profiler_enable_trigger to 1 to manually enable analyzer. When it is set to 1, you can allow the analyzer to use the variable named XDEBUG_PROFILE to GET/POST or COOKIE values. The FireFox 2 extension can also be used to enable debugger (refer to HTTP Debug Sessions. To properly run the trigger, set xdebug. profiler_enable to 0.

Analysis output

After the analysis result is generated, you can use KCacheGrind to open it:

Once the file is opened, KCacheGrind has different panels that provide sufficient information for your reference. On the left side, you can see that the "Flat Profile" panel lists all the script functions in the order of time consumed, including their Subfunction time. The second column "Self" shows the time spent by this function (excluding subfunctions). The third column "Called" indicates the frequency of calls. The last column "functions" shows the function name. Xdebug changes the internal function name of PHP and adds the prefix "php:" to the function name. The referenced file is also processed in the specified method. The call include command follows ":" and the referenced file name. you can see "include:/home/httpd/ez_34/v... "and memory function example" php: mysql_query ". The number of the first two columns can represent the percentage of the total running time (see the example) or absolute time (Unit 1 represents one second of 1/1. 000.000 ). You can use the buttons on the right to switch between the two modes.

The right panel contains the upper and lower panels. The upper panel shows which function has called the selected function (medium "eztemplatedesignresource-> executecompiledtemplate). The lower panel displays the list of functions called by the selected function.

The Cost column on the upper panel shows the time spent when the selected function is called in the list. This number is usually 100% in the Cost column. The Cost column in the lower panel shows the time spent by the function called in the list. Among the numbers in this column, you will never see the function that reaches the 100% execution time.

"All Callers" and "All CILS" display not only the direct call of the function to be executed separately, but also the more upper and lower-level relations of the function. The upper-layer panel displays all function columns of the currently selected function call. other functions with direct and indirect relationships are in the middle of the stack. (Limited translation capabilities ...... The original statement is as follows: 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 indicates how many function calls are in the list, and the currently selected function calls are (-1 ). If the two functions have different distances, a range value (for example, "5-24") is displayed "). The numbers in parentheses represent the average value. The lower panel is similar to the display, but the difference is that it displays all function information of the currently selected function call, whether directly or indirectly.

Settings

Xdebug. profiler_append

Type:Integer, Default value:0

When set to 1, the analysis File works when the new request maps to the same file (depending on xdebug. profiler_output_name) does not overwrite the analysis results, but adds the analysis information to the end to form a new analysis file.

Xdebug. profiler_enable

Type:Integer, Default value:0

The analyzer that enables Xdebug can create analysis files in the profile output directory. These files can be read by KcacheGrind and analyzed visually. This setting cannot be set in the script using ini_set. If you want to enable analyzer selectively, you can use xdebug. profiler_enable_trigger to set it to 1 instead.

Xdebug. profiler_enable_trigger

Type:Integer, Default value:0

When set to 1, you can use the GET/POST parameter of XDEBUG_PROFILE or set the cookie value of XDEBUG_RPOFILE to trigger the generation of the analysis file. Write and analyze data to a predefined Directory. in order not to generate the analysis file in each request, you must set xdebug. profiler_enable to 0. The access trigger may have been configured with xdebug. profiler_enable_trigger_value.

Xdebug. profiler_enable_trigger_value

Type:String, Default value:"", StartsXdebug> 2.3

As described in xdebug. profiler_enable_trigger, this setting is used to limit who can use the XDEBUG_PROFILE function. When the default value of the original null string is changed, the cookie, GET, or POST parameter values must match the shared secret set and enable the analyzer with the settings.

Xdebug. profiler_output_dir

Type:String, Default value:/Tmp

This directory is the output of the analysis File. make sure that the account running PHP has the write permission for this directory. This setting cannot be set in the script using ini_set.

Xdebug. profiler_output_name

Type:String, Default value:Cachegrind. out. % p

This setting determines the name of the analysis file, which can be specified by the format identifier, similar to sprintf () and strftime (). There are several identifiers that can format the file name. For more information, see xdebug. trace_output_name.

Related functions

String Xdebug_get_profiler_filename ()

Returns the name of the currently saved analysis file.

Analyze (6) analyze the PHP script and analyze the PHP script Xdebug built-in analyzer so that you can locate the bottleneck in the script and visualize it with additional tools such as KcacheGrind or WinCacheGrind ....

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.