Xhprof is a PHP performance analysis and debugging tool developed and maintained by a Facebook engineer, which is more lightweight and resource-efficient than xdebug, and is highly recommended for everyone. The following article mainly introduces you to the PHP Performance analysis tool XHPROF installation and use of relevant information, the need for friends can refer to.
Objective
Xhprof, a PHP performance monitoring tool that is open source by Facebook, consumes little resources and can even be deployed in a production environment.
It can be used in conjunction with Graphviz, and can visually demonstrate the time-consuming execution of code in the form of pictures.
The following main talk about the installation and use of the process
1. Installation
(1) Download and decompress
wget Http://pecl.php.net/get/xhprof-0.9.4.tgztar ZXVF xhprof-0.9.4.tgz
(2) Compiling and running
CD Xhprof-0.9.4/extension/phpize//This statement compiles PHP extension tools, mainly based on system information to generate the corresponding configure files, generally stored in the/usr/local/php/bin/directory. Configure--with-php-config=/usr/local/php/bin/php-configmake && make Installmkdir/tmp/xhprof
(3) Edit php.ini:
[xhprof]extension = Xhprof.soxhprof.output_dir=/tmp/xhprof
Xhprof.output_dir is the save path for the profiling build log
(4) Install plug-in
Finally, the array is returned, which means the installation is ready. What are the specific values? Forget about it, because there is a configuration of the UI below. It will be intuitive!
Yum-y Install libjpeg freetype freetype-devel libjpeg-devel liberation-sans-fonts.noarch
Automatic installation
Yum-y Install Graphviz
(5) Inserting code
Find the code you want to analyze, add at the beginning of the code, start profiling, will count the memory usage xhprof_enable (xhprof_flags_memory);//Specific code//add $xhprof_data at the end of code = Xhprof_disable (); Stop Profiler, display raw xhprof data for the profiler runinclude_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils /xhprof_lib.php "); # Please note set site Include_path permissions include_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils/xhprof_runs.php"); $xhprof _ Runs = new \xhprofruns_default ();//Save the run under a namespace "Xhprof_foo".//**note**://by Default Save_run () would Automatically generate a unique//run ID for you. [You can override this behavior by passing//a run ID (optional arg) to the Save_run () method instead.] $xhprof _runs->save_run ($xhprof _data, "Xhprof_foo");
(6) View
Configure an accessible site for the xhprof-0.9.4/xhprof_html in (2) and use PHP's built-in server cleanly
CD Xhprof-0.9.4/xhprof_htmlphp-s 0.0.0.0:8990
Then access the ip+ port to report it.
2. Instructions for use
Function Name: Method name.
Calls: The number of times the method was called.
calls%: The percentage of the number of method invocations that are called in the total numbers of sibling methods.
Incl.wall Time (microsec): How long the method takes to execute, including the execution time of the child method. (Unit: microseconds)
iwall%: Percentage of time spent on method execution.
Excl. Wall time (microsec): How long the method itself takes to execute, excluding the execution time of the child method. (Unit: microseconds)
ewall%: The percentage of time that the method itself takes to execute.
Incl. CPU (MICROSECS): The CPU time spent by the method execution, including the execution time of the child method. (Unit: microseconds)
icpu%: Percentage of CPU time spent by method execution.
Excl. CPU (MICROSEC): The method itself executes the CPU time that is spent, excluding the execution time of the child method. (Unit: microseconds)
ecpu%: The percentage of CPU time spent by the method itself execution.
Incl.memuse (bytes): The memory used by the method to execute, including the memory occupied by the child method execution. (Unit: bytes)
Imemuse%: Percentage of memory consumed by method execution.
Excl.memuse (bytes): The method itself executes the occupied memory, excluding the memory occupied by the child method execution. (Unit: bytes)
Ememuse%: The percentage of memory consumed by the method itself.
Incl.peakmemuse (bytes): Incl.memuse Peak. (Unit: bytes)
Ipeakmemuse%:incl.memuse peak percentage.
Excl.peakmemuse (bytes): Excl.memuse Peak. Unit: (bytes)
Epeakmemuse%:excl.memuse peak percentage.
Attention:
1, before the official opening, be sure to verify that the normal data output will not be affected. Confirm that the output content is the same, then go online.
2, the max_time of each URL do not set too small.
3, Xhprof will affect the performance of online services, it is best to monitor only on a single machine, or modify the xhprof.php code, the request is randomly monitored.
Summarize
Articles you may be interested in:
PHP Package DB Class Connection Sqlite3 Database Method Example Explanation
PHP implementation of analog HTTP request method analysis explained
PHP implementation of socket push Technology example explained