锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

php7 安装PHP性能分析扩展XHPROF

时间:2023-01-03 07:30:00 ecpu电容

1.克隆

git clone https://github.com/longxinH/xhprof

2.安装(phpize和./configure你必须为自己安装php版本)

cd xhprof/extension/

phpize

./configure --with-php-config=/usr/local/php/7.2/bin/php-config

make

make install

3.修改php.ini并重启

# vi /etc/php/7.2/php.ini

; 内容为:

extension = xhprof.so

; 注意:output_dir 必须存在和可写

xhprof.output_dir = /tmp/xhpro

然后重启apache服务

# service php-fpm restart 或 service httpd restart

4.使用

// start profiling

xhprof_enable(XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

// run program

...

// stop profiler

$xhprof_data = xhprof_disable();

//

// Saving the XHProf run

// using the default implementation of iXHProfRuns.

// include 下载的xhprof包

include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";

include_once $XHPROF_ROOT . "/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.]

// 两种写入方式

$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");

/*file_put_contents(

"/srv/log/xhprof" . DIRECTORY_SEPARATOR . uniqid() . '.myapplication.xhprof',

serialize($xhprof_data)

);*/

//如果项目入口文件与目录相同,请访问以下地址

http://test.com/xhprof_html/

http://test.com/xhprof_html/index.php?run=5cd528dc4fafd&source=xhprof_foo

echo "---------------\n".

"Assuming you have set up the http based UI for \n".

"XHProf at some address, you can view run at \n".

"http:///index.php?run=$run_id&source=xhprof_foo\n".

"---------------\n";

5.graphviz

graphviz绘制图形的工具可以让你更直观地看到性能的瓶颈。

wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz

cd graphviz-2.24.0

./configure

make && make install

或者

yum install libpng

yum install graphviz

ubuntu

sudo apt-get install graphviz

6.补充解释

Function Name:方法名称。

Calls:调用方法的次数。

Calls%:同级方法总数调用次数中方法调用次数的百分比。

Incl.Wall Time(microsec):该方法的执行时间,包括子方法的执行时间。(单位:微秒)

IWall%:执行方法所花费的时间百分比。

Excl. Wall Time(microsec):方法本身的执行时间不包括子方法的执行时间。(单位:微秒)

EWall%:执行方法本身所需的时间百分比。

Incl. CPU(microsecs):执行方法的费用CPU时间,包括子方法的执行时间。(单位:微秒)

ICpu%:执行方法的费用CPU时间百分比。

Excl. CPU(microsec):实施方法本身的费用CPU时间,不包括子方法的执行时间。(单位:微秒)

ECPU%:方法本身执行费用。CPU时间百分比。

Incl.MemUse(bytes):该方法占用的内存,包括子方法占用的内存。(单位:字节)

IMemUse%:方法占用的内存百分比。

Excl.MemUse(bytes):方法本身占用的内存不包括子方法占用的内存。(单位:字节)

EMemUse%:方法本身占用的内存百分比。

Incl.PeakMemUse(bytes):Incl.MemUse峰值。(单位:字节)

IPeakMemUse%:Incl.MemUse峰值百分比。

Excl.PeakMemUse(bytes):Excl.MemUse峰值。单位:(字节)

EPeakMemUse%:Excl.MemUse峰值百分比。

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章