zoukankan      html  css  js  c++  java
  • Xhprof安装笔记(PHP性能监控)

    由facebook开源出来的一个PHP性能监控工具,占用资源很少,甚至能够在生产环境中进行部署。
    它可以结合graphviz使用,能够以图片的形式很直观的展示代码执行耗时
    wget http://pecl.php.net/get/xhprof-0.9.4.tgz
    tar zxvf xhprof-0.9.4.tgz
    cd xhprof-0.9.4/extension/
    /usr/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make && make install
    mkdir /tmp/xhprof
    chown -R www:www /usr/local/src/xhprof-0.9.4
    # 编辑php.ini: [xhprof] extension = xhprof.so xhprof.output_dir=/tmp/xhprof 重启服务 service php-fpm restart # 最后返回数组,就表示安装好了。具体哪些值是什么意思先别管,因为下面有UI的配置。会很直观! yum -y install libjpeg freetype freetype-devel libjpeg-devel liberation-sans-fonts.noarch 自动安装 yum -y install graphviz 为Xhprof配置一个访问站点(虚拟主机) 比如做一个虚拟域名 dev.xhprof.com 绑定到xhprof的站点根目录 /usr/local/xhprof-0.9.4/xhprof_html # 找到你要分析的代码,在代码开始处添加,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.] $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); $str = " ------------------ ". "Assuming you have set up the http based UI for ". "XHProf at some address, you can view run at ". "http://dev.xhprof.com/index.php?run=$run_id&source=xhprof_foo". " ------------------ "; echo nl2br($str); 然后进入程序输出的网址(比如 http://dev.xhprof.com/index.php?run=52c0ea0bef834&source=xhprof_foo ),进行查看 下面是一些参数说明 Inclusive Time 包括子函数所有执行时间。 Exclusive Time/Self Time 函数执行本身花费的时间,不包括子树执行时间。 Wall Time 花去了的时间或挂钟时间。 CPU Time 用户耗的时间+内核耗的时间 Inclusive CPU 包括子函数一起所占用的CPU Exclusive CPU 函数自身所占用的CPU 点击 [View Full Callgraph] 能够以图文的形式查看,很方便 注意: 需要使用ctype这个扩展,Callgraph图片生成依赖一些PHP系统级的函数,所以,最好去掉 php.ini 中的函数禁用
  • 相关阅读:
    Android sendToTarget
    OSI七层模型具体解释
    JAVA中字符串比較equals()和equalsIgnoreCase()的差别
    [Angular 2] ng-class and Encapsulated Component Styles
    [Angular 2] Passing data to components with @Input
    [Angular 2] Template property syntax
    [Angular 2] Adding a data model
    [Angular 2] Using ng-model for two-way binding
    [Angular 2] ngFor
    [Angular 2] Inject Service
  • 原文地址:https://www.cnblogs.com/funsion/p/5738302.html
Copyright © 2011-2022 走看看