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! :)

You might also want to look at these posts

  • why vTiger sucks
  • so clean and so fresh…
  • 4Gamers.be Launched
  • mysqli for WordPress 2.9.1
  • WordPress mysqli 2.9 Database Class Patch
  • 

    7 Responses (Add Your Comment)

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

      thanks for your efforst

    2. doum-ti-di-li-doom August 4, 2010
      at 3:42 pm

      1) set_time_limit(0);
      2) error_reporting(0);
      3) Where are the images ?

    3. Can you upload (or at least permit me to upload) the package on Github or something so that we can work on it ?

    4. Hi, i forked your code and modified it to support trace_format = 0:

      https://github.com/beberlei/xdebug-trace-gui

    5. Simon Michael May 25, 2011
      at 7:45 pm

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

    6. Lots of thanks Thomas, great work!

      I forked the beberlei github to fix the broken images with Unicode symbol and show require files and parameters pass to function/method.

      I can’t view in my trace the return values… in working to resolve this issue.

      https://github.com/corretge/xdebug-trace-gui

    7. Respect to the post author. This is truly some crucial information.

    Leave a Reply

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

    Archives

    Twitter!