In addition to Xdebug’s great profiling and debugging features it also supports tracing memory usage. This helps to find functions which consume a lot of memory or to identify memory leaks. The following options enable tracing right away:
xdebug.auto_trace=1 xdebug.trace_format=1
Traces are written to /tmp by default. You may change this via the xdebug.trace_output_dir setting. With xdebug.trace_format=1 you tell Xdebug to write traces in an easy-to-parse tab separated format. The logged information includes the start and end times of function calls as well as the amount of used memory when entering and leaving the function. The last two numbers help to figure out which functions increase the memory usage a lot. Luckily you don’t have to interpret the traces yourself but use a script for that.
The script parses the trace files and aggregates the numbers by function name. It accepts a few different keys to sort the output: time-own, memory-own, time-inclusive, memory-inclusive and calls. You can also configure the number of elements to show:
php tracefile-analyser.php trace.662975268.xt memory-own 10
Showing the 10 most costly calls sorted by 'memory-own'.
Inclusive Own
function #calls time memory time memory
------------------------------------------------------------------------------------------
Icinga\Application\ClassLoader->loadClass 90 0.9151 2638176 0.0814 1262312
Zend_Loader::loadFile 17 0.1496 1183528 0.0345 882928
PDOStatement->execute 22 0.0102 395368 0.0102 395368
require 85 0.6066 1548112 0.0157 338512
require_once 22 0.0506 566296 0.0107 149128
Icinga\Application\ClassLoader->requireZendAutoloader 1 0.0045 154360 0.0023 120136
Composer\Autoload\includeFile 8 0.0148 86544 0.0028 59448
Zend_Db_Select->_join 41 0.2599 59368 0.0627 57072
explode 135 0.0341 55672 0.0341 55672
Icinga\Application\Benchmark::measure 94 0.2099 47448 0.0737 47352


























0 Kommentare