PHP performance monitoring extension xhprof performance analysis tool

WBOY
Release: 2016-07-25 09:13:19
Original
1330 people have browsed it

The PHP performance monitoring extension xhprof is generally a good tool. This section introduces the installation and usage process under Ubuntu.

Install xhprof:

  1. wget http://pecl.php.net/get/xhprof-0.9.2.tgz
  2. tar zxf xhprof-0.9.2.tgz
  3. cd xhprof-0.9.2/extension/
  4. sudo phpize
  5. ./configure --with-php-config=/usr/local/php/bin/php-config
  6. sudo make
  7. sudo make install
Copy the code

In order to view the debugging results graphically, you must also To install the tool graphviz, you can directly use apt-get to install it under ubuntu. The command is: sudo apt-get install graphviz. If it is another system, you may have to use some twists and turns. The command is as follows:

  1. wget http://www.graphviz.org/pub/graphviz/stable/sources/graphviz-2.24.0.tar.gz
  2. tar zxf graphviz-2.24.0.tar.gz
  3. cd graphviz- 2.24.0
  4. ./configure
  5. make && make install
Copy the code

Next configure php.ini

Add in php.ini:

  1. [xhprof]
  2. extension=xhprof.so;
  3. ; directory used by default implementation of the ixhprofruns
  4. ; interface (namely, the xhprofruns_default class) for storing
  5. ; xhprof runs.
  6. ;
  7. ;xhprof.output_dir =
  8. xhprof.output_dir=/tmp/xhprof
Copy code

Note: If it is a 64-bit system, you need to copy the xhprof.so file to the relevant lib directory (lib64)

After modification, restart apache and look at phpinfo. There should be information about xhprof.

Add the code to the php to be tested

  1. // cpu:xhprof_flags_cpu Memory: xhprof_flags_memory
  2. // If both together: xhprof_flags_cpu + xhprof_flags_memory
  3. xhprof_enable(xhprof_flags_cpu + xhprof_ flags_memory);
  4. //PHP code to be tested
  5. $data + /utils/xhprof_runs.php";
  6. $objxhprofrun = new xhprofruns_default();
  7. // The first parameter j is the running information returned by the xhprof_disable() function
  8. // The second parameter is the custom namespace character String (any string),
  9. //Return the running id, use this id to view the relevant running results
  10. $run_id = $objxhprofrun->save_run($data, "xhprof");
  11. var_dump($run_id);
  12. Copy the code
View the running results: Copy the xhprof_lib&&xhprof_html related directories to an accessible address Visit xxx/xhprof_html/index.php?run=$run_id to see the running status of your php code. $run_id is the content output in the above page. Remember to include the two files under xhprof_lib. If you don't want to use this method, you can also directly output the relevant printing information, that is, directly print_r out the value of $data above.

Parameter description:

Inclusive time includes all execution time of sub-functions. exclusive time/self time The time it takes for the function to execute itself, excluding subtree execution time. wall time elapsed time or wall clock time. cpu time user time + kernel time inclusive cpu includes the cpu occupied by sub-functions together exclusive cpu The cpu occupied by the function itself

source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!