Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * CodeIgniter Profiler Class |
| 32 | * |
| 33 | * This class enables you to display benchmark, query, and other data |
| 34 | * in order to help with debugging and optimization. |
| 35 | * |
| 36 | * Note: At some point it would be good to move all the HTML in this class |
| 37 | * into a set of template files in order to allow customization. |
| 38 | * |
| 39 | * @package CodeIgniter |
| 40 | * @subpackage Libraries |
| 41 | * @category Libraries |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 42 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | * @link http://codeigniter.com/user_guide/general/profiling.html |
| 44 | */ |
| 45 | class CI_Profiler { |
| 46 | |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 47 | protected $_available_sections = array( |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 48 | 'benchmarks', |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 49 | 'get', |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 50 | 'memory_usage', |
| 51 | 'post', |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 52 | 'uri_string', |
| 53 | 'controller_info', |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 54 | 'queries', |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 55 | 'http_headers', |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 56 | 'session_data', |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 57 | 'config' |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 58 | ); |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 59 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 60 | protected $_query_toggle_count = 25; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 61 | |
| 62 | protected $CI; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 63 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 64 | // -------------------------------------------------------------------- |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 65 | |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 66 | public function __construct($config = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 67 | { |
| 68 | $this->CI =& get_instance(); |
| 69 | $this->CI->load->language('profiler'); |
| 70 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 71 | if (isset($config['query_toggle_count'])) |
| 72 | { |
| 73 | $this->_query_toggle_count = (int) $config['query_toggle_count']; |
| 74 | unset($config['query_toggle_count']); |
| 75 | } |
| 76 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 77 | // default all sections to display |
| 78 | foreach ($this->_available_sections as $section) |
| 79 | { |
| 80 | if ( ! isset($config[$section])) |
| 81 | { |
| 82 | $this->_compile_{$section} = TRUE; |
| 83 | } |
| 84 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 85 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 86 | $this->set_sections($config); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | // -------------------------------------------------------------------- |
| 90 | |
| 91 | /** |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 92 | * Set Sections |
| 93 | * |
| 94 | * Sets the private _compile_* properties to enable/disable Profiler sections |
| 95 | * |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 96 | * @param mixed |
| 97 | * @return void |
| 98 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 99 | public function set_sections($config) |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 100 | { |
| 101 | foreach ($config as $method => $enable) |
| 102 | { |
| 103 | if (in_array($method, $this->_available_sections)) |
| 104 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 105 | $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 112 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | * Auto Profiler |
| 114 | * |
| 115 | * This function cycles through the entire array of mark points and |
| 116 | * matches any two points that are named identically (ending in "_start" |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 117 | * and "_end" respectively). It then compiles the execution times for |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | * all points and returns it as an array |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 119 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 120 | * @return array |
| 121 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 122 | protected function _compile_benchmarks() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 123 | { |
| 124 | $profile = array(); |
| 125 | foreach ($this->CI->benchmark->marker as $key => $val) |
| 126 | { |
| 127 | // We match the "end" marker so that the list ends |
| 128 | // up in the order that it was defined |
| 129 | if (preg_match("/(.+?)_end/i", $key, $match)) |
| 130 | { |
| 131 | if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) |
| 132 | { |
| 133 | $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); |
| 134 | } |
| 135 | } |
| 136 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | |
| 138 | // Build a table containing the profile data. |
| 139 | // Note: At some point we should turn this into a template that can |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 140 | // be modified. We also might want to make this data available to be logged |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 141 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 142 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 143 | $output .= '<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 144 | $output .= "\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 145 | $output .= '<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks').' </legend>'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 146 | $output .= "\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 147 | $output .= "\n\n<table style='width:100%'>\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 148 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 149 | foreach ($profile as $key => $val) |
| 150 | { |
| 151 | $key = ucwords(str_replace(array('_', '-'), ' ', $key)); |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 152 | $output .= "<tr><td style='padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;'>".$key." </td><td style='padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 153 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 154 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | $output .= "</table>\n"; |
| 156 | $output .= "</fieldset>"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 157 | |
| 158 | return $output; |
| 159 | } |
| 160 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | // -------------------------------------------------------------------- |
| 162 | |
| 163 | /** |
| 164 | * Compile Queries |
| 165 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 167 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 168 | protected function _compile_queries() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | { |
| 170 | $dbs = array(); |
Derek Jones | f0a9b33 | 2009-07-29 14:19:18 +0000 | [diff] [blame] | 171 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | // Let's determine which databases are currently connected to |
| 173 | foreach (get_object_vars($this->CI) as $CI_object) |
| 174 | { |
Derek Jones | f0a9b33 | 2009-07-29 14:19:18 +0000 | [diff] [blame] | 175 | if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') ) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 176 | { |
| 177 | $dbs[] = $CI_object; |
| 178 | } |
| 179 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 180 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 181 | if (count($dbs) == 0) |
| 182 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 183 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 184 | $output .= '<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | $output .= "\n"; |
| 186 | $output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 187 | $output .= "\n"; |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 188 | $output .= "\n\n<table style='border:none; width:100%;'>\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 189 | $output .="<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | $output .= "</table>\n"; |
| 191 | $output .= "</fieldset>"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 192 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | return $output; |
| 194 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 195 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | // Load the text helper so we can highlight the SQL |
| 197 | $this->CI->load->helper('text'); |
| 198 | |
| 199 | // Key words we want bolded |
Greg Aker | 3424bf7 | 2010-09-14 17:53:10 -0500 | [diff] [blame] | 200 | $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', '(', ')'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 202 | $output = "\n\n"; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 203 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 204 | $count = 0; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 205 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 206 | foreach ($dbs as $db) |
| 207 | { |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 208 | $count++; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 209 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 210 | $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 211 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 212 | $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>)'; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 213 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 214 | if ($hide_queries != '') |
| 215 | { |
| 216 | $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>)'; |
| 217 | } |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 218 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
| 220 | $output .= "\n"; |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 221 | $output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database').': '.$db->database.' '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).' '.$show_hide_js.'</legend>'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 222 | $output .= "\n"; |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 223 | $output .= "\n\n<table style='width:100%;{$hide_queries}' id='ci_profiler_queries_db_{$count}'>\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 224 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | if (count($db->queries) == 0) |
| 226 | { |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 227 | $output .= "<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | } |
| 229 | else |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 230 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | foreach ($db->queries as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 232 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | $time = number_format($db->query_times[$key], 4); |
| 234 | |
| 235 | $val = highlight_code($val, ENT_QUOTES); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 236 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | foreach ($highlight as $bold) |
| 238 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 239 | $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 240 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 241 | |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 242 | $output .= "<tr><td style='padding:5px; vertical-align: top;width:1%;color:#900;font-weight:normal;background-color:#ddd;'>".$time." </td><td style='padding:5px; color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 245 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 246 | $output .= "</table>\n"; |
| 247 | $output .= "</fieldset>"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 248 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 250 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | return $output; |
| 252 | } |
| 253 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 254 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | // -------------------------------------------------------------------- |
| 256 | |
| 257 | /** |
| 258 | * Compile $_GET Data |
| 259 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 261 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 262 | protected function _compile_get() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 263 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 264 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 265 | $output .= '<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 266 | $output .= "\n"; |
| 267 | $output .= '<legend style="color:#cd6e00;"> '.$this->CI->lang->line('profiler_get_data').' </legend>'; |
| 268 | $output .= "\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 269 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | if (count($_GET) == 0) |
| 271 | { |
| 272 | $output .= "<div style='color:#cd6e00;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_get')."</div>"; |
| 273 | } |
| 274 | else |
| 275 | { |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 276 | $output .= "\n\n<table style='width:100%; border:none'>\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | foreach ($_GET as $key => $val) |
| 279 | { |
| 280 | if ( ! is_numeric($key)) |
| 281 | { |
| 282 | $key = "'".$key."'"; |
| 283 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 284 | |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 285 | $output .= "<tr><td style='width:50%;color:#000;background-color:#ddd;padding:5px'>$_GET[".$key."] </td><td style='width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;'>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | if (is_array($val)) |
| 287 | { |
| 288 | $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>"; |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | $output .= htmlspecialchars(stripslashes($val)); |
| 293 | } |
| 294 | $output .= "</td></tr>\n"; |
| 295 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 296 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 297 | $output .= "</table>\n"; |
| 298 | } |
| 299 | $output .= "</fieldset>"; |
| 300 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 301 | return $output; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 303 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 305 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | /** |
| 307 | * Compile $_POST Data |
| 308 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 310 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 311 | protected function _compile_post() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 312 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 313 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 314 | $output .= '<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 315 | $output .= "\n"; |
| 316 | $output .= '<legend style="color:#009900;"> '.$this->CI->lang->line('profiler_post_data').' </legend>'; |
| 317 | $output .= "\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 318 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | if (count($_POST) == 0) |
| 320 | { |
| 321 | $output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_post')."</div>"; |
| 322 | } |
| 323 | else |
| 324 | { |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 325 | $output .= "\n\n<table style='width:100%'>\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 326 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | foreach ($_POST as $key => $val) |
| 328 | { |
| 329 | if ( ! is_numeric($key)) |
| 330 | { |
| 331 | $key = "'".$key."'"; |
| 332 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 333 | |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 334 | $output .= "<tr><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>$_POST[".$key."] </td><td style='width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;'>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | if (is_array($val)) |
| 336 | { |
Derek Jones | 511e3d7 | 2010-05-13 09:03:30 -0500 | [diff] [blame] | 337 | $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "</pre>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 338 | } |
| 339 | else |
| 340 | { |
| 341 | $output .= htmlspecialchars(stripslashes($val)); |
| 342 | } |
| 343 | $output .= "</td></tr>\n"; |
| 344 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 345 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | $output .= "</table>\n"; |
| 347 | } |
| 348 | $output .= "</fieldset>"; |
| 349 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 350 | return $output; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 351 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 352 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 353 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 354 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | /** |
| 356 | * Show query string |
| 357 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 359 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 360 | protected function _compile_uri_string() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 361 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 362 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 363 | $output .= '<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 364 | $output .= "\n"; |
| 365 | $output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string').' </legend>'; |
| 366 | $output .= "\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 367 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 368 | if ($this->CI->uri->uri_string == '') |
| 369 | { |
| 370 | $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_uri')."</div>"; |
| 371 | } |
| 372 | else |
| 373 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 374 | $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->uri->uri_string."</div>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 375 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 376 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | $output .= "</fieldset>"; |
| 378 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 379 | return $output; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 383 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 384 | /** |
| 385 | * Show the controller and function that were called |
| 386 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 387 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 388 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 389 | protected function _compile_controller_info() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 390 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 391 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 392 | $output .= '<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 393 | $output .= "\n"; |
| 394 | $output .= '<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info').' </legend>'; |
| 395 | $output .= "\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 397 | $output .= "<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."</div>"; |
| 398 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 399 | $output .= "</fieldset>"; |
| 400 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 401 | return $output; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 402 | } |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 403 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | /** |
| 407 | * Compile memory usage |
| 408 | * |
| 409 | * Display total used memory |
| 410 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 411 | * @return string |
| 412 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 413 | protected function _compile_memory_usage() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 415 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 416 | $output .= '<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 417 | $output .= "\n"; |
| 418 | $output .= '<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage').' </legend>'; |
| 419 | $output .= "\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 420 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 421 | if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') |
| 422 | { |
| 423 | $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage).' bytes</div>'; |
| 424 | } |
| 425 | else |
| 426 | { |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 427 | $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory')."</div>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 429 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | $output .= "</fieldset>"; |
| 431 | |
| 432 | return $output; |
| 433 | } |
| 434 | |
| 435 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 437 | /** |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 438 | * Compile header information |
| 439 | * |
| 440 | * Lists HTTP headers |
| 441 | * |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 442 | * @return string |
| 443 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 444 | protected function _compile_http_headers() |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 445 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 446 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 447 | $output .= '<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 448 | $output .= "\n"; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 449 | $output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_headers').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_httpheaders_table\').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>)</legend>'; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 450 | $output .= "\n"; |
| 451 | |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 452 | $output .= "\n\n<table style='width:100%;display:none' id='ci_profiler_httpheaders_table'>\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 453 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 454 | 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) |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 455 | { |
| 456 | $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 457 | $output .= "<tr><td style='vertical-align: top;width:50%;padding:5px;color:#900;background-color:#ddd;'>".$header." </td><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>".$val."</td></tr>\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | $output .= "</table>\n"; |
| 461 | $output .= "</fieldset>"; |
| 462 | |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 463 | return $output; |
| 464 | } |
| 465 | |
| 466 | // -------------------------------------------------------------------- |
| 467 | |
| 468 | /** |
| 469 | * Compile config information |
| 470 | * |
| 471 | * Lists developer config variables |
| 472 | * |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 473 | * @return string |
| 474 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 475 | protected function _compile_config() |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 476 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 477 | $output = "\n\n"; |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 478 | $output .= '<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 479 | $output .= "\n"; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 480 | $output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_config').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').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>)</legend>'; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 481 | $output .= "\n"; |
| 482 | |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 483 | $output .= "\n\n<table style='width:100%; display:none' id='ci_profiler_config_table'>\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 484 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 485 | foreach ($this->CI->config->config as $config=>$val) |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 486 | { |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 487 | if (is_array($val)) |
| 488 | { |
| 489 | $val = print_r($val, TRUE); |
| 490 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 491 | |
Greg Aker | 3a56398 | 2010-11-18 18:43:03 -0600 | [diff] [blame] | 492 | $output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$config." </td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | $output .= "</table>\n"; |
| 496 | $output .= "</fieldset>"; |
| 497 | |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 498 | return $output; |
| 499 | } |
| 500 | |
| 501 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 502 | |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 503 | /** |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 504 | * Compile session userdata |
| 505 | * |
| 506 | * @return string |
| 507 | */ |
yterajima | 8310c9a | 2011-08-22 07:26:54 +0900 | [diff] [blame] | 508 | protected function _compile_session_data() |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 509 | { |
| 510 | if ( ! isset($this->CI->session)) |
| 511 | { |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | $output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; |
| 516 | $output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_session_data').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_session_data\').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>)</legend>'; |
| 517 | $output .= "<table style='width:100%;display:none' id='ci_profiler_session_data'>"; |
| 518 | |
| 519 | foreach ($this->CI->session->all_userdata() as $key => $val) |
| 520 | { |
Pedro Junior | 7fe625a | 2011-09-05 09:47:09 -0300 | [diff] [blame] | 521 | if (is_array($val) || is_object($val)) |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 522 | { |
| 523 | $val = print_r($val, TRUE); |
| 524 | } |
| 525 | |
| 526 | $output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$key." </td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n"; |
| 527 | } |
| 528 | |
| 529 | $output .= '</table>'; |
| 530 | $output .= "</fieldset>"; |
| 531 | return $output; |
| 532 | } |
| 533 | |
| 534 | // -------------------------------------------------------------------- |
| 535 | |
| 536 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 537 | * Run the Profiler |
| 538 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 539 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 540 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 541 | public function run() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 542 | { |
| 543 | $output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>"; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 544 | $fields_displayed = 0; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 545 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 546 | foreach ($this->_available_sections as $section) |
| 547 | { |
| 548 | if ($this->_compile_{$section} !== FALSE) |
| 549 | { |
| 550 | $func = "_compile_{$section}"; |
| 551 | $output .= $this->{$func}(); |
| 552 | $fields_displayed++; |
| 553 | } |
| 554 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 555 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 556 | if ($fields_displayed == 0) |
| 557 | { |
| 558 | $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee">'.$this->CI->lang->line('profiler_no_profiles').'</p>'; |
| 559 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 560 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | $output .= '</div>'; |
| 562 | |
| 563 | return $output; |
| 564 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | // END CI_Profiler class |
| 568 | |
| 569 | /* End of file Profiler.php */ |
yterajima | 8310c9a | 2011-08-22 07:26:54 +0900 | [diff] [blame] | 570 | /* Location: ./system/libraries/Profiler.php */ |