Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Include the connection name in the query profiling section (Issue #1368) #1369

Closed
wants to merge 6 commits into from

3 participants

@amccausl

Little tweak to make profiling more useful.

system/libraries/Cache/Cache.php
@@ -117,7 +122,23 @@ public function __construct($config = array())
*/
public function get($id)
{
- return $this->{$this->_adapter}->get($id);
+ if( $this->save_queries )

Please try and following the coding style guide and wrap with {'s on new lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/libraries/Cache/Cache.php
@@ -132,7 +153,23 @@ public function get($id)
*/
public function save($id, $data, $ttl = 60)
{
- return $this->{$this->_adapter}->save($id, $data, $ttl);
+ if( $this->save_queries )

Spaces are off, please use this:

if ($this->save_queries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/libraries/Cache/Cache.php
@@ -117,7 +122,23 @@ public function __construct($config = array())
*/
public function get($id)
{
- return $this->{$this->_adapter}->get($id);
+ if ($this->save_queries)
+ $this->queries[] = "get( '{$id}' )";
+
+ // Start the Query Timer
+ $time_start = list($sm, $ss) = explode(' ', microtime());
@narfbg Owner
narfbg added a note

Use microtime(TRUE) (on each such instance).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/libraries/Cache/Cache.php
@@ -117,7 +122,23 @@ public function __construct($config = array())
*/
public function get($id)
{
- return $this->{$this->_adapter}->get($id);
+ if ($this->save_queries)
+ $this->queries[] = "get( '{$id}' )";
@narfbg Owner
narfbg added a note

This needs to be wrapped around in braces, see some examples in here: http://codeigniter.com/user_guide/general/styleguide.html#code_indenting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/libraries/Cache/Cache.php
@@ -117,7 +122,27 @@ public function __construct($config = array())
*/
public function get($id)
{
- return $this->{$this->_adapter}->get($id);
+ if ($this->save_queries)
+ {
+ $this->queries[] = "get( '{$id}' )";
+ }
+
+ // Start the Query Timer
+ $time_start = list($sm, $ss) = explode(' ', microtime(TRUE));
@narfbg Owner
narfbg added a note

That's really not what I meant. microtime(TRUE) returns a float with the sum of your originally exploded values, it is used like this:

$time_start = microtime(TRUE);

// Do stuff

$time_end = microtime(TRUE);

$time_total = $time_end - $time_start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg
Owner

Partially implemented, see 55a8c62.
Please submit a separate pull request for Cache information.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2012
  1. Added cache operations to the 'queries' section of the profiler stats…

    Alex McCausland authored
    … (Issue #1370)
Commits on May 25, 2012
  1. Fix whitespace for IFs (Issue #1370)

    Alex McCausland authored
Commits on Jun 12, 2012
Commits on Jun 18, 2012
  1. Fix usage of microtime (Issue #1370)

    Alex McCausland authored
Commits on Jul 4, 2012
  1. Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into …

    Alex McCausland authored
    …develop
This page is out of date. Refresh to see the latest.
View
1  system/language/english/profiler_lang.php
@@ -26,6 +26,7 @@
*/
$lang['profiler_database'] = 'DATABASE';
+$lang['profiler_cache'] = 'CACHE';
$lang['profiler_controller_info'] = 'CLASS/METHOD';
$lang['profiler_benchmarks'] = 'BENCHMARKS';
$lang['profiler_queries'] = 'QUERIES';
View
71 system/libraries/Cache/Cache.php
@@ -71,6 +71,11 @@ class CI_Cache extends CI_Driver_Library {
*/
protected $_backup_driver = 'dummy';
+ public $query_count = 0;
+ public $save_queries = TRUE;
+ public $queries = array();
+ public $query_times = array();
+
/**
* Constructor
*
@@ -134,7 +139,27 @@ public function __construct($config = array())
*/
public function get($id)
{
- return $this->{$this->_adapter}->get($id);
+ if ($this->save_queries)
+ {
+ $this->queries[] = "get( '{$id}' )";
+ }
+
+ // Start the Query Timer
+ $time_start = microtime(TRUE);
+
+ $item = $this->{$this->_adapter}->get($id);
+
+ // Stop and aggregate the query time results
+ $time_end = microtime(TRUE);
+
+ if ($this->save_queries)
+ {
+ $this->query_times[] = $time_end - $time_start;
+ }
+
+ $this->query_count++;
+
+ return $item;
}
// ------------------------------------------------------------------------
@@ -149,7 +174,27 @@ public function get($id)
*/
public function save($id, $data, $ttl = 60)
{
- return $this->{$this->_adapter}->save($id, $data, $ttl);
+ if ($this->save_queries)
+ {
+ $this->queries[] = "save( '{$id}' )";
+ }
+
+ // Start the Query Timer
+ $time_start = microtime(TRUE);
+
+ $response = $this->{$this->_adapter}->save($id, $data, $ttl);
+
+ // Stop and aggregate the query time results
+ $time_end = microtime(TRUE);
+
+ if ($this->save_queries)
+ {
+ $this->query_times[] = $time_end - $time_start;
+ }
+
+ $this->query_count++;
+
+ return $response;
}
// ------------------------------------------------------------------------
@@ -162,7 +207,27 @@ public function save($id, $data, $ttl = 60)
*/
public function delete($id)
{
- return $this->{$this->_adapter}->delete($id);
+ if ($this->save_queries)
+ {
+ $this->queries[] = "delete( '{$id}' )";
+ }
+
+ // Start the Query Timer
+ $time_start = microtime(TRUE);
+
+ $response = $this->{$this->_adapter}->delete($id);
+
+ // Stop and aggregate the query time results
+ $time_end = microtime(TRUE);
+
+ if ($this->save_queries)
+ {
+ $this->query_times[] = $time_end - $time_start;
+ }
+
+ $this->query_count++;
+
+ return $response;
}
// ------------------------------------------------------------------------
View
12 system/libraries/Profiler.php
@@ -190,11 +190,11 @@ protected function _compile_queries()
$dbs = array();
// Let's determine which databases are currently connected to
- foreach (get_object_vars($this->CI) as $CI_object)
+ foreach (get_object_vars($this->CI) as $name => $CI_object)
{
- if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB'))
+ if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') || is_a($CI_object, 'CI_Cache'))
{
- $dbs[] = $CI_object;
+ $dbs[$name] = $CI_object;
}
}
@@ -219,7 +219,7 @@ protected function _compile_queries()
$output = "\n\n";
$count = 0;
- foreach ($dbs as $db)
+ foreach ($dbs as $name => $db)
{
$hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : '';
@@ -232,8 +232,8 @@ protected function _compile_queries()
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">'
."\n"
- .'<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database')
- .':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
+ .'<legend style="color:#0000FF;">&nbsp;&nbsp;'.(is_a($db, 'CI_DB') ? $this->CI->lang->line('profiler_database') : $this->CI->lang->line('profiler_cache') )
+ .':&nbsp; '.(isset($db->database) ? $db->database : $db->_adapter).'&nbsp;('.$name.') &nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries')
.': '.count($db->queries).'&nbsp;&nbsp;'.$show_hide_js."</legend>\n\n\n"
.'<table style="width:100%;'.$hide_queries.'" id="ci_profiler_queries_db_'.$count."\">\n";
Something went wrong with that request. Please try again.