summaryrefslogtreecommitdiffstats
path: root/system/libraries/Profiler.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Profiler.php')
-rw-r--r--system/libraries/Profiler.php89
1 files changed, 67 insertions, 22 deletions
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 6320ab50d..1c97e3481 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Profiler Class
@@ -42,23 +43,47 @@
*/
class CI_Profiler {
+ /**
+ * List of profiler sections available to show
+ *
+ * @var array
+ */
protected $_available_sections = array(
- 'benchmarks',
- 'get',
- 'memory_usage',
- 'post',
- 'uri_string',
- 'controller_info',
- 'queries',
- 'http_headers',
- 'session_data',
- 'config'
- );
+ 'benchmarks',
+ 'get',
+ 'memory_usage',
+ 'post',
+ 'uri_string',
+ 'controller_info',
+ 'queries',
+ 'http_headers',
+ 'session_data',
+ 'config'
+ );
+ /**
+ * Number of queries to show before making the additional queries togglable
+ *
+ * @var int
+ */
protected $_query_toggle_count = 25;
+ /**
+ * Reference to the CodeIgniter singleton
+ *
+ * @var object
+ */
protected $CI;
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * Initialize Profiler
+ *
+ * @param array $config Parameters
+ */
public function __construct($config = array())
{
$this->CI =& get_instance();
@@ -89,11 +114,17 @@ class CI_Profiler {
*
* Sets the private _compile_* properties to enable/disable Profiler sections
*
- * @param mixed
+ * @param mixed $config
* @return void
*/
public function set_sections($config)
{
+ if (isset($config['query_toggle_count']))
+ {
+ $this->_query_toggle_count = (int) $config['query_toggle_count'];
+ unset($config['query_toggle_count']);
+ }
+
foreach ($config as $method => $enable)
{
if (in_array($method, $this->_available_sections))
@@ -162,11 +193,24 @@ class CI_Profiler {
$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 => $cobject)
{
- if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB'))
+ if (is_object($cobject))
{
- $dbs[] = $CI_object;
+ if ($cobject instanceof CI_DB)
+ {
+ $dbs[get_class($this->CI).':$'.$name] = $cobject;
+ }
+ elseif ($cobject instanceof CI_Model)
+ {
+ foreach (get_object_vars($cobject) as $mname => $mobject)
+ {
+ if ($mobject instanceof CI_DB)
+ {
+ $dbs[get_class($cobject).':$'.$mname] = $mobject;
+ }
+ }
+ }
}
}
@@ -191,13 +235,13 @@ class CI_Profiler {
$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' : '';
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_hide').'\'?\''.$this->CI->lang->line('profiler_section_show').'\':\''.$this->CI->lang->line('profiler_section_hide').'\';">'.$this->CI->lang->line('profiler_section_hide').'</span>)';
- if ($hide_queries != '')
+ if ($hide_queries !== '')
{
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)';
}
@@ -205,7 +249,7 @@ class CI_Profiler {
$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')
+ .':&nbsp; '.$db->database.' ('.$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";
@@ -293,7 +337,7 @@ class CI_Profiler {
."\n"
.'<legend style="color:#009900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_post_data')."&nbsp;&nbsp;</legend>\n";
- if (count($_POST) == 0)
+ if (count($_POST) === 0)
{
$output .= '<div style="color:#009900;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_post').'</div>';
}
@@ -343,7 +387,7 @@ class CI_Profiler {
."\n"
.'<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_uri_string')."&nbsp;&nbsp;</legend>\n"
.'<div style="color:#000;font-weight:normal;padding:4px 0 4px 0;">'
- .($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string)
+ .($this->CI->uri->uri_string === '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string)
.'</div></fieldset>';
}
@@ -380,7 +424,7 @@ class CI_Profiler {
."\n"
.'<legend style="color:#5a0099;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_memory_usage')."&nbsp;&nbsp;</legend>\n"
.'<div style="color:#5a0099;font-weight:normal;padding:4px 0 4px 0;">'
- .((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory'))
+ .(($usage = memory_get_usage()) != '' ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory'))
.'</div></fieldset>';
}
@@ -505,6 +549,7 @@ class CI_Profiler {
return $output.'</div>';
}
+
}
/* End of file Profiler.php */