xhprof is a PHP performance analysis and debugging tool developed and maintained by Facebook engineers. Compared with xdebug, it is lighter and more resource-saving. It is highly recommended for everyone to use. The following article mainly introduces relevant information about the installation and use of the PHP performance analysis tool xhprof. Friends in need can refer to it.
Preface
xhprof is a PHP performance monitoring tool open sourced by Facebook. It takes up very little resources and can even be deployed in a production environment. .
It can be used in conjunction with graphviz, which can intuitively display the code execution time in the form of pictures.
The following mainly talks about the installation and usage process
1. Installation
(1) Download and decompress
wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar zxvf xhprof-0.9.4.tgz
(2) Compile and run
cd xhprof-0.9.4/extension/ phpize //此语句编译PHP扩展的工具,主要是根据系统信息生成对应的configure文件,一般存放在/usr/local/php/bin/目录下 ./configure --with-php-config=/usr/local/php/bin/php-config make && make install mkdir /tmp/xhprof
(3) Edit php.ini:
[xhprof] extension = xhprof.so xhprof.output_dir=/tmp/xhprof
xhprof. output_dir is the saving path of the analysis generated log
(4) Install the plug-in
The last return array means it is installed. Don’t worry about what the specific values mean, because there is UI configuration 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
//找到你要分析的代码,在代码开始处添加,start profiling,将会统计内存占用情况 xhprof_enable(XHPROF_FLAGS_MEMORY); //具体代码 //在代码结束位置添加 $xhprof_data = xhprof_disable(); // stop profiler, display raw xhprof data for the profiler run include_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
for xhprof in (2)- 0.9.4/xhprof_html To configure an accessible site, you can simply use PHP's built-in server
cd xhprof-0.9.4/xhprof_html php -S 0.0.0.0:8990
and then access the ip port to report.
2. Instructions for use
Function Name: Method name.
Calls: The number of times the method has been called.
Calls%: The number of method calls as a percentage of the total number of method calls at the same level.
Incl.Wall Time(microsec): The time it takes for method execution, including the execution time of sub-methods. (Unit: microseconds)
IWall%: The percentage of time spent in method execution.
Excl. Wall Time (microsec): The time it takes to execute the method itself, excluding the execution time of sub-methods. (Unit: microseconds)
EWall%: The percentage of time spent executing the method itself.
Incl. CPU(microsecs): The CPU time spent on method execution, including the execution time of sub-methods. (Unit: microseconds)
ICpu%: The percentage of CPU time spent in method execution.
Excl. CPU (microsec): The CPU time spent executing the method itself, excluding the execution time of sub-methods. (Unit: microseconds)
ECPU%: The percentage of CPU time spent executing the method itself.
Incl.MemUse(bytes): The memory occupied by method execution, including the memory occupied by sub-method execution. (Unit: bytes)
IMemUse%: The percentage of memory occupied by method execution.
Excl.MemUse(bytes): The memory occupied by the execution of the method itself, excluding the memory occupied by the execution of sub-methods. (Unit: bytes)
EMemUse%: The percentage of memory occupied by the method itself.
Incl.PeakMemUse(bytes): Incl.MemUse peak value. (Unit: Bytes)
IPeakMemUse%: Incl.MemUse peak percentage.
Excl.PeakMemUse(bytes): Excl.MemUse peak value. Unit: (Bytes)
EPeakMemUse%: Excl.MemUse peak percentage.
Note:
Summary
Articles you may be interested in:php encapsulates db Example explanation of the method of connecting the sqlite3 database
Analysis and explanation of the method of simulating http request in PHP
php implements socket Example explanation of push technology
The above is the detailed content of Installation and use of PHP performance analysis tool xhprof and related precautions. For more information, please follow other related articles on the PHP Chinese website!