Inheritance: extends QM_Plugin
/**
 * Require the plugin files for Query Monitor, faking a
 * plugin activation, if it's the first time.
 */
function wpcom_vip_qm_require()
{
    /**
     * Filter whether Query Monitor is activated; return true,
     * if QM should be activated.
     *
     * @param bool $enable False by default
     */
    if (!apply_filters('wpcom_vip_qm_enable', false)) {
        return;
    }
    if (!defined('SAVEQUERIES')) {
        define('SAVEQUERIES', true);
    }
    // For hyperdb, which doesn't use SAVEQUERIES
    global $wpdb;
    $wpdb->save_queries = SAVEQUERIES;
    $wpcom_vip_qm_file = __DIR__ . '/query-monitor/query-monitor.php';
    require_once $wpcom_vip_qm_file;
    // Because we're including Query Monitor as an MU plugin, we need to
    // manually call the `activate` method on `activation`.
    if (0 === get_option('wpcom_vip_qm_activated', 0)) {
        QueryMonitor::init($wpcom_vip_qm_file)->activate(true);
        update_option('wpcom_vip_qm_activated', 1, true);
    }
    // We don't want to share our environment information via Query Monitor
    remove_filter('qm/collectors', 'register_qm_collector_environment', 20, 2);
    // We know we haven't got the QM DB drop-in in place, so don't show the message
    add_filter('qm/show_extended_query_prompt', '__return_false');
}
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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'];
         }
     }
 }
Beispiel #4
0
 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>';
 }
Beispiel #5
0
function register_qm_collectors_debug_bar()
{
    global $debug_bar;
    if (class_exists('Debug_Bar') || qm_debug_bar_being_activated()) {
        return;
    }
    $collectors = QM_Collectors::init();
    $qm = QueryMonitor::init();
    require_once $qm->plugin_path('classes/debug_bar.php');
    $debug_bar = new Debug_Bar();
    $redundant = array('debug_bar_actions_addon_panel', 'debug_bar_remote_requests_panel', 'debug_bar_screen_info_panel', 'ps_listdeps_debug_bar_panel');
    foreach ($debug_bar->panels as $panel) {
        $panel_id = strtolower(get_class($panel));
        if (in_array($panel_id, $redundant)) {
            continue;
        }
        $collector = new QM_Collector_Debug_Bar();
        $collector->set_id("debug_bar_{$panel_id}");
        $collector->set_panel($panel);
        $collectors->add($collector);
    }
}
Beispiel #6
0
 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));
 }
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
defined('ABSPATH') or die;
$qm_dir = dirname(__FILE__);
# No autoloaders for us. See https://github.com/johnbillion/query-monitor/issues/7
foreach (array('Plugin', 'Activation', 'Util') as $qm_class) {
    require_once "{$qm_dir}/classes/{$qm_class}.php";
}
QM_Activation::init(__FILE__);
if (defined('QM_DISABLED') and QM_DISABLED) {
    return;
}
if ('cli' === php_sapi_name() && !defined('QM_TESTS')) {
    # For the time being, let's not load QM when using the CLI because we've no persistent storage and no means of
    # outputting collected data on the CLI. This will hopefully change in a future version of QM.
    return;
}
if (defined('DOING_CRON') && DOING_CRON) {
    # Let's not load QM during cron events for the same reason as above.
    return;
}
foreach (array('QueryMonitor', 'Backtrace', 'Collectors', 'Collector', 'Dispatchers', 'Dispatcher', 'Output') as $qm_class) {
    require_once "{$qm_dir}/classes/{$qm_class}.php";
}
QueryMonitor::init(__FILE__);
Beispiel #8
0
 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'));
 }