Developer Area/Php profiling: Difference between revisions
From Mahara Wiki
< Developer Area
(Created page with "== 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 analys...") |
(→Xdebug) |
||
Line 46: | Line 46: | ||
Don't forget to restart the server<br> | Don't forget to restart the server<br> | ||
''sudo service apache2 restart'' | ''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 | |||
fl=(158)<br> | |||
fn=(765)<br> | |||
1409 2 0<br> | |||
cfl=(1)<br> | |||
cfn=(564)<br> | |||
calls=1 0 0<br> | |||
1410 0 160<br> | |||
So we will need another application to display this information in human friendly way. | |||
== Kcachegrind == | == Kcachegrind == |
Revision as of 16:46, 10 July 2020
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
Xdebug
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/xdebug.so
you should check where is the xdebug.so 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 https://xdebug.org/docs/profiler
- 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
fl=(158)
fn=(765)
1409 2 0
cfl=(1)
cfn=(564)
calls=1 0 0
1410 0 160
So we will need another application to display this information in human friendly way.