Xhprof Installation && Use

Source: Internet
Author: User
Tags configuration php

listen to colleagues talk about a PHP performance analysis extension, called Xhprof, recently learned the next.

The Xhprof is a lightweight, layered performance measurement analyzer. During the data collection phase, it tracks the number of calls and the measured data, and shows the arc diagram of the program's dynamic invocation. It calculates exclusive performance metrics during the reporting and post-processing stages, such as elapsed time, CPU compute time, and memory overhead. Function performance reports can be terminated by the caller and callee. During the data collection phase, the recursive function is detected by invoking the loop of the graph, which avoids the loop of recursive calls by assigning a unique depth name to the xhprof.

below to organize my installation and how to use

1. Compile and install 
wget http://pecl.php.net/get/xhprof-0.9.2.tgz tar zxf xhprof-0.9.2.tgzcd xhprof-0.9.2/extension/sudo phpize./ Configure--with-php-config=/usr/local/php/bin/php-configsudo Makesudo make install


2, configuration php.ini 
join in the php.ini.
[Xhprof]extension=xhprof.so;; Directory used by default implementation of the Ixhprofruns; Interface (namely, the Xhprofruns_default Class) for storing; Xhprof runs.; Xhprof.output_dir=<directory_for_storing_xhprof_runs>xhprof.output_dir=/tmp/xhprof


Note: If the 64-bit system needs to copy the xhprof.so file to the relevant lib64 directory

3, add the analysis code in the PHP code 

<?pho//CPU:XHPROF_FLAGS_CPU Memory: xhprof_flags_memory//If two together: Xhprof_flags_cpu + xhprof_flags_memory xhprof_enable (Xhprof_flags_cpu + xhprof_flags_memory);//PHP code to be tested $data = xhprof_disable ();   Return to run data//Xhprof_lib in the downloaded package, the directory exists, remember to include the directory in the running PHP code include_once "xhprof_lib/utils/xhprof_lib.php";  Include_once "xhprof_lib/utils/xhprof_runs.php";  $objXhprofRun = new Xhprofruns_default (); The first parameter, J, is the run information returned by the xhprof_disable () function//The second parameter is a custom namespace string (any string),//Returns the run ID, which is used to view the associated run result $run_id = $objXhprofRun Save_run ($data, "xhprof"); Var_dump ($run _id);


4. View running Results 
Copy the xhprof_lib&&xhprof_html related directory to the address that you can access xxx/xhprof_html/index.php?run= $run _id&source=bluefrog You can see how your PHP code is running. Here are some parameter descriptions inclusive                 time includes all execution times of the child functions. Exclusive time/self  time function to execute itself, not including subtree execution time. Wall                        time or wall clock time spent. CPU                        Time user elapsed + kernel time consumed inclusive CPU includes cpuexclusive CPU functions consumed by the                  function itself


Note: This extension requires the use of CType


Reference: http://www.lai18.com/content/323747.html

Xhprof Installation && Use

Related Article

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.