Knock knock who is calling

Knock knock

For Views: option_definition is called oh so many times I needed to find out what calls were made to my own method.

  function option_definition() {
    static $stack;
    if (!isset($stack)) $stack = array();

... 
normal code
...
    $trace = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT);
    $substack = &$stack;
    foreach ($trace as $caller) {
      $id = '';
      if (isset($caller['class'])) {
        $id = $caller['class'] . "::";
      }
      $id .= $caller['function'];
      if (!isset($substack[$id])) {
        $substack[$id] = array();
      }
      $substack = &$substack[$id];
    }
    dsm($stack, __CLASS__ . "::" . __METHOD__);
    return $options;

This shows a call stack like

... (Array, 1 element)

    views_plugin_style_graphapi::option_definition (Array, 3 elements)
        views_object::set_default_options (Array, 1 element)
            views_object::construct (Array, 1 element)
                _views_create_handler (Array, 1 element)
                    views_get_plugin (Array, 2 elements)
                        views_plugin_display::get_plugin (Array, 2 elements)
                            views_plugin_display::uses_fields (Array, 1 element)
                            views_plugin_display::validate (Array, 2 elements)
                                view::validate (Array, 1 element)
                                views_plugin_display_page::validate (Array, 1 element)
                        view::init_style (Array, 1 element)
        views_object::unpack_options (Array, 1 element)
            views_plugin_style::init (Array, 2 elements)
                views_plugin_display::get_plugin (Array, 2 elements)
                    views_plugin_display::uses_fields (Array, 1 element)
                        views_plugin_display::validate (Array, 2 elements)
                            view::validate (Array, 1 element)
                            views_plugin_display_page::validate (Array, 1 element)
                    views_plugin_display::validate (Array, 2 elements)
                        view::validate (Array, 1 element)
                        views_plugin_display_page::validate (Array, 1 element)
                view::init_style (Array, 1 element)
                    view::build (Array, 1 element)
        views_plugin_style_graphapi::theme_functions (Array, 1 element)
            views_plugin_style_graphapi::render (Array, 1 element)