public function admin_menu(array $menu) { if ($dbq = QueryMonitor::get_collector('db_queries')) { $dbq_data = $dbq->get_data(); if (isset($dbq_data['times'])) { $menu[] = $this->menu(array('title' => __('Queries by Caller', 'query-monitor'))); } } return $menu; }
public function process() { if ($dbq = QueryMonitor::get_collector('db_queries')) { if (isset($dbq->data['component_times'])) { $this->data['times'] = $dbq->data['component_times']; usort($this->data['times'], 'QM_Collector::sort_ltime'); } if (isset($dbq->data['types'])) { $this->data['types'] = $dbq->data['types']; } } }
public function output() { $data = $this->collector->get_data(); $db_query_num = null; $db_query_types = array(); # @TODO: make this less derpy: $db_queries = QueryMonitor::get_collector('db_queries'); if ($db_queries) { $db_queries_data = $db_queries->get_data(); if (isset($db_queries_data['types'])) { $db_query_num = $db_queries_data['types']; $db_stime = number_format_i18n($db_queries_data['total_time'], 4); } } $total_stime = number_format_i18n($data['time'], 4); echo '<div class="qm" id="' . $this->collector->id() . '">'; echo '<table cellspacing="0">'; $memory_usage = '<br><span class="qm-info">' . sprintf(__('%1$s%% of %2$s kB limit', 'query-monitor'), number_format_i18n($data['memory_usage'], 1), number_format_i18n($data['memory_limit'] / 1024)) . '</span>'; $time_usage = '<br><span class="qm-info">' . sprintf(__('%1$s%% of %2$ss limit', 'query-monitor'), number_format_i18n($data['time_usage'], 1), number_format_i18n($data['time_limit'])) . '</span>'; echo '<thead>'; echo '<tr>'; echo '<th scope="col">' . __('Page generation time', 'query-monitor') . '</th>'; echo '<th scope="col">' . __('Peak memory usage', 'query-monitor') . '</th>'; if (isset($db_query_num)) { echo '<th scope="col">' . __('Database query time', 'query-monitor') . '</th>'; echo '<th scope="col">' . __('Database queries', 'query-monitor') . '</th>'; } echo '</tr>'; echo '</thead>'; echo '<tbody>'; echo '<tr>'; echo "<td>{$total_stime}{$time_usage}</td>"; echo '<td>' . sprintf(__('%s kB', 'query-monitor'), number_format_i18n($data['memory'] / 1024)) . $memory_usage . '</td>'; if (isset($db_query_num)) { echo "<td>{$db_stime}</td>"; echo '<td>'; foreach ($db_query_num as $type_name => $type_count) { $db_query_types[] = sprintf('%1$s: %2$s', $type_name, number_format_i18n($type_count)); } echo implode('<br>', $db_query_types); echo '</td>'; } echo '</tr>'; echo '</tbody>'; echo '</table>'; echo '</div>'; }
public function process() { global $wp_actions, $wp_filter; if (is_admin() and $admin = QueryMonitor::get_collector('admin')) { $this->data['screen'] = $admin->data['base']; } else { $this->data['screen'] = ''; } $hooks = $parts = $components = array(); foreach ($wp_actions as $name => $count) { $actions = array(); # @TODO better variable name: $c = array(); if (isset($wp_filter[$name])) { # http://core.trac.wordpress.org/ticket/17817 $action = $wp_filter[$name]; foreach ($action as $priority => $callbacks) { foreach ($callbacks as $callback) { $callback = QM_Util::populate_callback($callback); if (isset($callback['component'])) { $c[$callback['component']->name] = $callback['component']->name; } $actions[] = array('priority' => $priority, 'callback' => $callback); } } } # @TODO better variable name: $p = array_filter(preg_split('/[_\\/-]/', $name)); $parts = array_merge($parts, $p); $components = array_merge($components, $c); $hooks[$name] = array('name' => $name, 'actions' => $actions, 'parts' => $p, 'components' => $c); } $this->data['hooks'] = $hooks; $this->data['parts'] = array_unique(array_filter($parts)); $this->data['components'] = array_unique(array_filter($components)); }
public function process() { global $wp_version, $blog_id; $mysql_vars = array('key_buffer_size' => true, 'max_allowed_packet' => false, 'max_connections' => false, 'query_cache_limit' => true, 'query_cache_size' => true, 'query_cache_type' => 'ON'); $php_u = ''; if ($dbq = QueryMonitor::get_collector('db_queries')) { foreach ($dbq->db_objects as $id => $db) { if (!is_a($db, 'wpdb')) { continue; } $variables = $db->get_results("\n\t\t\t\t\tSHOW VARIABLES\n\t\t\t\t\tWHERE Variable_name IN ( '" . implode("', '", array_keys($mysql_vars)) . "' )\n\t\t\t\t"); if (is_resource($db->dbh)) { $version = mysql_get_server_info($db->dbh); $driver = 'mysql'; } else { if (is_object($db->dbh) and method_exists($db->dbh, 'db_version')) { $version = $db->dbh->db_version(); $driver = get_class($db->dbh); } else { $version = $driver = '<span class="qm-warn">' . __('Unknown', 'query-monitor') . '</span>'; } } $this->data['db'][$id] = array('version' => $version, 'driver' => $driver, 'user' => $db->dbuser, 'host' => $db->dbhost, 'name' => $db->dbname, 'vars' => $mysql_vars, 'variables' => $variables); } } if (function_exists('posix_getpwuid')) { $u = posix_getpwuid(posix_getuid()); $g = posix_getgrgid($u['gid']); $php_u = esc_html($u['name'] . ':' . $g['name']); } else { if (isset($_SERVER['USER'])) { $php_u = esc_html($_SERVER['USER']); } else { if (function_exists('exec')) { $php_u = esc_html(exec('whoami')); } } } if (empty($php_u)) { $php_u = '<em>' . __('Unknown', 'query-monitor') . '</em>'; } $this->data['php']['version'] = phpversion(); $this->data['php']['user'] = $php_u; foreach ($this->php_vars as $setting) { $this->data['php']['variables'][$setting]['after'] = ini_get($setting); } $this->data['php']['error_reporting'] = error_reporting(); # @TODO put WP's other debugging constants in here, eg. SCRIPT_DEBUG $this->data['wp'] = array('version' => $wp_version, 'WP_DEBUG' => self::format_bool_constant('WP_DEBUG'), 'WP_LOCAL_DEV' => self::format_bool_constant('WP_LOCAL_DEV')); if (is_multisite()) { $this->data['wp']['blog_id'] = $blog_id; } $server = explode(' ', $_SERVER['SERVER_SOFTWARE']); $server = explode('/', reset($server)); if (isset($server[1])) { $server_version = $server[1]; } else { $server_version = '<em>' . __('Unknown', 'query-monitor') . '</em>'; } if (isset($_SERVER['SERVER_ADDR'])) { $address = $_SERVER['SERVER_ADDR']; } else { $address = '<em>' . __('Unknown', 'query-monitor') . '</em>'; } $this->data['server'] = array('name' => $server[0], 'version' => $server_version, 'address' => $address, 'host' => php_uname('n')); }