Приглашаем посетить
Спорт (www.sport-data.ru)

A Smorgasbord of Profilers

Previous
Table of Contents
Next

A Smorgasbord of Profilers

As with most features of PHP, a few choices are available for script profilers:

  • Userspace profilers An interesting yet fundamentally flawed category of profiler is the userspace profilers. This is a profiler written in PHP. These profilers are interesting because it is always neat to see utilities for working with PHP written in PHP itself. Unfortunately, userspace profilers are heavily flawed because they require code change (every function call to be profiled needs to be modified to hook the profiler calls), and because the profiler code is PHP, there is a heavy bias generated from the profiler running. I can't recommend userspace profilers for any operations except timing specific functions on a live application where you cannot install an extension-based profiler. Benchmark_Profiler is an example of a userspace profiler in PEAR, and is available at http://pear.php.net/package/Benchmark.

  • Advanced PHP Debugger (APD) APD was developed by Daniel Cowgill and me. APD is a PHP extension-based profiler that overrides the execution calls in the Zend Engine to provide high-accuracy timings. Naturally, I am a little biased in its favor, but I think that APD provides the most robust and configurable profiling capabilities of any of the candidates. It creates trace files that are machine readable so they can be postprocessed in a number of different ways. It also provides user-level hooks for output formatting so that you can send profiling results to the browser, to XML, or using any format you wanted. It also provides a stepping, interactive debugger, which us not covered here. APD is available from PEAR's PECL repository at http://pecl.php.net/apd.

  • DBG DBG is a Zend extension-based debugger and profiler that is available both in a free version and as a commercial product bundled with the commercial PHPEd code editor. DBG has good debugger support but lacks the robust profiling support of APD. DBG is available at http://dd.cron.ru/dbg.

  • Xdebug Xdebug is a Zend extension-based profiler debugger written by Derick Rethans. Xdebug is currently the best debugger of the three extension-based solutions, featuring multiple debugger interfaces and a robust feature set. Its profiling capabilities are still behind APD's, however, especially in the ability to reprocess an existing trace in multiple ways. Xdebug is available from http://xdebug.org.

The rest of this chapter focuses on using APD to profile scripts. If you are attached to another profiler (and by all means, you should always try out all the options), you should be able to apply these lessons to any of the other profilers. The strategies covered here are independent of any particular profiler; only the output examples differ from one profiler to another.


Previous
Table of Contents
Next