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. redis有序集合的使用

    Redis 有序集合(sorted set) Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过 ...

  2. IDEA使用操作文档

    IDEA中怎么设置黑色或白色背景? http://jingyan.baidu.com/article/4e5b3e19330df191911e246b.html 一. IntelliJ IDEA  的 ...

  3. I would I were a careless child

    I would I were a careless child by George Gordon Byron 1 I would I were a careless child, still dwel ...

  4. kong插件官方文档翻译

    kong插件官方文档翻译 目录 介绍 文件结构 编写自定义逻辑 存储配置 访问数据存储 自定义实体 缓存自定义实体 扩展Admin API 编写测试 (卸载)安装你的插件 插件开发 - 介绍 什么是插 ...

  5. django的settings文件

    转载:http://www.cnblogs.com/likeshan168/articles/3596344.html

  6. hexo博客相关

    https://www.cnblogs.com/sulishibaobei/p/6428241.html 利用hexo+github+nodejs搭建自我博客的一天 http://www.sulish ...

  7. C#获取路由器外网IP,MAC地址

    C#实现的获取路由器MAC地址,路由器外网地址.对于要获取路由器MAC地址,一定需要知道路由器web管理系统的用户名和密码.至于获取路由器的外网IP地址,可以不需要知道路由器web管理系统的用户名和密 ...

  8. Python函数-round() 函数

    round( x [, n] )功能: round() 方法返回浮点数x的四舍五入值. x-数值表达式.n-数值表达式.返回浮点数x的四舍五入值. 实例: #!/usr/bin/python prin ...

  9. VS2005环境下的DLL应用

    VS2005环境下的DLL应用 作者:一点一滴的Beer http://beer.cnblogs.com/ 以前写过一篇题为<VC++的DLL应用(含Demo演示)>的文章,当时是刚开始接 ...

  10. POJ3249(DAG上的dfs)

    Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10567   Accepted: 2482 Des ...