1

I'm trying to profile a specific cron task in drupal 6 to check the function calls made and what consumes the maximum time and decided to use the XHProf module which I've never used before. I've got the module successfully installed and able to get the page loads profiled and listed in admin/reports/xhprof.

But to get my cron task to be profiled and listed in it I'm pretty clueless and tried out a few things from what I could gather from PHP.net but beyond coding

xhprof_enable();
echo "<h2>ENABLED</h2>";
// the code block I wish to profile
$xhprof_data = xhprof_disable();
echo "<pre>";
print_r($xhprof_data);
echo "</pre>";  

by checking the internet. The $xhprof_data does contain the necessary info array. But I'm not able to get the slightest hint of how this data that's printed could be formatted and displayed like the page loads which get profiled out of the box. Any help on this is greatly appreciated.

1

I haven't used the D6 version before but rummaging through the code I think something like this will work:

1st bit (taken from xhprof_shutdown_xhprof())

$namespace = variable_get('site_name', '');  // namespace for your application
$xhprof_data = xhprof_disable();

// Path to save file. Leave empty to use a default
$xhprof_data['path'] = isset($_GET['q'])?$_GET['q'] : ''; 
$class = variable_get('xhprof_default_class', 'XHProfRunsFile');
$xhprof_runs = new $class();
$run_id = $xhprof_runs->save_run($xhprof_data, $namespace);

2nd bit (taken from xhprof_display_page())

drupal_add_css(drupal_get_path('module', 'xhprof') . '/xhprof.css');
$html = xhprof_display_run(array($run_id), NULL);

// Do what you need to with $html to get it out to the screen
1
  • thanks for the quick response, i'll try this out and let you know how things turn out :) Dec 7 '12 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.