Installation and use of the PHP performance analysis tool xhprof and precautions

Source: Internet
Author: User

Installation and use of the PHP performance analysis tool xhprof and precautions

Preface

Xhprof is a PHP performance monitoring tool open-source by facebook. It occupies a small amount of resources and can even be deployed in a production environment.

It can be used in combination with graphviz to display the code execution time in the form of images intuitively.

The following describes the installation and use process.

1. Installation

(1) download and decompression

wget http://pecl.php.net/get/xhprof-0.9.4.tgztar zxvf xhprof-0.9.4.tgz

(2) Compile and run

Cd xhprof-0.9.4/extension/phpize // This statement is used to compile PHP extension tools, which generate corresponding configure files based on system information, it is generally stored in the/usr/local/php/bin/directory. /configure -- with-php-config =/usr/local/php/bin/php-configmake & make installmkdir/tmp/xhprof

(3) EDIT php. ini:

[xhprof]extension = xhprof.soxhprof.output_dir=/tmp/xhprof 

Xhprof. output_dir is the path for saving the log generated by analysis.

(4) install the plug-in

The array is returned, indicating that the installation is complete. Do not worry about the specific values, because the UI configuration is shown below. It will be very intuitive!

yum -y install libjpeg freetype freetype-devel libjpeg-devel liberation-sans-fonts.noarch

Automatic Installation

yum -y install graphviz

(5) Insert code

// Find the code you want to analyze and add it at the beginning of the Code. start profiling will count the memory usage. xhprof_enable (XHPROF_FLAGS_MEMORY ); // specific code // Add $ xhprof_data = xhprof_disable () at the end of the Code; // stop profiler, display raw xhprof data for the profiler runningde_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils/xhprof_lib.php "); # Pay attention to setting the site include_path permission include_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils/xhprof_runs.php"); $ xhprof_runs = new \ XHProfRuns_Default (); // Save the run under a namespace "xhprof_foo ". // ** NOTE **: // By default save_run () will automatically generate a unique // run id for you. [You can override that behavior by passing // a run id (optional arg) to the save_run () method instead.] $ xhprof_runs-> save_run ($ xhprof_data, "xhprof_foo ");

(6) view

Configure an accessible site for the xhprof-0.9.4/xhprof_html in (2) and use php's built-in server

cd xhprof-0.9.4/xhprof_htmlphp -S 0.0.0.0:8990

Then, access the ip address + port to report.

2. Instructions for use

  • Function Name: method Name.
  • CILS: the number of times a method is called.
  • CILS %: percentage of the number of method Calls in the total number of Calls to the same level.
  • Incl. Wall Time (microsec): The Time taken to execute a method, including the execution Time of sub-methods. (Unit: microseconds)
  • IWall %: percentage of time spent on method execution.
  • Excl. Wall Time (microsec): The Time taken to execute the method itself, excluding the execution Time of the sub-method. (Unit: microseconds)
  • EWall %: percentage of time spent on method execution.
  • Incl. CPU (microsecs): the CPU time used for method execution, including the execution time of sub-methods. (Unit: microseconds)
  • ICpu %: Percentage of CPU time consumed by method execution.
  • Excl. CPU (microsec): the CPU time consumed by the method itself, excluding the execution time of sub-methods. (Unit: microseconds)
  • ECPU %: Percentage of CPU time consumed by method execution.
  • Incl. MemUse (bytes): Memory occupied by method execution, including the memory occupied by sub-method execution. (Unit: bytes)
  • IMemUse %: Percentage of memory occupied by method execution.
  • Excl. MemUse (bytes): Memory occupied by method execution, excluding the memory occupied by sub-method execution. (Unit: bytes)
  • EMemUse %: Percentage of memory occupied by method execution.
  • Incl. PeakMemUse (bytes): the peak value of Incl. MemUse. (Unit: bytes)
  • IPeakMemUse %: Percentage of Incl. MemUse peaks.
  • Excl. PeakMemUse (bytes): Excl. MemUse peak value. Unit: (bytes)
  • EPeakMemUse %: Excl. MemUse peak percentage.

Note:

1. Make sure that the normal data output is not affected before it is officially enabled. After confirming that the output content is the same, go online again.

2. Do not set the value of max_time for each url to be too small.

3. xhprof will affect the performance of online services. Therefore, it is best to monitor the service on only one machine, or modify the xhprof. php code to randomly monitor requests.

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

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.