Detailed explanation of installation and use of PHP performance test tool xhprof

  • 2021-09-20 19:48:21
  • OfStack

In this paper, an example is given to analyze the installation and use of PHP performance test tool xhprof. Share it for your reference, as follows:

Overview of xhprof:

XHProf is a layered PHP performance analysis tool. It reports function-level requests and various metrics, including blocking times, CPU times, and memory usage. 1 function overhead, can be subdivided into caller and callee overhead, XHProf data collection phase, it records the number of calls tracked and inclusive index arc in the dynamic callgraph 1 program. It is unique to the reporting/post-processing stage of data calculation. During data collection, XHProfd handles recursive function calls by detecting loops, and avoids dead loops by giving a useful name to each deep call in recursive calls. The XHProf analysis report helps to understand the structure of the code being executed. It has a simple HTML user interface (written by PHP). Browser-based performance analysis user interface makes it easier to view or share results with peers. You can also draw call diagrams.

Installation and use:

Recently, I want to compare the performance of the website, so I look for a performance test to play with. There are many tools, but compared with before, I still feel that the installation and use of xhprof are relatively simple, and the data analysis is OK. Let's talk about its installation and use. . .

Download xhprof and graphviz

If xhprof, you can download it directly to php official website. For convenience, you can poke 1 here

graphviz also want to download, mainly show xhprof performance results of the graphical report, stamp here here

Compile and install xhprof


cd xhprof-0.9.4/xhprof-0.9.4/extension/
phpize
./configure
make
sudo make install

Add the generated xhprof. so file to the php. ini file and restart apache


...
# If you want to use relative path loading here, you should first look at 1 Under extension_dir Configured path, or write directly to the `.so` The absolute ability path of the file can be used. . . 
extension=xhprof.so
...
sudo apachectl restart
## Test whether the extension was installed successfully, with the following output ok
php --ri xhprof
...
 xhprof
 xhprof => 0.9.2
 CPU num => 4
...

Installing graphviz


cd graphviz-2.38.0/
# The following parameter is to ensure that it is installed libphp It's okay. "It's not installed  brew install linpng  You can " 
./configure --with-png=yes
make
sudo make install

Test 1 is under

In the previously downloaded xhprof folder, find xhprof_html, xhprof_lib and sample, then put these three folders where you can access them, and then visit the following http://xxxx/sample/sample.php by connecting. After visiting the following http://xxxx/xhprof_html/, you will see a record. After clicking, you can see the analysis result page. Click View ES70CallGraph to link to the graphic report page.

How to use

Suppose you want to look at the performance data of the home page of a website you made now, then you need to find the home page entry file of this website, and add the performance test code of xhprof before and after loading the core file respectively


# Open, you can view the official document for specific parameter description 
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
# Implementation of core documents 
...
require 'index.php'
...
# Shut down 
$xhprof_data = xhprof_disable();
# The path here is configured according to your own site 
$XHPROF_ROOT = realpath(dirname(__FILE__) .'/');
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof");
# Print out the id ", easy to go to the report list page" http://xxxx/xhprof_html/ "To go through the corresponding id Find the corresponding result 
var_dump($run_id);

For more readers interested in PHP related content, please check the topics of this site: "PHP Extended Development Tutorial", "php Cache Technology Summary", "PHP Network Programming Skills Summary", "php Object-Oriented Programming Introduction Tutorial", "PHP Basic Syntax Introduction Tutorial", "PHP Array (Array) Operation Skills Complete Book" and "php String (string) Usage Summary"

I hope this article is helpful to everyone's PHP programming.


Related articles: