美文网首页
php7 安装PHP性能分析扩展XHPROF

php7 安装PHP性能分析扩展XHPROF

作者: 俏皮但幺妹 | 来源:发表于2019-05-10 17:37 被阅读0次

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://<xhprof-ui-address>/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峰值百分比。

相关文章

  • 如何进行一次简单的性能分析

    基于xhprof开发php性能优化系统全文 安装 安装php msgpack扩展 安装php xhprof扩展 p...

  • php7 安装PHP性能分析扩展XHPROF

    1.克隆 2.安装(phpize和./configure都要针对自己要安装的php版本) 3.修改php.ini并...

  • php入门--性能测试

    PHP性能问题具体分析 工具:XHProf-性能分析扩展工具ab-压力测试vld-opcode代码分析 PHP性能...

  • laradock 中安装 xhprof

    xhprof 是 php性能分析工具 1. 添加变量来控制xhprof是否安装 进入 .env 文件,在 PHP_...

  • xhprof-php7

    facebook开源的xhprof 扩展不支持Php7, 只能在php5及以下运行。 因为xhprof抓取的内容过...

  • 记一次面试遇到的问题

    1.php性能检测(xhprof) xhprof 2.php类似redis,mc的扩展 (qrcode,phpex...

  • xhprof-PerfTool

    PHP程序分析 php代码的性能分析,推荐使用xhprof。 1、下载 2、解压到项目入口目录 开启xhprof,...

  • xhprof的使用

    简介 XHProf是一个分层PHP性能分析工具。XHProf是一个分层PHP性能分析工具。它报告函数级别的请求次数...

  • xhprof--php代码性能追踪及分析

    xhprof是什么 XHProf是facebook 开发的一个测试php性能的扩展,本文记录了在PHP应用中使用X...

  • PHP 性能追踪及分析工具(XHPROF)

    什么是 XHPROF? XHPROF:Facebook 开源的轻量级PHP性能分析工具。 它报告函数级别的请求次数...

网友评论

      本文标题:php7 安装PHP性能分析扩展XHPROF

      本文链接:https://www.haomeiwen.com/subject/rhxzoqtx.html