Drupal development Tools and better ways of debugging.

Configure xhprof drupal

Drupal xhprof module was a bit frustration for me and its not give you accurate result. Having said that, could lead to wrong decision and disastrous re factoring and implementation.

e..g it records multple runs per page load sometime. And i couldnt find the reason for that. So its relevant easy to setup xhprof by yourself and enjoy the dubugging. Step needs to be taken are:

  • cp -r /path/to/your/xhprof  path/to/your/drupal/root/installation      you can download it here xhprof
  • vi /path/to/your/drupal/installation/index.php

And replace the content of index.php with the following.  Make sure you change base url to your one.

<?php
xhprof_enable();

define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();

$xhprof_data = xhprof_disable();

$XHPROF_ROOT = "xhprof";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

$xhprof_url = "http://drupal_base_url/xhprof/index.php?run={$run_id}&source=xhprof_testing";
echo '<a style="z-index:1000; padding:5px 10px; position:fixed; bottom:0; right:50px; background:black; color:white;" href="' . $xhprof_url . '" target="_blank">';
echo $xhprof_url . " - uri " .  request_uri();
echo '</a>';

Go to the page you want to debug. and then visit http://your_drupal_base_url/xhporf . you will see all the xhprof listed there sorted by latest on the top. Click on one profile and you  will see result as shown in picture below.
XHProf Hierarchical Profiler Report

Now you can drill down on individual functions and callback. Happy Debugging 🙂
If you want to hear on specific topic, send in comment and i will try write something.

—————————————————————————————

Identifying your template variable

print print_r(array_keys(get_defined_vars()), 1);
and if you have devel enable, then:
dsm(array_keys(get_defined_vars()));

more stuff will come every week…