3

Is there a module that can essentially show you the function stack trace of the last request made?

Say I have a form that I submit. After the page loads with the result from the request, I would like to see a list of all the functions that were called, start to finish, that resulted in the currently loaded page.

3

A function trace will only show you the function calls that lead directly to that piece of code.

PHP provides the functions debug_print_backtrace() for that, which is however not very readable but it will result a huge amount of text. devel.module provides a ddebug_backtrace()function, which us much easier to read.

To see all function calls of a single page, you need to install a profiler like XhProf.

2

XDebug

You can use PHP XDebug extension with the following options:

  • start/stop by xdebug_start_trace()/xdebug_stop_trace() at the specific places (e.g. before form submit),
  • set xdebug.auto_trace=1 in php.ini for full trace,
  • use xdebug_print_function_stack() to display your current function stack,
  • use xdebug.remote_enable=1 in php.ini to use debugger directly from IDE for step-by-step debugging.

Check: XDebug Docs.

See my suggested xdebug.ini config file for PHP.

DTrace

If your system supports DTrace (e.g. OS X) and your PHP has been configured with DTrace static probes (php -i | grep dtrace), the following command will trace all your function calls:

sudo dtrace -qn 'php*:::function-entry { printf("%Y: PHP function-entry:\t%s%s%s() in %s:%d\n", walltimestamp, copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2); }'

This should work in Apache, if not, you may re-run your CMS by using builtin PHP server, e.g.:

php -S localhost:8080

then access your site at http://localhost:8080/, so when you submit the form - you should see trace output containing all functions that were called as result of loaded page.

For more scripts, check my dtruss-lamp repository.

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.