xdebug trace file parser

xdebug_trace_preview

When I am trying to optimize my PHP code, one of my prefered tools is xdebug. It provides me with excellent error messages, outputs code tracing files & insight into memory usage.

By using kcachegrind or webgrind – wincachegrind crashes *all* the time – to parse the cachegrind files created by xdebug, you get a good idea of what your code is doing most of the time. It’ll show you which functions are called, by who, which arguments are passed and tons more. Check it out.

Now, there was one small thing I couldn’t find anywhere. A program to parse the trace files that xdebug generates. True, xdebug already provides the option to output this information into HTML, but it’s not really what I was looking for. I want to get quick information in the blink of an eye! That’s why I have created my own trace file parser, based on PHP of course.

What is it?

This xdebug trace parser will show you, for each function:

  • How much memory was used on entry & exit
  • How much time it costed to execute the function
  • The exact line the function was called from plus insight into the code by clicking a link
  • Whether the function is native PHP or not

xdebug_trace_warning

It also has a basic “alerting” feature, which will allow you to set triggers on memory usage & execution time. You can specifiy that if the memory or time jump is greater than a certain value, to show this in the output.

Requirements

It should be obvious that you’ll need to install and configure xdebug for your PHP installation. See http://www.xdebug.org for more information on this.

Your xdebug config should look a bit like this, don’t forget to update your paths ;)

[XDebug]
;; Only Zend OR (!) XDebug
zend_extension_ts="\php\ext\php_xdebug-2.0.4-5.2.8.dll"
xdebug.auto_trace=1
xdebug.trace_format=1
xdebug.profiler_append=1
xdebug.profiler_enable=1
xdebug.profiler_enable_trigger=0
xdebug.collect_params=4
xdebug.collect_return=1
xdebug.trace_output_dir="D:\webserver\xdebug"
xdebug.trace_output_name= %t.trace
xdebug.profiler_output_name = %s.%t.profile
xdebug.profiler_output_dir="D:\webserver\xdebug"

Download

Now, give it a try and downlod the xdebug trace file parser here!

Usage

Once you’ve downloaded the trace file parser, extract it to a directory inside your website root and surf to the URL. If everything works out you should be able to select trace files onceyou have ran an other PHP script on your server. This trace file parser will *not* show it’s own traces because that would make things even more complicated!

Comments & suggestions! :)

12 thoughts on “xdebug trace file parser

  1. NetWorker

    cool script, it’s helpful specially the configurable alerting feature.

    thanks for your efforst

  2. Simon Michael

    Hi, yes thanks for this and could you share the images so they can be added to the github version ?

  3. Pingback: xdebug «

  4. Pingback: 一个奔向攻城狮的程序猿

  5. Pingback: » 【转】PHP调试利器XDebug的安装与使用

  6. Pingback: PHP调试利器XDebug的安装与使用 – 老高的自留地

  7. Pingback: PHP调试利器XDebug的安装与使用 « 神经质的盛宴

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>