summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-01-23 18:26:37 +0100
committerDerek Jones <derek.jones@ellislab.com>2008-01-23 18:26:37 +0100
commit56e9fa581b9e7d590dfb56482b898339f29bd8f2 (patch)
tree52b18faa17bde54d6287eb2700f49421afc56e0c
parentdb708af87341897cbc7fd1157291377c253d371f (diff)
added $query_times property to DB driver for profiling
added individual query execution time to profiler output
-rw-r--r--system/database/DB_driver.php6
-rw-r--r--system/libraries/Profiler.php35
-rw-r--r--user_guide/changelog.html2
3 files changed, 32 insertions, 11 deletions
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 .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
$output .= "\n";
- $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>';
- $output .= "\n";
if ( ! class_exists('CI_DB_driver'))
{
- $output .= "<div style='color:#0000FF;font-weight:normal;padding:4px 0 0 0;'>".$this->CI->lang->line('profiler_no_db')."</div>";
+ $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>';
+ $output .= "\n";
+ $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
+ $output .="<tr><td width='100%' style='color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n";
}
else
{
+ $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').' ('.count($this->CI->db->queries).')&nbsp;&nbsp;</legend>';
+ $output .= "\n";
+ $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
+
if (count($this->CI->db->queries) == 0)
{
- $output .= "<div style='color:#0000FF;font-weight:normal;padding:4px 0 4px 0;'>".$this->CI->lang->line('profiler_no_queries')."</div>";
+ $output .= "<tr><td width='100%' style='color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\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 .= '<div style="padding:3px;margin:12px 0 12px 0;background-color:#ddd;color:#000">';
- $output .= htmlspecialchars($val, ENT_QUOTES);
- $output .= "</div>\n";
- }
+ $val = htmlspecialchars($val, ENT_QUOTES);
+ $time = number_format($this->CI->db->query_times[$key], 4);
+
+ foreach ($highlight as $bold)
+ {
+ $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val);
+ }
+
+ $output .= "<tr><td width='1%' valign='top' style='color:#990000;font-weight:normal;background-color:#ddd;'>".$time."&nbsp;&nbsp;</td><td style='color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
+ }
}
}
- $output .= "</fieldset>";
+ $output .= "</table>\n";
+ $output .= "</fieldset>";
return $output;
}
+
// --------------------------------------------------------------------
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 8889e279d..090528a44 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -103,7 +103,7 @@ Change Log
<li>Added the ability to <a href="./general/autoloader.html">auto-load</a> <a href="./general/models.html">Models</a>.</li>
<li>Reorganized the URI and Routes classes for better clarity.</li>
<li>Added Compat.php to allow function overrides for older versions of PHP or PHP environments missing certain extensions / libraries</li>
- <li>Added memory usage, GET, and URI string data to Profiler output.</li>
+ <li>Added memory usage, GET, URI string data, and individual query execution time to Profiler output.</li>
<li>Deprecated Scaffolding.</li>
</ul>
</li>