Home  >  Article  >  Backend Development  >  About PHP+xdebug analysis of code performance bottlenecks

About PHP+xdebug analysis of code performance bottlenecks

藏色散人
藏色散人forward
2021-02-18 17:27:212906browse

PHP xdebug analysis code performance bottleneck

Usually enabledxdebug Plug-in, performance test output file will be generated, usually in the cachegrind.out.xxxx file.

This file can be used for code performance analysis through third-party tools.

But if there are multiple projects/websites locally, all profiles will be output to one file, which is not convenient for subsequent performance analysis.

Custom profile file name

You can set the output file name by configuring the xdebug.profiler_output_name parameter. Some parameters are as follows:

##%R#$_SERVER ['REQUEST_URI']cachegrind.out.%Rcachegrind.out._test_xdebug_test_php_var=1_var2%S session_id (from $_COOKIE if set)cachegrind.out.%Scachegrind.out.c70c1ec2375af58f74b390bbdd2a679d%%%characterscachegrind.out.%%cachegrind.out.%%##edit
Symbol Meaning Configuration sample Sample file name
%c Crc32 check value of the current working directory cachegrind.out.%c cachegrind.out.1258863198
% p Pid of the current server process cachegrind.out.%p cachegrind.out.9685
%r Random number cachegrind.out.%r cachegrind.out.072db0
%s Script file name (note) cachegrind.out.%s cachegrind.out._home_httpd_html_test_xdebug_test_php
%t Unix Timestamp (seconds) cachegrind.out.%t cachegrind.out.1179434742
%u Unix time Stamp (microseconds) cachegrind.out.%u cachegrind.out.1179434749_642382
%H $_SERVER ['HTTP_HOST'] cachegrind.out.%H cachegrind.out.localhost
php. ini

Configuration file: <pre class="brush:php;toolbar:false">xdebug.profiler_output_name = cachegrind.out.%H</pre> Then restart the php server.

Under Mac, the profile file is stored in the

/var/tmp/

directory. Performance Analysis

Under Mac, MacCallGrind and qcachegrind can be used, but the former is charged and can be downloaded directly through the Apple Store, while the latter is free. Requires manual installation.

Install graphviz for Call Graph function:

$ brew install graphviz

Install qcachegrind:

$ brew install qcachegrind

After the installation is completed, you can open the

qcachegrind

application, graph The interface is as follows:

About PHP+xdebug analysis of code performance bottlenecksOthers

However, it should be noted that after turning on the

profile

file output, if there are many local projects, it is easy to It occupies a large area of ​​disk space. The picture below shows the status that I haven’t cleaned up in about half a year:

About PHP+xdebug analysis of code performance bottlenecksYou can use the command to clean up:

$ sudo rm -fr /private/var/tmp/cachegrind.out.*

The above is the detailed content of About PHP+xdebug analysis of code performance bottlenecks. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete