From 56e9fa581b9e7d590dfb56482b898339f29bd8f2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 23 Jan 2008 17:26:37 +0000 Subject: added $query_times property to DB driver for profiling added individual query execution time to profiler output --- system/database/DB_driver.php | 6 ++++++ system/libraries/Profiler.php | 35 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 65be13dc9..dbd54bebe 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -48,6 +48,7 @@ class CI_DB_driver { var $bind_marker = '?'; var $save_queries = TRUE; var $queries = array(); + var $query_times = array(); var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; @@ -341,6 +342,11 @@ class CI_DB_driver { $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); + if ($this->save_queries == TRUE) + { + $this->query_times[] = ($em + $es) - ($sm + $ss); + } + // Increment the query counter $this->query_count++; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 3b189027f..21c2135cc 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -105,34 +105,49 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; if ( ! class_exists('CI_DB_driver')) { - $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; + $output .= "\n"; + $output .= "\n\n\n"; + $output .="\n"; } else { + $output .= '  '.$this->CI->lang->line('profiler_queries').' ('.count($this->CI->db->queries).')  '; + $output .= "\n"; + $output .= "\n\n
".$this->CI->lang->line('profiler_no_db')."
\n"; + if (count($this->CI->db->queries) == 0) { - $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; + $output .= "\n"; } else { - foreach ($this->CI->db->queries as $val) + $highlight = array('SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'LEFT JOIN', 'ORDER BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE'); + + foreach ($this->CI->db->queries as $key => $val) { - $output .= '
'; - $output .= htmlspecialchars($val, ENT_QUOTES); - $output .= "
\n"; - } + $val = htmlspecialchars($val, ENT_QUOTES); + $time = number_format($this->CI->db->query_times[$key], 4); + + foreach ($highlight as $bold) + { + $val = str_replace($bold, ''.$bold.'', $val); + } + + $output .= "\n"; + } } } - $output .= ""; + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
".$time."  ".$val."
\n"; + $output .= "
"; return $output; } + // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b