toolkit是tideway官方提供的性能分析的命令行工具。若是你只是本地开发调试接口性能,不想安装xhgui,那么使用toolkit就足够了php
git clone https://github.com/tideways/php-xhprof-extension.git cd php-profiler-extension phpize ./configure make && make install
在php.ini中加入git
extension=tideways_xhprof.so
重启php-fpmgithub
service php-fpm restart
go get github.com/tideways/toolkit # 安装graphviz # macOS brew install graphviz # ubuntu sudo apt-get install -y graphviz
alias tk=toolkit
在程序入口中加入shell
if (extension_loaded('tideways_xhprof')) { tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_CPU | TIDEWAYS_XHPROF_FLAGS_MEMORY); } // 你的代码 application(); if (extension_loaded('tideways_xhprof')) { $data = tideways_xhprof_disable(); file_put_contents( sprintf('%s/app.xhprof', '/path/to'), json_encode($data) ); }
执行下代码,而后就会生成/path/to/app.xphrofjson
tk analyze-xhprof /path/to/app.xphrof
默认性能分析的指标是wt_excl,其余的指标有ubuntu
tk generate-xhprof-graphviz /path/to/app.xhprof dot -Tpng callgraph.dot > callgraph.png
显示的指标有app