Home > Backend Development > PHP Tutorial > tideways+toolkit performs performance analysis on php code

tideways+toolkit performs performance analysis on php code

藏色散人
Release: 2023-04-07 12:58:01
forward
3088 people have browsed it

Toolkit is a command line tool for performance analysis officially provided by tideway. If you only develop and debug interface performance locally and do not want to install xhgui, then using toolkit is enough.

Install

Install tideways extension

git clone https://github.com/tideways/php-xhprof-extension.git
cd php-profiler-extension
phpize
./configure
make && make install
Copy after login

Add to php.ini

extension=tideways_xhprof.so
Copy after login

Restart php-fpm

service php-fpm restart
Copy after login

toolkit installation

go get github.com/tideways/toolkit
# 安装graphviz
# macOS
brew install graphviz
# ubuntu
sudo apt-get install -y graphviz
Copy after login

Set alias

alias tk=toolkit
Copy after login

tideways toolkit

Code Buried Point

Add

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)
    );
}
Copy after login

to the program entrance to execute the code , and then /path/to/app.xphrof

Performance Analysis

tk analyze-xhprof /path/to/app.xphrof
Copy after login

tideways+toolkit performs performance analysis on php code

The default performance analysis indicator is wt_excl , other indicators include

1.wt call duration, including sub-functions

2.excl_wt call duration, excluding sub-functions

3.cpu CPU call duration, including Subfunction

4.excl_cpu CPU call duration, excluding subfunction

5.memory memory consumption (bytes), including subfunction

6.excl_memory memory consumption ( Bytes), excluding sub-functions

7.io io duration, including sub-functions

8.excl_io io duration, excluding sub-functions

Generation performance The indicators displayed in the bottleneck chart

tk generate-xhprof-graphviz /path/to/app.xhprof
dot -Tpng callgraph.dot > callgraph.png
Copy after login

tideways+toolkit performs performance analysis on php code

#1.Function name

2.Inc Function running time, including sub-functions

3.Excl Function running time, excluding sub-functions

4.total calls Total calls

The above is the detailed content of tideways+toolkit performs performance analysis on php code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template