Developer Area/Php profiling

From Mahara Wiki

< Developer Area
Revision as of 15:55, 24 July 2020 by Cecilia (talk | contribs) (Kcachegrind)

What is profiling

Profiling is a method that is used to detect performace issues. For this we use tools to record stack traces of the running program to later be analysed

The install and configuration instructions work on Ubuntu 18.04


The first thing we need to do is installed Xdebug php extension to get the data of Mahara's php scripts. This extension can also be used for debugging php code well, but I will only add the instructions fro profiling here.

install extension

sudo apt-get install php-xdebug

check the extension is there

php -m | grep xdebug

on php.ini you need to add the following lines

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
zend_extension = /usr/lib/php/20170718/
you should check where is the in your machine

Add the setting for xdebug profiling

Here you can choose if you want to trace all the php code that is run or only a few scripts by passing an argument to the selected ones. more information on this here

To trace all scripts

Set to 1 to turn it on for every request
xdebug.profiler_enable = 0

To trace only the scripts with the parameter

Let's use a GET/POST parameter to turn on the profiler
xdebug.profiler_enable_trigger = 0

The GET/POST value we will pass; empty for any value

xdebug.profiler_enable_trigger_value = ""

Set up the output file name and location

Output cachegrind files to /tmp so our system cleans them up later
xdebug.profiler_output_dir = "/tmp/profiling"
xdebug.profiler_output_name = "cachegrind.out.%p"

Don't forget to restart the server
sudo service apache2 restart

If you made it work, you'll get files named cachegrind.out.* in the directory /tmp/profiling. These will contain data that looks like this

1409 2 0
calls=1 0 0
1410 0 160

So we will need another application to display this information in human friendly way.


Kcachegrind is a tool to display the profiling data in a graphical way. All those numbers and codes that we captured with the xdebug profiling tool can be seen as function calls and graphs.

how to in install

sudo apt-get install kcachegrind

Open the profiling files

Once you have the kcachegrind install, you should be able to open one of the xdebug data generated files. Open the kcachegrind application and open