Analyze xdebug memory profiling for PHP

Step 1:      Install XDebug on Wamp

1. Download the latest release of xdebug for PHP version you are using.

2. Copy xdebug dll file into php’s extension directory, in my case, as I use wamp, it is C:\wamp\bin\php\php5.4.16\ext

3. Now we need to configure xdebug so that it get recognized by PHP, so open php.ini. For CLI it will be located at  C:\wamp\bin\php\php5.4.16\php.ini. and Apache it will be located at C:\wamp\bin\php\php5.4.16\php.ini. You need to modify both above files

4. Add following at the end of your php.ini file

[xdebug]

zend_extension = "D:/wamp/bin/php/php5.4.16/zend_ext/php_xdebug-2.2.3-5.4-vc9.dll"

xdebug.remote_enable = 1

xdebug.profiler_enable = 1

xdebug.profiler_enable_trigger = 1

xdebug.auto_trace=1

xdebug.trace_output_dir="D:\wamp\tmp"

xdebug.trace_output_name="cachegrind.out.%s.%t.html"

xdebug.collect_params=0

xdebug.trace_format=1

xdebug.show_mem_delta=1

xdebug.collect_assignments=1

Visit page: http://xdebug.org/docs/execution_trace to read more config xdebug output format.

5. Finally restart Apache service .

Step 2:   Analyze XDebug Memory Profiling

1. Download PHP scripts https://github.com/derickr/xdebug/raw/master/contrib/tracefile-analyser.php

2. Run script by command line

Before run script you must be add PHP path to “Environment variables” in your PC.

config variable PC

You can sort the output on a few different keys: time-own, memory-own, time-inclusive, memory-inclusive and calls. You can also configure how many elements it will show. As an example here is some output from a trace of one of the presentation system's PHP scripts:

php tracefile-analyser.php cachegrind.out.test.1393832078.html.xt memory-own 20

memory profiling comand line

3. Import data into MS Access

+ Change format XDebug output file to “.txt”;

+ Open XDebug output file by editor:

memory profiling access 1

+ Create new MS Access and Import data from Text file

memory profiling access 2

 

memory profiling access 3

Step 3:  Example code

Click here  to download example code.

CASE 1: Use array

Run three scenarios:

-          1 000 iterations

-          10 000 iterations

-          100 000 iterations

Result:

memory_profiling_use_array

CASE 2: Use persistent backend instead of arrays.

Run three scenarios:

-          1 000 iterations

-          10 000 iterations

-          100 000 iterations

Result:

memory_profiling_use_saving_database

http://xdebug.org/docs/all_settings

http://derickrethans.nl/xdebug-and-tracing-memory-usage.html

http://xdebug.org/docs/execution_trace

Comments
My Cart
loading