Changeset 432272
- Timestamp:
- 09/02/2011 01:06:13 PM (14 years ago)
- Location:
- debug-bar-extender/trunk
- Files:
-
- 3 edited
-
debug-bar-extender.php (modified) (16 diffs)
-
readme.txt (modified) (2 diffs)
-
screenshot-1.jpg (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
debug-bar-extender/trunk/debug-bar-extender.php
r425345 r432272 5 5 Description: A minimalistic profiler / debugging class that hooks into the debug bar and can be implemented easily 6 6 Author: Thorsten Ott, Automattic 7 Version: 0. 38 Author URI: http://hitchhacker .com7 Version: 0.5 8 Author URI: http://hitchhackerguide.com 9 9 */ 10 10 … … 18 18 * <?php if (have_posts()) : ?> 19 19 * 20 * <?php Debug_Bar_Extender::instance()->start('loop start'); ?>20 * <?php dbgx_checkpoint('loop start'); ?> 21 21 * 22 22 * <?php while (have_posts()) : the_post(); ?> 23 23 * 24 * <?php Debug_Bar_Extender::instance()->trace_var( $post ); ?>25 * <?php Debug_Bar_Extender::instance()->checkpoint('loop1'); ?>24 * <?php dbgx_trace_var( $post ); ?> 25 * <?php dbgx_checkpoint('loop1'); ?> 26 26 * 27 27 * <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> … … 36 36 * </div> 37 37 * 38 * <?php Debug_Bar_Extender::instance()->checkpoint('loop2'); ?>38 * <?php dbgx_checkpoint('loop2'); ?> 39 39 * 40 40 * <?php endwhile; ?> 41 41 * 42 * <?php Debug_Bar_Extender::instance()->end('loop end'); ?>42 * <?php dbgx_checkpoint('loop end'); ?> 43 43 * 44 44 * <div class="navigation"> … … 48 48 * <?php else : ?> 49 49 * ... 50 *51 * You can have as many Debug_Bar_Extender::instance()->checkpoint() calls as you want but must have only 1 Debug_Bar_Extender::instance()->start() and Debug_Bar_Extender::instance()->end() call52 50 * 53 51 */ … … 84 82 'savequeries_debugmode_enable' => 1, 85 83 'use_error_log' => 0, 84 'allow_url_settings' => 0, 85 'enable_admin_bar_menu' => 0, 86 86 ) ); 87 87 88 88 $this->settings_texts = (array) apply_filters( 'debugbarextender_settings_texts', array( 89 'enable_profiler' => array( 'label' => 'Enable profiler', 'desc' => 'You can measure runtimes between checkpoints via <code>Debug_Bar_Extender::instance()->start( $note="" )</code>, <code>Debug_Bar_Extender::instance()->checkpoint( $note="" )</code>, <code>Debug_Bar_Extender::instance()->end( $note="" )</code> .' ),90 'enable_variable_lookup' => array( 'label' => 'Enable variable lookup', 'desc' => 'You can screen variables via <code>Debug_Bar_Extender::instance()->trace_var( $value, $var_name = false )</code> . Omitting the <code>$var_name</code> will let the script look it up. Please be aware that sizes are approximate based on <code>strlen(serialize())</code>' ),89 'enable_profiler' => array( 'label' => 'Enable profiler', 'desc' => 'You can measure runtimes between checkpoints via <code>Debug_Bar_Extender::instance()->start( $note="" )</code>, <code>Debug_Bar_Extender::instance()->checkpoint( $note="" )</code>, <code>Debug_Bar_Extender::instance()->end( $note="" )</code> or by using the wrapper function <code>dbgx_checkpoint( $note="" )</code>.' ), 90 'enable_variable_lookup' => array( 'label' => 'Enable variable lookup', 'desc' => 'You can screen variables via <code>Debug_Bar_Extender::instance()->trace_var( $value, $var_name = false )</code> or via <code>dbgx_trace_var( $value, $var_name = false )</code>. Omitting the <code>$var_name</code> will let the script look it up. Please be aware that sizes are approximate based on <code>strlen(serialize())</code>' ), 91 91 'track_default_vars' => array( 'label' => 'Track default variables', 'desc' => 'Track various useful variables useful for the regular debugging.' ), 92 92 'add_default_checkpoints' => array( 'label' => 'Add default checkpoints', 'desc' => 'Enabling this option will add various default checkpoints to be used with the profiler.' ), 93 93 'savequeries_debugmode_enable' => array( 'label' => 'Try setting debug mode', 'desc' => 'Try setting <code>WP_DEBUG</code> and <code>SAVEQUERIES</code> variables to enable additional debug menus. This should be generally done via <code>wp-config.php</code>, but this setting is worth a shot.' ), 94 94 'use_error_log' => array( 'label' => 'Use <code>error_log()</code> reporting', 'desc' => 'Log the results using <code>error_log()</code> as well. This helps when debugging sessions which are not producing any admin bar output.' ), 95 'allow_url_settings' => array( 'label' => 'Allow setting alteration via query parameters', 'desc' => 'Allow <code>dbgx_use_error_log</code>, <code>dbgx_track_default_vars</code>, <code>dbgx_add_default_checkpoints</code> to be added as query strings in order to enable respective features. Combinations are possible - for example: ' . add_query_arg( array( 'dbgx_use_error_log' => 1, 'dbgx_add_default_checkpoints' => 1, 'dbgx_track_default_vars' => 1 ) ) ), 96 'enable_admin_bar_menu' => array( 'label' => 'Enable admin bar menu', 'desc' => 'Adds a menu to your admin bar to allow access to the url query parameters to control debug bar behaviour, only useful with allow_url_settings enabled' ), 95 97 ) ); 96 98 … … 110 112 } 111 113 112 if ( 1 == Debug_Bar_Extender::instance()->settings['use_error_log'] ) {114 if ( 1 == Debug_Bar_Extender::instance()->settings['use_error_log'] || ( 1 == Debug_Bar_Extender::instance()->settings['allow_url_settings'] && isset( $_GET['dbgx_use_error_log'] ) && 1 == $_GET['dbgx_use_error_log'] ) ) { 113 115 Debug_Bar_Extender::instance()->use_error_log = true; 114 116 } … … 116 118 if ( Debug_Bar_Extender::instance()->use_error_log ) 117 119 error_log( 'Starting debug session for ' . $_SERVER['REQUEST_URI'] ); 118 120 119 121 Debug_Bar_Extender::instance()->prepare_debug_menu(); 120 122 } … … 146 148 147 149 150 add_action( 'admin_bar_menu', array( &$this, 'debug_action_admin_bar_menu' ), 101 ); 148 151 add_action( 'init', array( &$this, 'add_design_parts' ) ); 149 152 150 if ( 1 == $this->settings['track_default_vars'] ) {153 if ( 1 == $this->settings['track_default_vars'] || ( 1 == Debug_Bar_Extender::instance()->settings['allow_url_settings'] && isset( $_GET['dbgx_track_default_vars'] ) && 1 == $_GET['dbgx_track_default_vars'] ) ) { 151 154 add_action( 'parse_request', array( &$this, 'trace_var_request' ), 1000 ); 152 155 add_action( 'after_setup_theme', array( &$this, 'trace_var_template' ), 1000 ); 153 156 add_action( 'posts_request', array( &$this, 'trace_var_posts_request' ), 1000 ); 154 add_action( 'posts_results', array( &$this, 'trace_var_found_post_ids' ), 1000 );157 //add_action( 'posts_results', array( &$this, 'trace_var_found_post_ids' ), 1000 ); 155 158 add_action( 'pre_get_posts', array( &$this, 'trace_var_wp_query' ), 1000 ); 156 159 add_action( 'wp_redirect', array( &$this, 'trace_var_redirect' ), 1000, 2 ); … … 158 161 } 159 162 160 if ( 1 == $this->settings['add_default_checkpoints'] ) { 161 Debug_Bar_Extender::instance()->start( 'start' ); 163 if ( 1 == $this->settings['add_default_checkpoints'] || ( 1 == Debug_Bar_Extender::instance()->settings['allow_url_settings'] && isset( $_GET['dbgx_add_default_checkpoints'] ) && 1 == $_GET['dbgx_add_default_checkpoints'] ) ) { 162 164 163 $checkpoint_actions = a rray(165 $checkpoint_actions = apply_filters( 'debugbarextender_default_checkpoint_actions', array( 164 166 'widgets_init', 165 167 'register_sidebar', … … 215 217 'admin_print_footer_scripts', 216 218 'admin_footer-edit.php', 217 218 ); 219 ) ); 219 220 220 221 foreach( $checkpoint_actions as $action_hook ) { 221 add_action( $action_hook, create_function( '$in=NULL', ' Debug_Bar_Extender::instance()->checkpoint("' . $action_hook . ' action");if ( $in ) return $in;' ) );222 add_action( $action_hook, create_function( '$in=NULL', 'dbgx_checkpoint("' . $action_hook . ' action");if ( $in ) return $in;' ) ); 222 223 } 223 224 } 224 225 } 225 226 227 /* 228 * Receive start time 229 */ 230 public function get_start_time() { 231 return $this->start_time; 232 } 233 234 /* 235 * Receive end time 236 */ 237 public function get_time() { 238 return $this->current_time; 239 } 240 226 241 /* 227 242 * Enqueue Styles and Scripts … … 279 294 $mem_usage = $this->guess_variable_size( $value ); 280 295 $trace = debug_backtrace(); 281 296 if ( !empty( $trace[1]['function'] ) && 'dbgx_trace_var' == $trace[1]['function'] ) // usage of dbgx_trace_var() shortcut function 297 array_shift( $trace ); 298 282 299 $result = array( 283 300 'file' => $trace[0]['file'], … … 453 470 } 454 471 455 $note = '<span class="debug-note">Note: you can measure runtimes between checkpoints via <code>Debug_Bar_Extender::instance()->start( $note="" )</code>, <code>Debug_Bar_Extender::instance()->checkpoint( $note="" )</code>, <code>Debug_Bar_Extender::instance()->end( $note="" )</code> </span>';472 $note = '<span class="debug-note">Note: you can measure runtimes between checkpoints via <code>Debug_Bar_Extender::instance()->start( $note="" )</code>, <code>Debug_Bar_Extender::instance()->checkpoint( $note="" )</code>, <code>Debug_Bar_Extender::instance()->end( $note="" )</code> or using the simple shortcut function <code>dbgx_checkpoint( $note="" )</code></span>'; 456 473 $out = $query_time . $out . $note; 457 474 return $out; … … 548 565 549 566 if ( 'variable' == $scope ) 550 $note = '<span class="debug-note">Note: you can screen additional variables via <code>Debug_Bar_Extender::instance()->trace_var( $value, $var_name = false )</code> . Omitting the <code>$var_name</code> will let the script look it up. Please be aware that sizes are approximate based on <code>strlen(serialize())</code></span>';567 $note = '<span class="debug-note">Note: you can screen additional variables via <code>Debug_Bar_Extender::instance()->trace_var( $value, $var_name = false )</code> or simply by using <code>dbgx_trace_var( $value, $var_name = false )</code>. Omitting the <code>$var_name</code> will let the script look it up. Please be aware that sizes are approximate based on <code>strlen(serialize())</code></span>'; 551 568 elseif ( 'memcache' == $scope ) 552 569 $note = '<span class="debug-note">Note: you can screen additional keys via <code>Debug_Bar_Extender::instance()->trace_memcache( $key, $group = "default" )</code>. This lookups are gathering the values from all datacenters and will show one value if all results are the same and multiple if the results in the datacenters differ. As sandboxes don\'t update remote memcache servers make sure to prime the caches by a live page load prior to sandboxing a site.</span>'; … … 556 573 private function log() { 557 574 $trace = debug_backtrace(); 575 if ( !empty( $trace[2]['function'] ) && 'dbgx_checkpoint' == $trace[2]['function'] ) // usage of dbgx_checkpoint() shortcut function 576 array_shift( $trace ); 577 558 578 $caller = $trace[1]; // it always goes through start, checkpoint or end 559 579 $result = array( … … 632 652 } 633 653 634 function settings_page() { ?> 654 public function settings_page() { 655 if ( !current_user_can( 'manage_options' ) ) { 656 global $current_user; 657 $msg = "I'm sorry, " . $current_user->display_name . " I'm afraid I can't do that."; 658 echo '<div class="wrap">' . $msg . '</div>'; 659 return false; 660 } 661 ?> 635 662 <div class="wrap"> 636 663 <?php if ( function_exists('screen_icon') ) screen_icon(); ?> … … 678 705 <?php 679 706 } 707 708 public function debug_action_admin_bar_menu() { 709 global $wp_admin_bar; 710 if ( 0 == Debug_Bar_Extender::instance()->settings['allow_url_settings'] || 0 == Debug_Bar_Extender::instance()->settings['enable_admin_bar_menu'] ) 711 return; 712 713 $wp_admin_bar->add_menu( array( 714 'id' => 'dbg', 715 'title' => 'DbgBExt', 716 'href' => false, 717 ) ); 718 $wp_admin_bar->add_menu( array( 719 'parent' => 'dbg', 720 'title' => 'default vars', 721 'href' => add_query_arg( array( 'dbgx_use_error_log' => 0, 'dbgx_add_default_checkpoints' => 0, 'dbgx_track_default_vars' => 1 ) ), 722 ) ); 723 $wp_admin_bar->add_menu( array( 724 'parent' => 'dbg', 725 'title' => 'default checkpoints', 726 'href' => add_query_arg( array( 'dbgx_use_error_log' => 0, 'dbgx_add_default_checkpoints' => 1, 'dbgx_track_default_vars' => 0 ) ), 727 ) ); 728 $wp_admin_bar->add_menu( array( 729 'parent' => 'dbg', 730 'title' => 'default checkpoints+vars', 731 'href' => add_query_arg( array( 'dbgx_use_error_log' => 0, 'dbgx_add_default_checkpoints' => 1, 'dbgx_track_default_vars' => 1 ) ), 732 ) ); 733 $wp_admin_bar->add_menu( array( 734 'parent' => 'dbg', 735 'title' => 'send to error_log', 736 'href' => add_query_arg( array( 'dbgx_use_error_log' => 1, 'dbgx_add_default_checkpoints' => 0, 'dbgx_track_default_vars' => 0 ) ), 737 ) ); 738 $wp_admin_bar->add_menu( array( 739 'parent' => 'dbg', 740 'title' => 'default vars -> log', 741 'href' => add_query_arg( array( 'dbgx_use_error_log' => 1, 'dbgx_add_default_checkpoints' => 0, 'dbgx_track_default_vars' => 1 ) ), 742 ) ); 743 $wp_admin_bar->add_menu( array( 744 'parent' => 'dbg', 745 'title' => 'default checkpoints -> log', 746 'href' => add_query_arg( array( 'dbgx_use_error_log' => 1, 'dbgx_add_default_checkpoints' => 1, 'dbgx_track_default_vars' => 0 ) ), 747 ) ); 748 $wp_admin_bar->add_menu( array( 749 'parent' => 'dbg', 750 'title' => 'default checkpoints+vars -> log', 751 'href' => add_query_arg( array( 'dbgx_use_error_log' => 1, 'dbgx_add_default_checkpoints' => 1, 'dbgx_track_default_vars' => 1 ) ), 752 ) ); 753 } 754 680 755 681 756 } 682 757 683 758 Debug_Bar_Extender::init(); 759 760 if ( !function_exists( 'dbgx_checkpoint' ) ) { 761 function dbgx_checkpoint( $note = '' ) { 762 if ( 0 == Debug_Bar_Extender::instance()->get_start_time() ) { 763 Debug_Bar_Extender::instance()->start( $note ); 764 } else { 765 Debug_Bar_Extender::instance()->checkpoint( $note ); 766 } 767 } 768 } 769 770 if ( !function_exists( 'dbgx_trace_var' ) ) { 771 function dbgx_trace_var( $value, $var_name = false ) { 772 Debug_Bar_Extender::instance()->trace_var( $value, $var_name ); 773 } 774 } -
debug-bar-extender/trunk/readme.txt
r425345 r432272 61 61 ` 62 62 63 == Advanced usage == 64 65 Looking at the source of the debug-bar-extender.php you will notice that there are various filters to control the default settings. This is useful when you are working on a multisite install and want to use the debug bar without having to adjust the settings every time. Here's an example of how settings enforced by a php file in mu-plugins/ could look like 66 67 `add_filter( 'debugbarextender_default_settings', 'my_debug_bar_extender_settings' ); 68 // enforce debug bar settings 69 function my_debug_bar_extender_settings( $default_settings ) { 70 $default_settings = array( 71 'enable_profiler' => 1, 72 'enable_variable_lookup' => 1, 73 'track_default_vars' => 0, 74 'add_default_checkpoints' => 1, 75 'savequeries_debugmode_enable' => 1, 76 'use_error_log' => 0, 77 'allow_url_settings' => 1, 78 'enable_admin_bar_menu' => 1, 79 ); 80 return $default_settings; 81 } 82 83 add_filter( 'debugbarextender_default_checkpoint_actions', 'my_debug_bar_extender_checkpoints' ); 84 // initiate some default checkpoints 85 function my_debug_bar_extender_checkpoints( $default_checkpoints ) { 86 $default_checkpoints = array( 87 'muplugins_loaded', 88 'wp_head', 89 'wp_footer', 90 'loop_start', 91 'loop_end', 92 'shutdown', 93 ); 94 return $default_checkpoints; 95 } 96 ` 97 63 98 == Wishlist == 64 99 … … 73 108 74 109 == ChangeLog == 110 111 = Version 0.5 = 112 113 * added filters to control settings `debugbarextender_default_settings`, `debugbarextender_default_checkpoint_actions` 114 * added wrapper functions `dbgx_checkpoint( $note = '' )` and `dbgx_trace_var( $value, $var_name = false )` for easier access to debugging functions. 115 * added new setting option to allow control of some settings via $_GET parameters in the urls. Allows dbgx_use_error_log, dbgx_track_default_vars, dbgx_add_default_checkpoints to be added as query strings in order to enable respective features. Combinations are possible - for example: /wp-admin/options-general.php?page=debug-bar-extender&dbgx_use_error_log=1&dbgx_add_default_checkpoints=1&dbgx_track_default_vars=1 116 * added new setting option to enable a admin bar menu with shortcuts to this urls 75 117 76 118 = Version 0.4 =
Note: See TracChangeset
for help on using the changeset viewer.