pounard/xtrace2fg

Converts XDebug TRACE files to https://github.com/brendangregg/FlameGraph compatible input

Installs: 17

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Type:project

2.0.0 2021-07-21 12:18 UTC

This package is auto-updated.

Last update: 2024-04-22 22:29:44 UTC


README

From a given Xdebug generated trace file, outputs text suitable for https://github.com/brendangregg/FlameGraph flamegraph generator.

This requires xdebug.trace_format setting to be set to 1.

Prerequisites

Usage

This will output a trace file using time relative cost for each function:

xtrace2fg TRACE_FILE | flamegraph.pl > OUTPUT.svg

And this will output a trace file using memory relative cost for each function:

xtrace2fg memory TRACE_FILE | flamegraph.pl --color=mem > OUTPUT.svg

Where:

  • FILE is the Xdebug TRACE file (generated using xdebug.trace_format=1)

  • OUTPUT.svg if the output filename

You can load the SVG output file into any recent browser to benefit from browsing capabilities in the flame graph.

Warning, memory support is experimental, and is NOT doing what you'd expect because it will revert all functions that actually free memory to 0. You will see functions that consume memory without freeing it, but it not necessarily mean it's a leak, since it could be garbage collected somewhere else.

Generated sample trace file

XDEBUG_MODE=trace XDEBUG_TRIGGER=1 php -d'xdebug.trace_format=1' -f samples/test.php
cp /tmp/trace.XXXXXX.xt samples/test.xt

./xtrace2fg samples/test.xt > samples/test.cost.output
cat samples/test.cost.output | ~/FlameGraph/flamegraph.pl > samples/test.cost.svg

./xtrace2fg memory samples/test.xt > samples/test.memory.output
cat samples/test.memory.output | ~/FlameGraph/flamegraph.pl --color=mem > samples/test.memory.svg