|
| F5 | Continue | Runs until the next breakpoint or until the code exits, whichever comes first |
| F8 | Step over | Steps through the code one line at a time, but doesn’t enter any functions it encounters |
| F7 | Step into | Like step over, but steps into any functions it encounters |
| CTRL+F7 | Step out | Steps out of a function which has previously been stepped into |
| F4 | Run to cursor | Runs until the current line of execution is on the same line as a cursor (this is useful to skip past big blocks of uninteresting code) |
In addition to doing step through debugging, you can also use Xdebug to profile your code. Profiling your code lets you see which functions use most of the execution time, making it easy to spot candidates for optimization.
Before you can use Xdebug to profile your code, you have to modify the configuration slightly. Open a terminal window and run the following command to open the xdebug.ini file in a text editor:
sudo gedit /etc/php5/conf.d/xdebug.ini
Add the following line to the end of the file:
xdebug.profiler_enable_trigger=1
This lets you trigger the xdebug profiler from the browser.
When you have saved the file you must run the following command to restart Apache:
sudo /etc/init.d/apache2 restart
In order to analyze the output files generated by the profiler, you must install Webgrind.
Start by downloading the latest version of Webgrind. Open the file with the Archive Manager and extract the webgrind folder to the Drupal folder in your home directory.
Next, we’ll add a hostname for the local webgrind installation. Open a terminal window and run the following command to open the hosts file in a text editor:
sudo gedit /etc/hosts
Add an entry for webgrind and point it at the local web server on 127.0.0.1.
Finally, we have to create a new Apache virtual host to handle requests to http://webgrind/. Open a terminal window and run the following commands to create a new virtual host definition:
cd /etc/apache2/sites-availablesudo gedit drupal614
It is a good idea to use the hostname as the name of the virtual host file. This makes it easier to manage a lot of virtual hosts.
Enter the following virtual host definition and save the file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName drupal614
DocumentRoot /home/<username>/Drupal/drupal-6.14
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
The ServerName must match the hostname you added to the hosts file, and the DocumentRoot must match the name of the folder where webgrind is installed. Replace
When you have saved the file, you can run the following commands in a terminal window to enable the new virtual host and reload the Apache configuration:
sudo a2ensite webgrindsudo /etc/init.d/apache2 reload
You can now access Webgrind at http://webgrind/.
To start the profiler, simply add ?XDEBUG_PROFILE to any URL on your local Drupal site. The page will load normally, but Xdebug will create a cachegrind.out file in the /tmp folder.
When the cachegrind file has been written you can go to http://webgrind/ to start analyzing it. In the Webgrind window, you can either just press Update to analyze the latest cachegrind file or select a specific file from the dropdown.
TODO: Description of the Webgrind interface.
Published with Backpack. This page is subject to the terms of service.
This guide walks you through setting up a Drupal development environment using Ubuntu and NetBeans. This setup will allow you to do step through debugging and profiling of your Drupal sites.