From c2f90e23b62c7155a49e38a2958796e6a886e868 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 3 Apr 2007 11:17:44 +0000 Subject: array to string addition http://codeigniter.com/forums/viewthread/46994/ --- system/libraries/Profiler.php | 414 +++++++++++++++++++++--------------------- 1 file changed, 212 insertions(+), 202 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 5b0f6e2b7..37b345184 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,203 +1,213 @@ -CI =& get_instance(); - $this->CI->load->language('profiler'); - } - - // -------------------------------------------------------------------- - - /** - * Auto Profiler - * - * This function cycles through the entire array of mark points and - * matches any two points that are named identically (ending in "_start" - * and "_end" respectively). It then compiles the execution times for - * all points and returns it as an array - * - * @access private - * @return array - */ - function _compile_benchmarks() - { - $profile = array(); - foreach ($this->CI->benchmark->marker as $key => $val) - { - // We match the "end" marker so that the list ends - // up in the order that it was defined - if (preg_match("/(.+?)_end/i", $key, $match)) - { - 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); - } - } - } - - // Build a table containing the profile data. - // 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"; - - foreach ($profile as $key => $val) - { - $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; - } - - $output .= "
".$key."  ".$val."
\n"; - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile Queries - * - * @access private - * @return string - */ - function _compile_queries() - { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; - - if ( ! class_exists('CI_DB_driver')) - { - $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; - } - else - { - if (count($this->CI->db->queries) == 0) - { - $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; - } - else - { - foreach ($this->CI->db->queries as $val) - { - $output .= '
'; - $output .= $val; - $output .= "
\n"; - } - } - } - - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile $_POST Data - * - * @access private - * @return string - */ - function _compile_post() - { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; - $output .= "\n"; - - if (count($_POST) == 0) - { - $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; - } - else - { - $output .= "\n\n\n"; - - foreach ($_POST as $key => $val) - { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } - - $output .= "\n"; - } - - $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
\n"; - } - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Run the Profiler - * - * @access private - * @return string - */ - function run($output = '') - { - $output = '
'; - $output .= "
"; - - $output .= $this->_compile_benchmarks(); - $output .= $this->_compile_post(); - $output .= $this->_compile_queries(); - - $output .= '
'; - - return $output; - } - -} - -// END CI_Profiler class +CI =& get_instance(); + $this->CI->load->language('profiler'); + } + + // -------------------------------------------------------------------- + + /** + * Auto Profiler + * + * This function cycles through the entire array of mark points and + * matches any two points that are named identically (ending in "_start" + * and "_end" respectively). It then compiles the execution times for + * all points and returns it as an array + * + * @access private + * @return array + */ + function _compile_benchmarks() + { + $profile = array(); + foreach ($this->CI->benchmark->marker as $key => $val) + { + // We match the "end" marker so that the list ends + // up in the order that it was defined + if (preg_match("/(.+?)_end/i", $key, $match)) + { + 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); + } + } + } + + // Build a table containing the profile data. + // 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"; + + foreach ($profile as $key => $val) + { + $key = ucwords(str_replace(array('_', '-'), ' ', $key)); + $output .= "\n"; + } + + $output .= "
".$key."  ".$val."
\n"; + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile Queries + * + * @access private + * @return string + */ + function _compile_queries() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; + $output .= "\n"; + + if ( ! class_exists('CI_DB_driver')) + { + $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; + } + else + { + if (count($this->CI->db->queries) == 0) + { + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; + } + else + { + foreach ($this->CI->db->queries as $val) + { + $output .= '
'; + $output .= $val; + $output .= "
\n"; + } + } + } + + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile $_POST Data + * + * @access private + * @return string + */ + function _compile_post() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; + $output .= "\n"; + + if (count($_POST) == 0) + { + $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; + } + else + { + $output .= "\n\n\n"; + + foreach ($_POST as $key => $val) + { + if ( ! is_numeric($key)) + { + $key = "'".$key."'"; + } + +// $output .= "\n"; + $output .= "\n"; + } + + $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
$_POST[".$key."] "; + if (is_array($val)) + { + $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; + } + else + { + $output .= htmlspecialchars(stripslashes($val)); + } + $output .= "
\n"; + } + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Run the Profiler + * + * @access private + * @return string + */ + function run($output = '') + { + $output = '
'; + $output .= "
"; + + $output .= $this->_compile_benchmarks(); + $output .= $this->_compile_post(); + $output .= $this->_compile_queries(); + + $output .= '
'; + + return $output; + } + +} + +// END CI_Profiler class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b