TAG | profiling
A while ago I was in need to profile one of our PHP applications. I needed to be able to see execution times, memory usage and some kind of a graphical interface to view it all. I remembered a PHP profiler debugger tool named Xdebug. Xdebug works as a PHP Zend extension. If you are a windows user installing it on your machine is very straightforward:
Download the appropriate windows module from xdebug.org. Edit your php.ini file by adding the following line to the extensions section:
Restart your web server and look for a module named Xdebug in your phpinfo() output. If you’re lucky enough you’ll find it there.
After that you need to configure xdebug extension.
;enables the profiler
;specifies profiler output files directory
;specifies profiler output file name pattern.
;enables auto tracing on every script startup
;specifies trace files output direcctory
;specifies trace output file name pattern.
;enable memory usage tracking
Restart your web server again. Run any of your php applications and you should find files in your specified directories:
Now you can view cachegrind files with WinCacheGrind. The application I tested was spawning few processes of it’s own and the profile information was in one file by default. But apparently something didn’t want to work so I separated each process to a separate file by adding %u to the output file name pattern.
The most interesting part for me was memory usage which you can find in the .xt files. It shows the total memory used after every line of code executed and a delta’s between executions. A tool for viewing/analyzing these trace files would be nice. Did not look for one though. All in all Xdebug is useful to find those nasty bottlenecks. It also has other nice features that help you to daily develop your apps. Nice thing I didn’t try yet is the “Code coverage” test. It might help me find some unused code in our applications.