From e6e6e64ab078205153513af24dd4163157efb148 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 15:54:13 -0500 Subject: changeset: 2204:37301a84c8be tag: tip user: Greg Aker date: Mon Apr 18 15:51:28 2011 -0500 summary: Adding toggle show/hide on database queries in the output profiler. Added a profiler config item to set a threshold of when to hide the queries by default. Additionally, fixed a bug I created earlier today by marking the $CI class var in CI_Profiler as private. --- system/libraries/Profiler.php | 35 ++++++++++--- user_guide/general/profiling.html | 103 ++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 55 deletions(-) diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index d1828b984..b73ddaf0d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,8 +32,6 @@ */ class CI_Profiler { - private $CI; - protected $_available_sections = array( 'benchmarks', 'get', @@ -46,12 +44,24 @@ class CI_Profiler { 'session_data', 'config' ); + + protected $_query_toggle_count = 25; + + protected $CI; + // -------------------------------------------------------------------- + public function __construct($config = array()) { $this->CI =& get_instance(); $this->CI->load->language('profiler'); + if (isset($config['query_toggle_count'])) + { + $this->_query_toggle_count = (int) $config['query_toggle_count']; + unset($config['query_toggle_count']); + } + // default all sections to display foreach ($this->_available_sections as $section) { @@ -163,7 +173,7 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; $output .="\n"; $output .= "
".$this->CI->lang->line('profiler_no_db')."
\n"; $output .= ""; @@ -178,14 +188,27 @@ class CI_Profiler { $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); $output = "\n\n"; - + + $count = 0; + foreach ($dbs as $db) { + $count++; + + $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; + + $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; + + if ($hide_queries != '') + { + $show_hide_js = '('.$this->CI->lang->line('profiler_section_show').')'; + } + $output .= '
'; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'   '; + $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'  '.$show_hide_js.''; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; if (count($db->queries) == 0) { diff --git a/user_guide/general/profiling.html b/user_guide/general/profiling.html index f3ea0c6fd..78ece7dcd 100644 --- a/user_guide/general/profiling.html +++ b/user_guide/general/profiling.html @@ -105,55 +105,60 @@ This information can be useful during development in order to help with debuggin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyDescriptionDefault
benchmarksElapsed time of Benchmark points and total execution timeTRUE
configCodeIgniter Config variablesTRUE
controller_infoThe Controller class and method requestedTRUE
getAny GET data passed in the requestTRUE
http_headersThe HTTP headers for the current requestTRUE
memory_usageAmount of memory consumed by the current request, in bytesTRUE
postAny POST data passed in the requestTRUE
queriesListing of all database queries executed, including execution timeTRUE
uri_stringThe URI of the current requestTRUE
KeyDescriptionDefault
benchmarksElapsed time of Benchmark points and total execution timeTRUE
configCodeIgniter Config variablesTRUE
controller_infoThe Controller class and method requestedTRUE
getAny GET data passed in the requestTRUE
http_headersThe HTTP headers for the current requestTRUE
memory_usageAmount of memory consumed by the current request, in bytesTRUE
postAny POST data passed in the requestTRUE
queriesListing of all database queries executed, including execution timeTRUE
uri_stringThe URI of the current requestTRUE
query_toggle_countThe number of queries after which the query block will default to hidden.25
-- cgit v1.2.3-24-g4f1b