You are here

function devel_queries in Devel 6

Same name and namespace in other branches
  1. 5 devel.module \devel_queries()
4 string references to 'devel_queries'
devel_menu in ./devel.module
Implementation of hook_menu().
devel_store_queries in ./devel.module
devel_update_4 in ./devel.install
devel_update_5 in ./devel.install

File

./devel.module, line 2059

Code

function devel_queries() {
  $header = array(
    array(
      'data' => t('Total (ms)'),
      'field' => 'total_time',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Average (ms)'),
      'field' => 'average',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Std deviation (ms)'),
    ),
    array(
      'data' => t('Count'),
      'field' => 'count',
    ),
    array(
      'data' => t('Function'),
      'field' => 'q.function',
    ),
    array(
      'data' => t('Query'),
      'field' => 'q.query',
    ),
  );
  global $db_type;
  if ($db_type == 'pgsql') {
    $result = pager_query('SELECT q.qid, q.query, q.function , t.* FROM {devel_queries} q INNER JOIN (SELECT t.qid, COUNT(t.qid) AS count,SUM(t.time) AS total_time, AVG(t.time) AS average, STDDEV(t.time) AS stddev FROM {devel_times} t GROUP BY t.qid) AS t ON t.qid=q.qid ' . tablesort_sql($header), 30, 0, 'SELECT COUNT(qid) FROM {devel_queries}');
  }
  else {
    $result = pager_query('SELECT q.qid, q.query, q.function, t.*, COUNT(t.qid) AS count, SUM(t.time) AS total_time, AVG(t.time) AS average, STDDEV(t.time) AS stddev FROM {devel_queries} q INNER JOIN {devel_times} t ON q.qid = t.qid GROUP BY t.qid ' . tablesort_sql($header), 30, 0, 'SELECT COUNT(qid) FROM {devel_queries}');
  }
  while ($log = db_fetch_object($result)) {
    $rows[] = array(
      round($log->total_time * 1000, 3),
      round($log->average * 1000, 3),
      round($log->stddev * 1000, 3),
      $log->count,
      $log->function,
      check_plain($log->query),
    );
  }
  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 30, 0);
  $output .= l(t('Delete collected query statistics'), 'devel/queries/empty');
  print theme('page', $output, FALSE);
}