What’s profiling?
Profiling – is a process of application performance analysis done for the purpose of acquiring data about efficiency (a set of characteristics like CPU times, RAM and resources processing, number of function calls and so on). Accordingly the instrument used for that is called a profiler.
Profilers in most cases are used to find hot-spots in the application (a hot-spot is a part in the code which processing time is inexcusably long) and also for analysis and evaluation of application quality.
PHP-code profiling
The most popular PHP-profilers are:
Xdebug's Profiler (http://www.xdebug.org/docs/profiler) and XHprof (http://pecl.php.net/package/xhprof). We’ll talk about the second one here.
About XHprof
XHprof is a hierarchical profiler for PHP with HTML interface. The core is written in C language (the code is ultimately PHP on the level of reports and interface), and for download it’s available as extension for PHP. This profiler knows how to collect data about memory usage, processor resources, number and order of calls of functions and also inclusive time (time spent for the function and all functions started by it) and exclusive time (time spent for the function with no regard to the time taken by the embedded function).
Additionally, XHprof supports ability to compare two runs (hierarchical DIFF report) and aggregate results from multiple runs for data averaging.
XHprof Install
XHprof (version 0.9.2, starting with PHP 5.2.0) is available as PECL-package since July 1, 2009. By the way, it’s not available for Windows.
Installation process is as follows:
pecl download xhprof-0.9.2 tar -xvf xhprof-0.9.2.tar.gz cd xhprof-0.9.2/extension phpize ./configure make make install
Then a module in php.ini must be enabled:
extension=xhprof.so xhprof.output_dir=/var/log/xhprof;