bobbingwide / oik-bwtrace

debug trace for WordPress
https://www.oik-plugins.com/oik-plugins/oik-bwtrace-debug-trace-for-wordpress/
GNU General Public License v2.0
6 stars 1 forks source link

Add attached functions count to [hook] shortcode #35

Closed bobbingwide closed 4 years ago

bobbingwide commented 8 years ago

The [hook] links shortcodes generated by oik-bwtrace action count logic, shows how many times a hook is invoked. If we're trying to improve performance we need some idea how many functions are registered against each hook.

Proposed solution

Alter bw_trace_get_hook_links() to invoke a new function called bw_trace_get_attached_hook_count(), which will provide a simple count of the attached hooks. Note: This will show the hooks attached at shutdown. It's probably good enough for the time being.

bobbingwide commented 8 years ago

In the first iteration I simply added the count. Then I decided to add a parameter so you could decide if the hook shortcode is generated when there are no implementers of the hook. Note: There are some times when you need to know about ALL hooks and other times when you need to know about the most used and their implementing functions.

I then changed some of the calls ( "most used" and "by hook name" ) which were using bw_trace() to bw_trace_create_hook_links(). "Most used" only logs the output when there are implementing functions.

bobbingwide commented 4 years ago

The format of the hook shortcode is documented at https://www.oik-plugins.com/wordpress-plugins-from-oik-plugins/free-oik-plugins/oik-trace-plugin/settings-oik-action-options/action-options-options/count-action-hooks-and-filters/

Example:

[hook option_siteurl filter 2 111 1]

Comments

Note: It's possible that some filter functions don't cater for all the parameters passed to it. In this example the attached function was _config_wp_siteurl().

This only expects one parameter. But two are passed by get_option().

wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(344:0) bw_trace_parms(1) 5 0 2019-12-11T15:07:07+00:00 0.012678 0.005378 cf=option_siteurl 48 4 0 2097152/2097152 256M F=193 parameters: 2: Array ( [0] => https://s.b/wordpress [1] => siteurl )

wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(525:0) bw_trace_attached_hooks(1) 6 0 2019-12-11T15:07:07+00:00 0.012890 0.000212 cf=option_siteurl 48 4 0 2097152/2097152 256M F=193 option_siteurl : 0 bw_trace_parms;9 bw_trace_attached_hooks;9 bw_trace_backtrace;9 : 10 _config_wp_siteurl;1 wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(609:0) bw_trace_backtrace(1) 7 0 2019-12-11T15:07:07+00:00 0.013051 0.000161 cf=option_siteurl 48 4 0 2097152/2097152 256M F=193 2 Array ( [0] => https://s.b/wordpress [1] => siteurl )

  1. bw_lazy_backtrace wp-content/plugins/oik-bwtrace/libs/bwtrace.php:108 0
  2. bw_backtrace wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php:610 0
  3. bw_trace_backtrace(https://s.b/wordpress,siteurl) wp-includes/class-wp-hook.php:288 2
  4. apply_filters(https://s.b/wordpress,array) wp-includes/plugin.php:206 2
  5. apply_filters(option_siteurl,https://s.b/wordpress,siteurl) wp-includes/option.php:152 3
  6. get_option(siteurl,) wp-includes/option.php:1286 2
  7. get_network_option(1,siteurl,) wp-includes/option.php:1151 3
  8. get_site_option(siteurl) wp-includes/default-constants.php:226 1
  9. wp_cookie_constants wp-settings.php:334 0
  10. require_once(C:\apache\htdocs\wordpress\wp-settings.php) wp-config.php:95 1
  11. require_once(C:\apache\htdocs\wordpress\wp-config.php) wp-load.php:37 1
  12. require_once(C:\apache\htdocs\wordpress\wp-load.php) wp-blog-header.php:13 1
  13. require(C:\apache\htdocs\wordpress\wp-blog-header.php) index.php:17 1
bobbingwide commented 4 years ago

I'm not going to add the above Comments to the documentation just yet. It could be a FAQ asking "Why doesn't the Number of args passed match the number of parameters expected?"