php 函数追踪扩展 phptrace

介绍

phptrace 是一个低开销的用于跟踪、分析 php 运行情况的工具。

它可以跟踪 php 在运行时的函数调用、请求信息、执行流程、并且提供有过滤器、统计信息、当前状态等实用功能。

在任何环境下,它都能很好的定位阻塞的问题以及在高负载下进行 denbug

官方源码:https://github.com/Qihoo360/phptrace。

安装

pecl 方式安装

$ pecl install trace

源码方式安装

$ wget https://pecl.php.net/get/trace-1.0.0.tgz # 下载源码
$ tar -xf trace-1.0.0.tgz # 解压文件
$ cd trace-1.0.0/extension # 进入扩展目录

源码编译

$ whereis php-config # 找到 php-config 的路径
$ phpize
$ ./configure --with-php-config=/usr/bin/php-config # 这里的 --with-php-config 是上一步找到的路径
$ make # 编辑
$ make test # 编译测试
$ make cli # 命令行工具
$ make install-all # 安装 php 扩展,命令行工具到 php 目录

修改 php.ini

php.ini 配置文件中增加以下配置信息。

[phptrace]
extension=trace.so
phptrace.enabled=1

注:修改 php.ini 后,需要手动重启 php-fpm

检查是否生效

root@639ca1f15214:~# php -m | grep trace
trace

实际测试

root@639ca1f15214:/var/www# php -r 'for ($i = 0; $i < 20; $i++) { sleep(5); }' &
[1] 361
root@639ca1f15214:/var/www# phptrace -p $!
process attached
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 4.966s 4.966s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.002s 5.002s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.002s 5.002s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 4.966s 4.966s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.003s 5.003s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.000s 5.000s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 5.001s 5.001s
[pid 361] > sleep(5) called at [Command line code:1]
[pid 361] < sleep(5) = 0 called at [Command line code:1] ~ 4.967s 4.967s
[pid 361]> swoole_call_user_shutdown_begin() called at [(null):0]
[pid 361]< swoole_call_user_shutdown_begin() = true called at [(null):0] ~ 0.000s -79.912s
[pid 361]< cli php for ($i = 0; $i < 20; $i++) { sleep(5); }
process detached

php 函数追踪扩展 phptrace的更多相关文章

  1. ES6 - Note3:数组、对象与函数的扩展

    一.数组的扩展,ES6在数组扩展了一些API,以实现更多的功能 1.Array.from:可以将类数组和可遍历的数据结构转换成真正的数组,如下所示 var a = { '0':1,'1':1,leng ...

  2. ES6入门之函数的扩展

    函数js原有的: 属性:arguments[].caller(调用该函数的引用,注意与callee分别开,callee指的是调用函数本身经常在递归中出现).length(形参个数).prototype ...

  3. 编译器对C++ 11变参模板(Variadic Template)的函数包扩展实现的差异

    编译器对C++ 11变参模板(Variadic Template)的函数包扩展实现的差异 题目挺绕口的.C++ 11的好东西不算太多,但变参模板(Variadic Template)肯定是其中耀眼的一 ...

  4. sqlserver 只有函数和扩展存储过程才能从函数内部执行

    一个SQLServer的自定义函数中调用一个自定义的存储过程,执行此函数后发出如下提示:“只有函数和扩展存储过程才能从函数内部执行". 原因:函数只能使用简单的sql语句,逻辑控制语句,复杂 ...

  5. ES6_入门(6)_函数的扩展

    // 2017/7/22 /*ES6函数的扩展*/ //ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; ...

  6. ES6的新特性(7)——函数的扩展

    函数的扩展 函数参数的默认值 基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console ...

  7. ES6学习(二):函数的扩展

    chapter07 函数的扩展 7.1 函数默认值 7.1.1 参数默认值简介 传统做法的弊端(||):如果传入的参数相等于(==)false的话,仍会被设为默认值,需要多加入一个if判断,比较麻烦. ...

  8. ES6学习笔记(6)----函数的扩展

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 函数的扩展 函数的默认值 : ES6可以为函数指定默认值 (1)指定默认值的两种方式 a.函数参 ...

  9. ES6__函数的扩展

    /** * 函数的扩展 * 1 为函数参数指定默认值 * 2 函数的 rest 参数 * 3 箭头函数 */ // ------------------------------------------ ...

随机推荐

  1. python lambda 用途

    可以让一个带参数函数,传递并以无参调用 def test(a): print a a=test # #a() a=897987 fun=lambda : test(a) fun()

  2. unitychan-crs 头发随动脚本

    // //SpringCollider for unity-chan! // //Original Script is here: //ricopin / SpringCollider.cs //Ro ...

  3. Pix mesa 自动化测试

    最近在准备PIX的认证, 需要进行mesa测试. 但是Mesa的标准测试工具中没有针对PIX的TestCase, 只是提到NIST的web测试.路径为:http://pixpdqtests.nist. ...

  4. mezzanine安装配置

    ubuntu 14.04 cd /var/wwwmkdir testingcd testingvirtualenv venv --python=python3. venv/bin/activate p ...

  5. Azure上采用Powershell从已有的VHD创建VM

    刚刚的一篇Blog采用Json Template的方式从已有的VHD创建了一台新的VM.由于Json Template封装的比较好,可以改的内容不多. 下面将介绍通过用Powershell来从已有的V ...

  6. VS编译linux项目生成静态库并在另一个项目中静态链接的方法

    VS2017也推出很久了,在单位的时候写linux的服务端程序只能用vim,这让用惯了IDE的我很难受. 加上想自己撸一套linux上的轮子,决定用VS开工远程编写调试linux程序. 在window ...

  7. Oracle 备份与恢复基础

    Oracle 备份与恢复基础 :三思笔记 备份与恢复 A whole database backup is either a consistent backup or an inconsistent ...

  8. C++11 引用叠加规则和模板参数类型推导规则

    http://zm8.sm-img2.com/?src=http%3A%2F%2F***%2FArticle%2F38320&uid=57422b713ac761e653af7b327bfd9 ...

  9. ajax补充FormData

    一.回顾上节知识点 1.什么是json字符串? 轻量级的数据交换格式 2.定时器:关于setTimeout setTimeout(foo,3000)  # 3000表示3秒,foo表示一个函数,3秒后 ...

  10. MySQL查询某个字段为某值的次数统计SQL语句

    SELECT GoodID,sum(if(Level = 1, 1, 0)) as Better,sum(if(Level = 0, 1, 0)) as Nomal,sum(if(Level = -1 ...