Vala Xdebug Tools
This package has tools that are useful for parsing Xdebug trace data. If you are not sure how to collect Xdebug trace data, see the section 'Collecting Data with Xdebug' below.
Install the Vala environment. (On Mac OS X,
brew install vala gee)
valac --pkg gio-2.0 --pkg gee-1.0 src/*.vala -o trace_analyzer
The trace analyzer has a number of features. In its basic form, it simply prints performance data about time and memory usage in a trace file.
To get an idea as to how it works, try this:
trace_analzer -c some_file, you can generate CSV output. This explains the columns.
Columns of output:
- function: Name of the function called
- calls: Number of times the function was called
- time_inclusive: Aggregated time for calling this function and all children functions
- memory_inclusive: Aggregated memory for calling this function
- time_own: Aggregated time for calling this function, MINUS the aggregated time for calling its children
- memory_own: Aggregated memory for this function, MINUS the aggregated memory of children functions
- time_own_min: The fastest this function was executed
- time_own_max: The slowest this function executed
- time_own_avg: The average time it took to execute the function
- memory_own_min: The minimum amount of memory this required to run
- memory_own_max: The maximum amount of memory this required to run
- memory_own_avg: The average memory consumed by this function
Note that memory numbers are somewhat suspect because of PHP's garbage collection, which may deallocate memory between function entry and function exit, essentially creating a negative memory usage number.
Collecting Data with Xdebug
php.ini config for Xdebug:
xdebug.auto_trace = 1 xdebug.trace_format = 1 xdebug.trace_output_name = php-trace.%t
The second one is the most important: Set the tracing format to 1.
Developers: Build Your Own Trace Tools
Included in this tool is a straightforward library for building your own tracefile analyzers. In a nutshell, here's how you do it:
- Create a class that extends XdebugTools.TraceObserver
- Write a simple wrapper that creates a new XdebugTools.TraceParser()
- Register your observer (e.g.
- Parse the file (e.g.
Why was this tool written in Vala instead of PHP? There are two reasons:
1. Vala is compiled to a native executable, and is thus substantially faster than its PHP equivalent. This is important when trace files start to get huge. 2. I think Vala is a fantastic language, and thus have used it here.
Thanks to Derick Rethans, who posted a simple PHP tool for parsing Xdebug trace files.
This script was written and originally tested on Mac OS X using the homebrew package of Vala and Gee. It was written in TextMate using the Vala bundle. Subsequently, this has been tested on Debian GNU/Linux.
There is no reason why this shouldn't compile and execute on any system that supports Vala.