Skip to content

Commit

Permalink
2.1.5
Browse files Browse the repository at this point in the history
Tweak a few conditional outputs
Full support for all WPDB instances
Tweak query var output
Initial code for data logging before redirects (incomplete)
  • Loading branch information
johnbillion committed Mar 5, 2012
1 parent 0cb952f commit f3c2056
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 87 deletions.
17 changes: 12 additions & 5 deletions components/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function process() {

global $current_screen, $pagenow;

if ( !is_admin() )
return;

if ( !isset( $current_screen ) or empty( $current_screen ) ) {

# Pre-3.0 compat:
Expand Down Expand Up @@ -57,15 +60,20 @@ function process() {

function admin_menu( $menu ) {

$menu[] = $this->menu( array(
'title' => sprintf( __( 'Admin Screen: %s', 'query_monitor' ), $this->data['base'] )
) );
if ( isset( $this->data['base'] ) ) {
$menu[] = $this->menu( array(
'title' => sprintf( __( 'Admin Screen: %s', 'query_monitor' ), $this->data['base'] )
) );
}
return $menu;

}

function output( $args, $data ) {

if ( empty( $data ) )
return;

$post_type_warning = '';

echo '<table class="qm" cellspacing="0" id="' . $args['id'] . '">';
Expand Down Expand Up @@ -152,8 +160,7 @@ function output( $args, $data ) {
}

function register_qm_admin( $qm ) {
if ( is_admin() )
$qm['admin'] = new QM_Admin;
$qm['admin'] = new QM_Admin;
return $qm;
}

Expand Down
4 changes: 2 additions & 2 deletions components/conditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function output( $args, $data ) {

function process() {

$conds = array(
$conds = apply_filters( 'qm_conditionals', array(
'is_404', 'is_archive', 'is_admin', 'is_attachment', 'is_author', 'is_blog_admin', 'is_category', 'is_comments_popup',
'is_date', 'is_day', 'is_feed', 'is_front_page', 'is_home', 'is_main_site', 'is_month', 'is_multitax', /*'is_multi_author',*/
'is_network_admin', 'is_page', 'is_page_template', 'is_paged', 'is_post_type_archive', 'is_preview', 'is_robots', 'is_rtl',
'is_search', 'is_single', 'is_singular', 'is_ssl', 'is_sticky', 'is_tag', 'is_tax', 'is_time', 'is_trackback', 'is_year'
);
) );

$true = $false = $na = array();

Expand Down
45 changes: 18 additions & 27 deletions components/db_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
if ( !defined( 'QM_DB_LIMIT' ) )
define( 'QM_DB_LIMIT', 100 );

# @TODO warnings and shit for long/slow queries
# @TODO warnings for slow queries

class QM_DB_Queries extends QM {

var $id = 'db_queries';
var $db_objects = array();

function __construct() {
parent::__construct();
Expand All @@ -21,7 +22,8 @@ function __construct() {
}

function admin_title( $title ) {
$title[] = sprintf( __( '%s<small>Q</small>', 'query_monitor' ), number_format_i18n( $this->data['query_num'] ) );
foreach ( $this->data['dbs'] as $db )
$title[] = sprintf( __( '%s<small>Q</small>', 'query_monitor' ), number_format_i18n( $db->total_qs ) );
return $title;
}

Expand All @@ -38,6 +40,7 @@ function admin_menu( $menu ) {
if ( $errors = $this->get_errors() ) {
$menu[] = $this->menu( array(
'id' => 'query_monitor_errors',
'href' => '#qm-overview',
'title' => sprintf( __( 'Database Errors (%s)', 'query_monitor' ), number_format_i18n( count( $errors ) ) )
) );
}
Expand All @@ -56,13 +59,14 @@ function process() {
if ( !SAVEQUERIES )
return;

$this->data['query_num'] = 0;
$this->data['errors'] = array();
$this->data['db_objects'] = apply_filters( 'query_monitor_db_objects', array(
$this->data['query_num'] = 0;
$this->data['errors'] = array();

$this->db_objects = apply_filters( 'query_monitor_db_objects', array(
'$wpdb' => $GLOBALS['wpdb']
) );

foreach ( $this->data['db_objects'] as $name => $db ) {
foreach ( $this->db_objects as $name => $db ) {
if ( $this->is_db_object( $db ) )
$this->process_db_object( $name, $db );
}
Expand All @@ -74,10 +78,8 @@ function output( $args, $data ) {
if ( !SAVEQUERIES )
return;

foreach ( $data['db_objects'] as $name => $db ) {
if ( isset( $this->data['dbs'][$name] ) )
$this->output_queries( $name, $this->data['dbs'][$name] );
}
foreach ( $data['dbs'] as $name => $db )
$this->output_queries( $name, $db );

}

Expand Down Expand Up @@ -138,10 +140,10 @@ function process_db_object( $id, $db ) {
$total_time += $ltime;
$total_qs++;

if ( !empty( $funcs ) )
$func = reset( array_reverse( explode( ', ', $funcs ) ) );
if ( false !== strpos( $funcs, '.php' ) )
$func = sprintf( __( '<em>None</em> (%s)', 'query_monitor' ), $funcs );
else
$func = '<em class="qm-info">' . __( 'none', 'query_monitor' ) . '</em>';
$func = reset( array_reverse( explode( ', ', $funcs ) ) );

$this->add_func_time( $func, $ltime );

Expand All @@ -154,13 +156,7 @@ function process_db_object( $id, $db ) {
) as $cmd )
$sql = trim( str_replace( " $cmd ", "<br/>$cmd ", $sql ) );

$rows[] = array(
'func' => $func,
'funcs' => $funcs,
'sql' => $sql,
'ltime' => $ltime,
'result' => $result
);
$rows[] = compact( 'func', 'funcs', 'sql', 'ltime', 'result' );

if ( is_wp_error( $result ) )
$this->data['errors'][] = $result;
Expand All @@ -171,12 +167,7 @@ function process_db_object( $id, $db ) {
$this->data['query_num'] += $total_qs;

# @TODO put errors in here too:
$this->data['dbs'][$id] = (object) array(
'rows' => $rows,
'has_results' => $has_results,
'total_time' => $total_time,
'total_qs' => $total_qs,
);
$this->data['dbs'][$id] = (object) compact('rows', 'types', 'has_results', 'total_time', 'total_qs' );

}

Expand Down Expand Up @@ -245,7 +236,7 @@ function output_queries( $name, $db ) {

if ( $has_results ) {
if ( is_wp_error( $row['result'] ) ) {
$r = $row['result']->get_error_message( 'qmdb_error' );
$r = $row['result']->get_error_message( 'query_monitor_db_error' );
$results = "<td valign='top'>{$r}</td>\n";
$row_class = 'qm-warn';
} else {
Expand Down
32 changes: 24 additions & 8 deletions components/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ function process() {
global $wp_version, $blog_id;

$vars = array(
'key_buffer_size' => true, # Key cache limit
'max_allowed_packet' => false, # Max individual query size
'max_connections' => false, # Max client connections
'query_cache_limit' => true, # Individual query cache limit
'query_cache_size' => true, # Query cache limit
'key_buffer_size' => true, # Key cache size limit
'max_allowed_packet' => false, # Individual query size limit
'max_connections' => false, # Max number of client connections
# 'profiling' => 'OFF', # Query profiling on or off
'query_cache_limit' => true, # Individual query cache size limit
'query_cache_size' => true, # Total cache size limit
'query_cache_type' => 'ON' # Query cache on or off
);

if ( $dbq = $this->get_component( 'db_queries' ) ) {

foreach ( $dbq->data['db_objects'] as $id => $db ) {
foreach ( $dbq->db_objects as $id => $db ) {

if ( !$dbq->is_db_object( $db ) )
continue;

$variables = $db->get_results( "
SHOW VARIABLES
Expand All @@ -43,6 +47,8 @@ function process() {
$this->data['db'][$id] = array(
'version' => mysql_get_server_info( $db->dbh ),
'user' => $db->dbuser,
'host' => $db->dbhost,
'name' => $db->dbname,
'vars' => $vars,
'variables' => $variables
);
Expand Down Expand Up @@ -112,7 +118,7 @@ function output( $args, $data ) {
$name = $id . '<br />MySQL';

echo '<tr>';
echo '<td rowspan="' . ( 2 + count( $db['variables'] ) ) . '">' . $name . '</td>';
echo '<td rowspan="' . ( 4 + count( $db['variables'] ) ) . '">' . $name . '</td>';
echo '<td>version</td>';
echo '<td>' . $db['version'] . '</td>';
echo '</tr>';
Expand All @@ -122,6 +128,16 @@ function output( $args, $data ) {
echo '<td>' . $db['user'] . '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>host</td>';
echo '<td>' . $db['host'] . '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>database</td>';
echo '<td>' . $db['name'] . '</td>';
echo '</tr>';

echo '<tr>';

$first = true;
Expand All @@ -140,7 +156,7 @@ function output( $args, $data ) {
else if ( is_string( $db['vars'][$key] ) and ( $val !== $db['vars'][$key] ) )
$prepend .= $warning;

if ( is_numeric( $val ) and ( $val >= 1024 ) )
if ( is_numeric( $val ) and ( $val >= ( 1024*1024 ) ) )
$prepend .= '<br /><span class="qm-info">~' . size_format( $val ) . '</span>';

if ( !$first )
Expand Down
6 changes: 3 additions & 3 deletions components/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function process_late() {
global $wp_actions, $wp_filter, $querymonitor, $current_screen, $pagenow;

if ( $admin = $this->get_component( 'admin' ) )
if ( is_admin() and ( $admin = $this->get_component( 'admin' ) ) )
$screen = $admin->data['base'];
else
$screen = '';
Expand Down Expand Up @@ -71,7 +71,7 @@ function process_late() {

if ( $qm_class == $class )
$css_class = 'qm-qm';
$out = $class . '-&gt;' . $function['function'][1] . '()';
$out = $class . '->' . $function['function'][1] . '()';
} else {
$out = $function['function'] . '()';
}
Expand Down Expand Up @@ -120,7 +120,7 @@ function output( $args, $data ) {
echo '<tr class="' . $action['class'] . '">';
echo '<td valign="top" class="qm-priority">' . $action['priority'] . '</td>';
echo '<td valign="top" class="qm-ltr">';
echo $action['function'];
echo esc_html( $action['function'] );
echo '</td>';
echo '</tr>';
}
Expand Down
2 changes: 2 additions & 0 deletions components/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function output( $args, $data ) {
unset( $row['trace'][0], $row['trace'][1], $row['trace'][2] );
$f = 6;
$func = $row['trace'][$f];
if ( 0 === strpos( $func, 'fetch_rss' ) )
$func = $row['trace'][++$f];
if ( 0 === strpos( $func, 'SimplePie' ) )
$func = $row['trace'][++$f];
if ( 0 === strpos( $func, 'fetch_feed' ) )
Expand Down
22 changes: 14 additions & 8 deletions components/php_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ function output( $args, $data ) {
if ( !$first )
echo '<tr>';

$funca = $error->funcs;
$funca = $error->funcs;
unset( $funca[0], $funca[1] );

$funca = implode( ', ', array_reverse( $funca ) );
$func = $error->funcs[2];
$message = str_replace( "href='function.", "target='_blank' href='http://php.net/function.", $error->message );

echo '<td>' . $message . '</td>';
echo '<td>' . esc_html( $error->file ) . '</td>';
echo '<td title="' . esc_attr( $error->file ) . '">' . esc_html( $error->filename ) . '</td>';
echo '<td>' . esc_html( $error->line ) . '</td>';
echo '<td title="' . esc_attr( $funca ) . '" class="qm-ltr">' . esc_html( $func ) . '</td>';
echo '</tr>';
Expand Down Expand Up @@ -129,16 +130,21 @@ function error_handler( $type, $message, $file = null, $line = null ) {

$key = md5( $message . $file . $line . $funcs[0] );

$filename = str_replace( '\\', '/', $file );
$path = str_replace( '\\', '/', ABSPATH );
$filename = str_replace( $path, '', $filename );

if ( isset( $this->data['errors'][$type][$key] ) ) {
$this->data['errors'][$type][$key]->calls++;
} else {
$this->data['errors'][$type][$key] = (object) array(
'type' => $type,
'message' => $message,
'file' => $file,
'line' => $line,
'funcs' => $funcs,
'calls' => 1
'type' => $type,
'message' => $message,
'file' => $file,
'filename' => $filename,
'line' => $line,
'funcs' => $funcs,
'calls' => 1
);
}

Expand Down
17 changes: 16 additions & 1 deletion components/query_vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ function __construct() {

function process() {

$query_vars = array_filter( $GLOBALS['wp_query']->query_vars );
$plugin_qvars = apply_filters( 'query_vars', array() );
$qvars = $GLOBALS['wp_query']->query_vars;
$query_vars = array();

foreach ( $qvars as $k => $v ) {
if ( in_array( $k, $plugin_qvars ) ) {
if ( '' !== $v )
$query_vars[$k] = $v;
} else {
if ( !empty( $v ) )
$query_vars[$k] = $v;
}
}

ksort( $query_vars );

Expand Down Expand Up @@ -64,6 +75,10 @@ function output( $args, $data ) {
echo "<li>{$k} => {$v}</li>";
}
echo '</ul></td>';
} else if ( is_object( $value ) ) {
echo '<td valign="top"><pre>';
print_r( $value );
echo '</pre></td>';
} else {
$value = esc_html( $value );
echo "<td valign='top'>{$value}</td>";
Expand Down
Loading

0 comments on commit f3c2056

Please sign in to comment.