3

I need to examine all the function calls Drupal makes during it loads a page (even if there are no errors). I guess debugging software can do this but I would also like to know a way to do this without xdebug etc.

I found this link: https://drupal.stackexchange.com/questions/545/how-to-debug-drupal but I'm not sure where to put for example this code:

<?php
$bt = debug_backtrace();
foreach ($bt as $key => $value) {
  if ($key == 0) {
    continue;
  }
  unset($bt[$key]['args']);
  unset($bt[$key]['object']);
}
drupal_set_message(str_replace('    ', '&nbsp;&nbsp;&nbsp;&nbsp;', nl2br(htmlentities(print_r($bt, TRUE)))));
?>
4

I would recommend using Xdebug as opposed to any other methods.

Xdebug can easily be installed and then all you have to do is enable profiling and navigate around your site.

Not only does it list all function calls but it counts how many times each is called during a request and also times the function call, so you know exactly where to look to resolve bottlenecks.

The results can be viewed using Webgrind (browser-based) or KCacheGrind (KDE/linux), amongst others.

This is more efficient because you are not tampering with the code and littering it with debug statements.

|improve this answer|||||
1

The number of function calls during a single page view can be quite a lot. I don't know the number, but my guess is that it's several thousand. If you want to log all of this data, you shouldn't post it to the screen, but instead write it in a file, like the dd function that the devel module has.

If you want to log all function calls, you should start by the end, that last function that is called in a drupal page. One of the last functions where you could start is drupal_page_footer. You can add the debug_backtrace in that function.

Then you would have to go through all the functions and add debug_backtrace for all the functions that those functions call. Then you would have to go through all the new functions listed in the debug_backtrace you just added and repeat the above step until you or your computer chokes.

It's possible to do this, but to get anything useful you will need a profile tool, which can do all of this in seconds instead of hours. This is where computers excels: recursion.

|improve this answer|||||
0

If you need to print all the function calls (e.g. just their names separated by comma), try:

print implode(', ', array_column(debug_backtrace(), 'function'));

Note: array_column() is part of PHP >=5.5.0

|improve this answer|||||

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.