tideways分享

2017-12-17  本文已影响0人  田佳伟

1.介绍

2. 实现原理

3. 安装

各个环境的安装
https://tideways.io/profiler/article/35-installation-on-php
Ubuntu安装:

echo 'deb http://s3-eu-west-1.amazonaws.com/qafoo-profiler/packages debian main' > /etc/apt/sources.list.d/tideways.list
wget -qO - https://s3-eu-west-1.amazonaws.com/qafoo-profiler/packages/EEB5E8F4.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install tideways-php tideways-daemon

4. 配置

server {
  listen 80;
  server_name site.localhost;
  root /Users/markstory/Sites/awesome-thing/app/webroot/;
  fastcgi_param PHP_VALUE "auto_prepend_file=/home/vagrant/code/xhgui-branch/external/header.php";
}
'profiler.enable' => function() {
   // url 中包含debug=1则百分百捕获
   if(!empty($_GET['debug'])){
       return True;
   }else{
       // 1%采样
       return rand(1, 100) === 42;
   }
}

如上代码,在xhgui的config/config.default.php中,可设置采样命中次数;
return rand(1, 100) === 42; 为1%的采样率,改成return True;则标识每次都采样
如果mongodb和xhgui不在同一台机器上的话,需要修改mongodb的配置,配置如下:

// Can be either mongodb or file.
   /*
   'save.handler' => 'file',
   'save.handler.filename' => dirname(__DIR__) . '/cache/' . 'xhgui.data.' . microtime(true) . '_' . substr(md5($url), 0, 6),
   */
   'save.handler' => 'mongodb',
   // Needed for file save handler. Beware of file locking. You can adujst this file path
   // to reduce locking problems (eg uniqid, time ...)
   //'save.handler.filename' => __DIR__.'/../data/xhgui_'.date('Ymd').'.dat',
   'db.host' => 'mongodb://127.0.0.1:27017',
   'db.db' => 'xhprof',
mongo
 > use xhprof
 > db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
 > db.results.ensureIndex( { 'profile.main().wt' : -1 } )
 > db.results.ensureIndex( { 'profile.main().mu' : -1 } )
 > db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
 > db.results.ensureIndex( { 'meta.url' : 1 } )

5. 使用

XHGui的详细使用教程: http://blog.oneapm.com/apm-tech/219.html

image.png

参考资料

下边是PHP性能分析和PHP性能调优的三篇文章

中文翻译版:

PHP 性能分析第一篇: Xhprof & Xhgui 介绍
PHP 性能分析第二篇: Xhgui In-Depth
PHP 性能分析第三篇: 性能调优实战

英文原版:
Profiling PHP Part 1: Intro to Xhprof & Xhgui
Profiling PHP Part 2: Xhgui In-Depth
Profiling PHP Part 3: Practical Performance Tuning

上一篇 下一篇

猜你喜欢

热点阅读