PHP Performance analysis tool XHPROF installation use and precautions

Source: Internet
Author: User

Objective

Xhprof, a PHP performance monitoring tool that is open source by Facebook, consumes little resources and can even be deployed in a production environment.

It can be used in conjunction with Graphviz, and can visually demonstrate the time-consuming execution of code in the form of pictures.

The following main talk about the installation and use of the process

1. Installation

(1) Download and decompress

12 wget http://pecl.php.net/get/xhprof-0.9.4.tgztarzxvf xhprof-0.9.4.tgz

(2) Compiling and running

12345 cd xhprof-0.9.4/extension/phpize //此语句编译PHP扩展的工具,主要是根据系统信息生成对应的configure文件,一般存放在/usr/local/php/bin/目录下./configure --with-php-config=/usr/local/php/bin/php-configmake && make install< mkdir /c19> /tmp/xhprof

(3) Edit php.ini:

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

Xhprof.output_dir is the save path for the profiling build log

(4) Install plug-in

Finally, the array is returned, which means the installation is ready. What are the specific values? Forget about it, because there is a configuration of the UI below. It will be intuitive!

1 yum -y installlibjpeg freetype freetype-devel libjpeg-devel liberation-sans-fonts.noarch

Automatic installation

1 yum -y installgraphviz

(5) Inserting code

1234567891011121314 //找到你要分析的代码,在代码开始处添加,start profiling,将会统计内存占用情况xhprof_enable(XHPROF_FLAGS_MEMORY);//具体代码//在代码结束位置添加$xhprof_data = xhprof_disable(); // stop profiler, display raw xhprof data for the profiler runinclude_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils/xhprof_lib.php"); # 请注意设置站点 include_path 权限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 cleanly

12 cdxhprof-0.9.4/xhprof_htmlphp -S 0.0.0.0:8990

Then access the ip+ port to report it.

2. Instructions for use

  • Function Name: Method name.

  • Calls: The number of times the method was called.

  • calls%: The percentage of the number of method invocations that are called in the total numbers of sibling methods.

  • Incl.wall Time (microsec): How long the method takes to execute, including the execution time of the child method. (Unit: microseconds)

  • iwall%: Percentage of time spent on method execution.

  • Excl. Wall time (microsec): How long the method itself takes to execute, excluding the execution time of the child method. (Unit: microseconds)

  • ewall%: The percentage of time that the method itself takes to execute.

  • Incl. CPU (MICROSECS): The CPU time spent by the method execution, including the execution time of the child method. (Unit: microseconds)

  • icpu%: Percentage of CPU time spent by method execution.

  • Excl. CPU (MICROSEC): The method itself executes the CPU time that is spent, excluding the execution time of the child method. (Unit: microseconds)

  • ecpu%: The percentage of CPU time spent by the method itself execution.

  • Incl.memuse (bytes): The memory used by the method to execute, including the memory occupied by the child method execution. (Unit: bytes)

  • Imemuse%: Percentage of memory consumed by method execution.

  • Excl.memuse (bytes): The method itself executes the occupied memory, excluding the memory occupied by the child method execution. (Unit: bytes)

  • Ememuse%: The percentage of memory consumed by the method itself.

  • Incl.peakmemuse (bytes): Incl.memuse Peak. (Unit: bytes)

  • Ipeakmemuse%:incl.memuse peak percentage.

  • Excl.peakmemuse (bytes): Excl.memuse Peak. Unit: (bytes)

  • Epeakmemuse%:excl.memuse peak percentage.

Attention:

1, before the official opening, be sure to verify that the normal data output will not be affected. Confirm that the output content is the same, then go online.

2, the max_time of each URL do not set too small.

3, Xhprof will affect the performance of online services, it is best to monitor only on a single machine, or modify the xhprof.php code, the request is randomly monitored.

Original link: 1190000012478668

PHP Performance analysis tool XHPROF installation use and precautions

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.