Skip to content

Commit

Permalink
Added cache operations to the 'queries' section of the profiler stats…
Browse files Browse the repository at this point in the history
… (Issue bcit-ci#1370)
  • Loading branch information
Alex McCausland committed May 18, 2012
1 parent 744d7ce commit b938ea6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
5 changes: 3 additions & 2 deletions system/language/english/profiler_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
*
* Licensed under the Open Software License version 3.0
*
*
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
Expand All @@ -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';
Expand Down
59 changes: 56 additions & 3 deletions system/libraries/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class CI_Cache extends CI_Driver_Library {
*/
protected $_backup_driver;

public $query_count = 0;
public $save_queries = TRUE;
public $queries = array();
public $query_times = array();

/**
* Constructor
*
Expand Down Expand Up @@ -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());

$item = $this->{$this->_adapter}->get($id);

// Stop and aggregate the query time results
$time_end = list($em, $es) = explode(' ', microtime());

if ($this->save_queries == TRUE)
$this->query_times[] = ($em + $es) - ($sm + $ss);

$this->query_count++;

return $item;
}

// ------------------------------------------------------------------------
Expand All @@ -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 )
$this->queries[] = "save( '{$id}' )";

// Start the Query Timer
$time_start = list($sm, $ss) = explode(' ', microtime());

$response = $this->{$this->_adapter}->save($id, $data, $ttl);

// Stop and aggregate the query time results
$time_end = list($em, $es) = explode(' ', microtime());

if ($this->save_queries == TRUE)
$this->query_times[] = ($em + $es) - ($sm + $ss);

$this->query_count++;

return $response;
}

// ------------------------------------------------------------------------
Expand All @@ -145,7 +182,23 @@ 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 = list($sm, $ss) = explode(' ', microtime());

$response = $this->{$this->_adapter}->delete($id);

// Stop and aggregate the query time results
$time_end = list($em, $es) = explode(' ', microtime());

if ($this->save_queries == TRUE)
$this->query_times[] = ($em + $es) - ($sm + $ss);

$this->query_count++;

return $response;
}

// ------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions system/libraries/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function _compile_queries()
// Let's determine which databases are currently connected to
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[$name] = $CI_object;
}
Expand Down Expand Up @@ -226,8 +226,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;('.$name.') &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";

Expand Down

0 comments on commit b938ea6

Please sign in to comment.