From 195d311796072477c5808ce99688abae1512b696 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 03:59:13 +0200 Subject: Improve the Profiler library --- system/libraries/Profiler.php | 225 +++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 144 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 8a2568d8e..9cbd69bb2 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,13 +1,13 @@ -CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) { - if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) - { - $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); - } + $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); } } @@ -139,12 +137,11 @@ class CI_Profiler { // Note: At some point we should turn this into a template that can // be modified. We also might want to make this data available to be logged - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; - $output .= "\n"; - $output .= "\n\n\n"; + $output = "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_benchmarks').'  ' + . "\n\n\n
\n"; foreach ($profile as $key => $val) { @@ -152,10 +149,7 @@ class CI_Profiler { $output .= "\n"; } - $output .= "
".$key."  ".$val."
\n"; - $output .= "
"; - - return $output; + return $output."\n"; } // -------------------------------------------------------------------- @@ -178,19 +172,16 @@ class CI_Profiler { } } - if (count($dbs) == 0) + if (count($dbs) === 0) { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; - $output .= "\n\n\n"; - $output .="\n"; - $output .= "
".$this->CI->lang->line('profiler_no_db')."
\n"; - $output .= "
"; - - return $output; + return "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_queries').'  ' + . "\n\n\n\n" + . '\n
' + . $this->CI->lang->line('profiler_no_db') + . "
\n
"; } // Load the text helper so we can highlight the SQL @@ -205,8 +196,6 @@ class CI_Profiler { 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').')'; @@ -216,13 +205,12 @@ class CI_Profiler { $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).'  '.$show_hide_js.''; - $output .= "\n"; - $output .= "\n\n\n"; + $output .= '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'  '.$show_hide_js.'' + . "\n\n\n
\n"; - if (count($db->queries) == 0) + if (count($db->queries) === 0) { $output .= "\n"; } @@ -243,8 +231,7 @@ class CI_Profiler { } } - $output .= "
".$this->CI->lang->line('profiler_no_queries')."
\n"; - $output .= "
"; + $output .= "\n"; } @@ -261,13 +248,13 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; - $output .= "\n"; + $output = "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_get_data').'  ' + . "\n"; - if (count($_GET) == 0) + if (count($_GET) === 0) { $output .= "
".$this->CI->lang->line('profiler_no_get')."
"; } @@ -282,23 +269,15 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "$_GET[".$key."]   "; - if (is_array($val)) - { - $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; - } - else - { - $output .= htmlspecialchars(stripslashes($val)); - } - $output .= "\n"; + $output .= "$_GET[".$key."]   " + . (is_array($val) ? "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
" : htmlspecialchars(stripslashes($val))) + . "\n"; } $output .= "\n"; } - $output .= "
"; - return $output; + return $output.'
'; } // -------------------------------------------------------------------- @@ -310,11 +289,11 @@ class CI_Profiler { */ protected function _compile_post() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; - $output .= "\n"; + $output = "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_post_data').'  ' + . "\n"; if (count($_POST) == 0) { @@ -345,9 +324,8 @@ class CI_Profiler { $output .= "\n"; } - $output .= "
"; - return $output; + return $output.'
'; } // -------------------------------------------------------------------- @@ -359,24 +337,13 @@ class CI_Profiler { */ protected function _compile_uri_string() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; - $output .= "\n"; - - if ($this->CI->uri->uri_string == '') - { - $output .= "
".$this->CI->lang->line('profiler_no_uri')."
"; - } - else - { - $output .= "
".$this->CI->uri->uri_string."
"; - } - - $output .= "
"; - - return $output; + return "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_uri_string').'  ' + . "\n
" + . ($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) + . '
'; } // -------------------------------------------------------------------- @@ -388,17 +355,12 @@ class CI_Profiler { */ protected function _compile_controller_info() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; - $output .= "\n"; - - $output .= "
".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."
"; - - $output .= "
"; - - return $output; + return "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_controller_info').'  ' + . "\n
".$this->CI->router->fetch_class().'/'.$this->CI->router->fetch_method() + . '
'; } // -------------------------------------------------------------------- @@ -412,24 +374,13 @@ class CI_Profiler { */ protected function _compile_memory_usage() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; - $output .= "\n"; - - if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') - { - $output .= "
".number_format($usage).' bytes
'; - } - else - { - $output .= "
".$this->CI->lang->line('profiler_no_memory')."
"; - } - - $output .= "
"; - - return $output; + return "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_memory_usage').'  ' + . "\n
" + . ((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) + . '
'; } // -------------------------------------------------------------------- @@ -443,13 +394,11 @@ class CI_Profiler { */ protected function _compile_http_headers() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; - $output .= "\n"; - - $output .= "\n\n\n"; + $output = "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')' + . "\n\n\n
\n"; foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) { @@ -457,10 +406,7 @@ class CI_Profiler { $output .= "\n"; } - $output .= "\n"; - $output .= "
"; - - return $output; + return $output."\n"; } // -------------------------------------------------------------------- @@ -474,13 +420,11 @@ class CI_Profiler { */ protected function _compile_config() { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; - $output .= "\n"; - - $output .= "\n\n\n"; + $output = "\n\n" + . '
' + . "\n" + . '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')' + . "\n\n\n
\n"; foreach ($this->CI->config->config as $config=>$val) { @@ -492,10 +436,7 @@ class CI_Profiler { $output .= "\n"; } - $output .= "\n"; - $output .= "
"; - - return $output; + return $output."\n"; } // -------------------------------------------------------------------- @@ -512,9 +453,9 @@ class CI_Profiler { return; } - $output = '
'; - $output .= '  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')'; - $output .= ""; + $output = '
' + . '  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')' + . "
"; foreach ($this->CI->session->all_userdata() as $key => $val) { @@ -526,9 +467,7 @@ class CI_Profiler { $output .= "\n"; } - $output .= ''; - $output .= "
"; - return $output; + return $output."\n"; } // -------------------------------------------------------------------- @@ -553,14 +492,12 @@ class CI_Profiler { } } - if ($fields_displayed == 0) + if ($fields_displayed === 0) { $output .= '

'.$this->CI->lang->line('profiler_no_profiles').'

'; } - $output .= ''; - - return $output; + return $output.''; } } -- cgit v1.2.3-24-g4f1b