2开启慢日志
配置输出php-fpm慢日志,阀值为2秒:
request_slowlog_timeout = 2
slowlog = log/$pool.log.slow
利用sort/uniq命令分析汇总php-fpm慢日志:
[[email protected] log]# grep -v "^$" www.log.slow.tmp | cut -d " " -f 3,2 | sort | uniq -c | sort -k1,1nr | head -n 50
5181 run() /www/test.net/framework/web/filters/CFilter.php:41
5156 filter() /www/test.net/framework/web/filters/CFilterChain.php:131
2670 = /www/test.net/index.php
2636 run() /www/test.net/application/controllers/survey/index.php:665
2630 action() /www/test.net/application/controllers/survey/index.php:18
2625 run() /www/test.net/framework/web/actions/CAction.php:75
2605 runWithParams() /www/test.net/framework/web/CController.php:309
2604 runAction() /www/test.net/framework/web/filters/CFilterChain.php:134
2538 run() /www/test.net/framework/web/CController.php:292
2484 runActionWithFilters() /www/test.net/framework/web/CController.php:266
2251 run() /www/test.net/framework/web/CWebApplication.php:276
1799 translate() /www/test.net/application/libraries/Limesurvey_lang.php:118
1786 load_tables() /www/test.net/application/third_party/php-gettext/gettext.php:254
1447 runController() /www/test.net/framework/web/CWebApplication.php:135
参数解释:
sort: 对单词进行排序
uniq -c: 显示唯一的行,并在每行行首加上本行在文件中出现的次数
sort -k1,1nr: 按照第一个字段,数值排序,且为逆序
head -10: 取前10行数据