使用tideways绘制php callgraph(profiling)
来源:互联网 发布:网络传真 编辑:程序博客网 时间:2024/06/14 15:17
零. 概述
tideways是一款付费的在线应用,其诸多强大功能可见这里。
你可以在官网上注册,并免费使用一个月。如果想继续使用,又不想付费怎么办?答:换个邮箱!
本文主要讲述如何用tideways绘制php callgraph(profiling)。
从callgraph上,你可以很清楚的看到:
- php函数调用关系
- 每步执行时间
- 函数执行次数
并依此对代码进行优化。
相比于xdebug和xhprof, tideways的优势如下:
- 支持代码级定制(xdebug只能在php.ini设置)
- 持续维护,支持php7及以上版本(xhprof已不再维护)
- 更丰富的UI和在线功能支持
一.安装
echo "[tideways]name = Tidewaysbaseurl = https://s3-eu-west-1.amazonaws.com/qafoo-profiler/rpm" > /etc/yum.repos.d/tideways.reporpm --import https://s3-eu-west-1.amazonaws.com/qafoo-profiler/packages/EEB5E8F4.gpgyum makecache --disablerepo=* --enablerepo=tidewaysyum install tideways-php tideways-cli tideways-daemon
php -m 查看是否安装成功–看是否有tideways
执行
<?php$result = class_exists('Tideways\Profiler');var_dump($result);
得到true
cat /etc/php.d/40-tideways.ini查看配置
; Configuration for Tideways Profiler Extension; priority=40extension=tideways.so; Tideways Application API-Key to configure when using just one application on; this php installation.;tideways.api_key=; Configure the profiling sample rate for this PHP server globally. The given; number is an integer representing percent between 0 and 100tideways.sample_rate=25; Automatically detect transactions and exceptions of a given framework The; following frameworks are currently supported:;; symfony2, symfony2c, shopware, oxid, magento, zend1, zend2, laravel,; wordpress;tideways.framework=
二. 界面上添加应用(application)
1. 建立Organization
主面板右上角设置–>Organizations
2. 建立application
主面板右上方–>Create Application
三.数据采集
1. 配置
1.1 获取application对api_key
- 主面板上,点击相应application。
- 在applicationd主界面点上方导航条settings
- 在settings页面中能得到API Key。
1.2 配置
- php.ini中的配置
tideways.api_key=1.1中的api_keytideways.sample_rate=25 //采样率,采集相应百分比的请求
如果是在php.ini中进行配置,对于来自浏览器的请求,要重启fpm才生会生效。
- 直接在php代码中配置
if (class_exists('Tideways\Profiler')) { \Tideways\Profiler::start(array( 'api_key' => 'a68KSPOFqNKdyC7W', 'sample_rate' => 100, ));}
- 更多配置方法参考这里
2. 启动tideways-daemon
- service tideways-daemon start
- 停止使用stop
- 日志通常位于/var/log/tideways/daemon.log(可以通过ps -ef| grep tideways-daemon确认)
更多关于tideways-daemon的配置参见这里
3. 触发trace
直接通过http请求触发php代码执行即可(通过浏览器,curl等都可以)。如果sample_rate是100,每个请求都会触发trace。
4. 触发callgraphtrace(profiing)
与3一样,只是相应的http请求需要带上特定参数。参数获取方法如下:
- 主页面板中点击相应applicaiton
- 在applicationd主界面中点击TriggerTrace
- 在新打开的页面中找到“Using GET-Parameters”,从文本框中复制请求参数,接到你原有的http GET请求参数后面即可。
5. 查看
- 主页面板中点击相应applicaiton
- 在applicationd主界面中点击All Traces
- 有图钉标识的为带有callgraph信息的trace, 其它为普通trace
一个callgraph的示例如下
6. 可能碰到的问题及解决
这里列的比较详细,请猛击!
四.其它
1. 如何对命令行程序触发callgraphtrace?
- 主界面点击右上角设置–>User Settings
- 新页面中点左侧>_console(链接)
- 页面上获取 cli setting,类似下面这样
tideways import "https://profiler.qafoolabs.com/api/cli-import-settings/7260?hash=eb9e77a5536029976a1508d0c9caecc0c4e87d238ecaa6b061b84ed400b9a17f&time=1509590786"
- 在命令行下执行上述命令
- 执行所要采样的php代码即可
tideways run sogo/yaokan php entry.php Test
其中sogo是Organization名子,yaokan是Application名字
2. 给trace起个名字
如果不做处理,每个trace都叫default,不方便查找。
可以使用如下代码给trace命名。注意,要在Tideways\Profiler::start()之后调用。
\Tideways\Profiler::setTransactionName($transactionName);
完整示例
if (class_exists('Tideways\Profiler')) { \Tideways\Profiler::start(array( 'api_key' => 'a68KSPOFqNKdyC7W', 'sample_rate' => 100, )); $transactionName = $_SERVER['SCRIPT_NAME'];//可以用你希望的任何规则定义 \Tideways\Profiler::setTransactionName($transactionName);}
3. 如何采集sql语句执行时间
- application setting界面“Detailed SQL Profiling”, 板块点击“enable”
- 触发callgraphtrace采集
- 在界面上查看采集数据详情,其中的timeline中可以看到sql执行时间
- 使用tideways绘制php callgraph(profiling)
- Tideways和xhgui打造PHP非侵入式监控平台
- 使用PHP绘制统计图
- 使用PHP绘制统计图
- profiling 的使用
- Mysql Profiling的使用
- MySQL Profiling 的使用
- MySQL Profiling 的使用
- MySQL Profiling的使用
- MySQL Profiling 的使用
- 使用PHP绘制电场线
- profiling和trace语句使用
- 性能-MySQL Profiling 的使用
- [置顶] Debugging and Profiling PHP with Xdebug
- MySQL中profiling的使用 简介
- 如何使用oprofile对软件做profiling
- android DDMS method profiling 工具使用分析
- 如何在php中使用Libchart绘制中文的图表
- js 获取前天、昨天、今天、明天、后天的时间
- 学习的开始,学习Python的输入与输出
- 三分钟教你读懂票据是什么
- android权限大全
- 15算法课程 168. Excel Sheet Column Title
- 使用tideways绘制php callgraph(profiling)
- oracle_16进制与10进制转换
- Java定时器
- 假装是一个成功的布局——1、配置
- oracle 使用with insert插入数据的问题
- 第六章基于栈的矩阵链乘
- Android横竖屏切换小结(重建、非重建Activity)
- 新用户如何获得阿里云优惠怎么才能省钱-写给阿里云新手
- ExpressRoute 概述