Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter Profiler Class |
| 42 | * |
| 43 | * This class enables you to display benchmark, query, and other data |
| 44 | * in order to help with debugging and optimization. |
| 45 | * |
| 46 | * Note: At some point it would be good to move all the HTML in this class |
| 47 | * into a set of template files in order to allow customization. |
| 48 | * |
| 49 | * @package CodeIgniter |
| 50 | * @subpackage Libraries |
| 51 | * @category Libraries |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 52 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 53 | * @link https://codeigniter.com/user_guide/general/profiling.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | */ |
| 55 | class CI_Profiler { |
| 56 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 57 | /** |
| 58 | * List of profiler sections available to show |
| 59 | * |
| 60 | * @var array |
| 61 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 62 | protected $_available_sections = array( |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 63 | 'benchmarks', |
| 64 | 'get', |
| 65 | 'memory_usage', |
| 66 | 'post', |
| 67 | 'uri_string', |
| 68 | 'controller_info', |
| 69 | 'queries', |
| 70 | 'http_headers', |
| 71 | 'session_data', |
| 72 | 'config' |
| 73 | ); |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 74 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 75 | /** |
| 76 | * Number of queries to show before making the additional queries togglable |
| 77 | * |
| 78 | * @var int |
| 79 | */ |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 80 | protected $_query_toggle_count = 25; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 81 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 82 | /** |
| 83 | * Reference to the CodeIgniter singleton |
| 84 | * |
| 85 | * @var object |
| 86 | */ |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 87 | protected $CI; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 88 | |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 89 | // -------------------------------------------------------------------- |
| 90 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 91 | /** |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 92 | * Class constructor |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 93 | * |
| 94 | * Initialize Profiler |
| 95 | * |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 96 | * @param array $config Parameters |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 97 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 98 | public function __construct($config = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 99 | { |
| 100 | $this->CI =& get_instance(); |
| 101 | $this->CI->load->language('profiler'); |
| 102 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 103 | // default all sections to display |
| 104 | foreach ($this->_available_sections as $section) |
| 105 | { |
| 106 | if ( ! isset($config[$section])) |
| 107 | { |
| 108 | $this->_compile_{$section} = TRUE; |
| 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 | $this->set_sections($config); |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 113 | log_message('info', 'Profiler Class Initialized'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 114 | } |
| 115 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | // -------------------------------------------------------------------- |
| 117 | |
| 118 | /** |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 119 | * Set Sections |
| 120 | * |
| 121 | * Sets the private _compile_* properties to enable/disable Profiler sections |
| 122 | * |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 123 | * @param mixed $config |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 124 | * @return void |
| 125 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 126 | public function set_sections($config) |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 127 | { |
Andrey Andreev | 0140ddd | 2012-06-16 01:12:56 +0300 | [diff] [blame] | 128 | if (isset($config['query_toggle_count'])) |
| 129 | { |
| 130 | $this->_query_toggle_count = (int) $config['query_toggle_count']; |
| 131 | unset($config['query_toggle_count']); |
| 132 | } |
| 133 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 134 | foreach ($config as $method => $enable) |
| 135 | { |
| 136 | if (in_array($method, $this->_available_sections)) |
| 137 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 138 | $this->_compile_{$method} = ($enable !== FALSE); |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 144 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 145 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | * Auto Profiler |
| 147 | * |
| 148 | * This function cycles through the entire array of mark points and |
| 149 | * matches any two points that are named identically (ending in "_start" |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 150 | * and "_end" respectively). It then compiles the execution times for |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | * all points and returns it as an array |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 152 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 153 | * @return array |
| 154 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 155 | protected function _compile_benchmarks() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 156 | { |
| 157 | $profile = array(); |
| 158 | foreach ($this->CI->benchmark->marker as $key => $val) |
| 159 | { |
| 160 | // We match the "end" marker so that the list ends |
| 161 | // up in the order that it was defined |
Richard Cunningham | 70a8626 | 2014-03-19 13:11:14 -0400 | [diff] [blame] | 162 | if (preg_match('/(.+?)_end$/i', $key, $match) |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 163 | && isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 164 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 165 | $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 166 | } |
| 167 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | |
| 169 | // Build a table containing the profile data. |
| 170 | // Note: At some point we should turn this into a template that can |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 171 | // 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] | 172 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 173 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 174 | .'<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 175 | ."\n" |
| 176 | .'<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks')." </legend>" |
| 177 | ."\n\n\n<table style=\"width:100%;\">\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 178 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | foreach ($profile as $key => $val) |
| 180 | { |
| 181 | $key = ucwords(str_replace(array('_', '-'), ' ', $key)); |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 182 | $output .= '<tr><td style="padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;">' |
| 183 | .$key.' </td><td style="padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;">' |
| 184 | .$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 186 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 187 | return $output."</table>\n</fieldset>"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | // -------------------------------------------------------------------- |
| 191 | |
| 192 | /** |
| 193 | * Compile Queries |
| 194 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 196 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 197 | protected function _compile_queries() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 198 | { |
| 199 | $dbs = array(); |
Derek Jones | f0a9b33 | 2009-07-29 14:19:18 +0000 | [diff] [blame] | 200 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | // Let's determine which databases are currently connected to |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 202 | foreach (get_object_vars($this->CI) as $name => $cobject) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | { |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 204 | if (is_object($cobject)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 205 | { |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 206 | if ($cobject instanceof CI_DB) |
| 207 | { |
| 208 | $dbs[get_class($this->CI).':$'.$name] = $cobject; |
| 209 | } |
| 210 | elseif ($cobject instanceof CI_Model) |
| 211 | { |
| 212 | foreach (get_object_vars($cobject) as $mname => $mobject) |
| 213 | { |
| 214 | if ($mobject instanceof CI_DB) |
| 215 | { |
| 216 | $dbs[get_class($cobject).':$'.$mname] = $mobject; |
| 217 | } |
| 218 | } |
| 219 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | } |
| 221 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 222 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 223 | if (count($dbs) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 225 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 226 | .'<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 227 | ."\n" |
| 228 | .'<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>' |
| 229 | ."\n\n\n<table style=\"border:none; width:100%;\">\n" |
| 230 | .'<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' |
| 231 | .$this->CI->lang->line('profiler_no_db') |
| 232 | ."</td></tr>\n</table>\n</fieldset>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 234 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 235 | // Load the text helper so we can highlight the SQL |
| 236 | $this->CI->load->helper('text'); |
| 237 | |
| 238 | // Key words we want bolded |
Greg Aker | 3424bf7 | 2010-09-14 17:53:10 -0500 | [diff] [blame] | 239 | $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] | 240 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 241 | $output = "\n\n"; |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 242 | $count = 0; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 243 | |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 244 | foreach ($dbs as $name => $db) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | { |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 246 | $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; |
Tim | 3224f07 | 2013-02-14 09:26:24 +0200 | [diff] [blame] | 247 | $total_time = number_format(array_sum($db->query_times), 4).' '.$this->CI->lang->line('profiler_seconds'); |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 248 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 249 | $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] | 250 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 251 | if ($hide_queries !== '') |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 252 | { |
| 253 | $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>)'; |
| 254 | } |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 255 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 256 | $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 257 | ."\n" |
| 258 | .'<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database') |
Andrey Andreev | 55a8c62 | 2012-11-06 13:31:21 +0200 | [diff] [blame] | 259 | .': '.$db->database.' ('.$name.') '.$this->CI->lang->line('profiler_queries') |
Andrey Andreev | a107a0f | 2013-02-15 22:30:31 +0200 | [diff] [blame] | 260 | .': '.count($db->queries).' ('.$total_time.') '.$show_hide_js."</legend>\n\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 261 | .'<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] | 262 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 263 | if (count($db->queries) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 265 | $output .= '<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' |
| 266 | .$this->CI->lang->line('profiler_no_queries')."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 267 | } |
| 268 | else |
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 | foreach ($db->queries as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 271 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | $time = number_format($db->query_times[$key], 4); |
Rasmus Lerdorf | 164a1f2 | 2013-05-18 10:29:56 -0400 | [diff] [blame] | 273 | $val = highlight_code($val); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 274 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | foreach ($highlight as $bold) |
| 276 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 279 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 280 | $output .= '<tr><td style="padding:5px;vertical-align:top;width:1%;color:#900;font-weight:normal;background-color:#ddd;">' |
| 281 | .$time.' </td><td style="padding:5px;color:#000;font-weight:normal;background-color:#ddd;">' |
| 282 | .$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | } |
| 284 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 285 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 286 | $output .= "</table>\n</fieldset>"; |
Cristian Riffo Huez | 0612e92 | 2013-12-13 22:09:44 -0300 | [diff] [blame] | 287 | $count++; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 289 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | return $output; |
| 291 | } |
| 292 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 293 | // -------------------------------------------------------------------- |
| 294 | |
| 295 | /** |
| 296 | * Compile $_GET Data |
| 297 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 299 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 300 | protected function _compile_get() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 301 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 302 | $output = "\n\n" |
| 303 | .'<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 304 | ."\n" |
| 305 | .'<legend style="color:#cd6e00;"> '.$this->CI->lang->line('profiler_get_data')." </legend>\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 307 | if (count($_GET) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 309 | $output .= '<div style="color:#cd6e00;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_get').'</div>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | } |
| 311 | else |
| 312 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 313 | $output .= "\n\n<table style=\"width:100%;border:none;\">\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 314 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 315 | foreach ($_GET as $key => $val) |
| 316 | { |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 317 | is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'"; |
| 318 | $val = (is_array($val) OR is_object($val)) |
Andrey Andreev | cd8d528 | 2017-01-23 11:42:47 +0200 | [diff] [blame] | 319 | ? '<pre>'.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'</pre>' |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 320 | : htmlspecialchars($val, ENT_QUOTES, config_item('charset')); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 321 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 322 | $output .= '<tr><td style="width:50%;color:#000;background-color:#ddd;padding:5px;">$_GET[' |
| 323 | .$key.'] </td><td style="width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;">' |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 324 | .$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | } |
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 | $output .= "</table>\n"; |
| 328 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 330 | return $output.'</fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 331 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 332 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 334 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | /** |
| 336 | * Compile $_POST Data |
| 337 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 338 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 339 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 340 | protected function _compile_post() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 341 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 342 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 343 | .'<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 344 | ."\n" |
| 345 | .'<legend style="color:#009900;"> '.$this->CI->lang->line('profiler_post_data')." </legend>\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 346 | |
David Cox Jr | abcb67c | 2013-10-16 14:43:52 -0400 | [diff] [blame] | 347 | if (count($_POST) === 0 && count($_FILES) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 348 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 349 | $output .= '<div style="color:#009900;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_post').'</div>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 350 | } |
| 351 | else |
| 352 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 353 | $output .= "\n\n<table style=\"width:100%;\">\n"; |
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 | foreach ($_POST as $key => $val) |
| 356 | { |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 357 | is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'"; |
| 358 | $val = (is_array($val) OR is_object($val)) |
Andrey Andreev | cd8d528 | 2017-01-23 11:42:47 +0200 | [diff] [blame] | 359 | ? '<pre>'.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'</pre>' |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 360 | : htmlspecialchars($val, ENT_QUOTES, config_item('charset')); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 361 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 362 | $output .= '<tr><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">$_POST[' |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 363 | .$key.'] </td><td style="width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;">' |
| 364 | .$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 366 | |
David Cox Jr | 06fa739 | 2013-09-25 01:56:10 -0400 | [diff] [blame] | 367 | foreach ($_FILES as $key => $val) |
| 368 | { |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 369 | is_int($key) OR $key = "'".htmlspecialchars($key, ENT_QUOTES, config_item('charset'))."'"; |
| 370 | $val = (is_array($val) OR is_object($val)) |
Andrey Andreev | cd8d528 | 2017-01-23 11:42:47 +0200 | [diff] [blame] | 371 | ? '<pre>'.htmlspecialchars(print_r($val, TRUE), ENT_QUOTES, config_item('charset')).'</pre>' |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 372 | : htmlspecialchars($val, ENT_QUOTES, config_item('charset')); |
David Cox Jr | 06fa739 | 2013-09-25 01:56:10 -0400 | [diff] [blame] | 373 | |
| 374 | $output .= '<tr><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">$_FILES[' |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 375 | .$key.'] </td><td style="width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;">' |
| 376 | .$val."</td></tr>\n"; |
David Cox Jr | 06fa739 | 2013-09-25 01:56:10 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 379 | $output .= "</table>\n"; |
| 380 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 382 | return $output.'</fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 384 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 386 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 387 | /** |
| 388 | * Show query string |
| 389 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 390 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 391 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 392 | protected function _compile_uri_string() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 393 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 394 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 395 | .'<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 396 | ."\n" |
| 397 | .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string')." </legend>\n" |
| 398 | .'<div style="color:#000;font-weight:normal;padding:4px 0 4px 0;">' |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 399 | .($this->CI->uri->uri_string === '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 400 | .'</div></fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 404 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 405 | /** |
| 406 | * Show the controller and function that were called |
| 407 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 408 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 409 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 410 | protected function _compile_controller_info() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 411 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 412 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 413 | .'<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 414 | ."\n" |
| 415 | .'<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info')." </legend>\n" |
Andrey Andreev | 0e4237f | 2013-04-04 16:53:21 +0300 | [diff] [blame] | 416 | .'<div style="color:#995300;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->router->class.'/'.$this->CI->router->method |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 417 | .'</div></fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 418 | } |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 419 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 420 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 421 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 422 | /** |
| 423 | * Compile memory usage |
| 424 | * |
| 425 | * Display total used memory |
| 426 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 427 | * @return string |
| 428 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 429 | protected function _compile_memory_usage() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 431 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 432 | .'<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 433 | ."\n" |
| 434 | .'<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage')." </legend>\n" |
| 435 | .'<div style="color:#5a0099;font-weight:normal;padding:4px 0 4px 0;">' |
Andrey Andreev | c839d28 | 2012-06-07 14:35:27 +0300 | [diff] [blame] | 436 | .(($usage = memory_get_usage()) != '' ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 437 | .'</div></fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 441 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | /** |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 443 | * Compile header information |
| 444 | * |
| 445 | * Lists HTTP headers |
| 446 | * |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 447 | * @return string |
| 448 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 449 | protected function _compile_http_headers() |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 450 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 451 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 452 | .'<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 453 | ."\n" |
| 454 | .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_headers') |
| 455 | .' (<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>\n\n\n" |
| 456 | .'<table style="width:100%;display:none;" id="ci_profiler_httpheaders_table">'."\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 457 | |
Iacami | 7c72cfc | 2013-06-27 12:20:48 -0300 | [diff] [blame] | 458 | 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', 'HTTP_DNT') as $header) |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 459 | { |
Andrey Andreev | e6a5f79 | 2016-03-07 11:34:43 +0200 | [diff] [blame] | 460 | $val = isset($_SERVER[$header]) ? htmlspecialchars($_SERVER[$header], ENT_QUOTES, config_item('charset')) : ''; |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 461 | $output .= '<tr><td style="vertical-align:top;width:50%;padding:5px;color:#900;background-color:#ddd;">' |
| 462 | .$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] | 463 | } |
| 464 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 465 | return $output."</table>\n</fieldset>"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | // -------------------------------------------------------------------- |
| 469 | |
| 470 | /** |
| 471 | * Compile config information |
| 472 | * |
| 473 | * Lists developer config variables |
| 474 | * |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 475 | * @return string |
| 476 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 477 | protected function _compile_config() |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 478 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 479 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 480 | .'<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 481 | ."\n" |
| 482 | .'<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>\n\n\n" |
| 483 | .'<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 | |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 485 | foreach ($this->CI->config->config as $config => $val) |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 486 | { |
Andrey Andreev | 9c068a1 | 2017-07-10 14:40:06 +0300 | [diff] [blame] | 487 | $pre = ''; |
| 488 | $pre_close = ''; |
| 489 | |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 490 | if (is_array($val) OR is_object($val)) |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 491 | { |
| 492 | $val = print_r($val, TRUE); |
Andrey Andreev | 9c068a1 | 2017-07-10 14:40:06 +0300 | [diff] [blame] | 493 | |
| 494 | $pre = '<pre>' ; |
| 495 | $pre_close = '</pre>'; |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 496 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 497 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 498 | $output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">' |
Andrey Andreev | 9c068a1 | 2017-07-10 14:40:06 +0300 | [diff] [blame] | 499 | .$config.' </td><td style="padding:5px;color:#000;background-color:#ddd;">'.$pre.htmlspecialchars($val, ENT_QUOTES, config_item('charset')).$pre_close."</td></tr>\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 502 | return $output."</table>\n</fieldset>"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 506 | |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 507 | /** |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 508 | * Compile session userdata |
| 509 | * |
| 510 | * @return string |
| 511 | */ |
yterajima | 8310c9a | 2011-08-22 07:26:54 +0900 | [diff] [blame] | 512 | protected function _compile_session_data() |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 513 | { |
| 514 | if ( ! isset($this->CI->session)) |
| 515 | { |
| 516 | return; |
| 517 | } |
| 518 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 519 | $output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 520 | .'<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>' |
| 521 | .'<table style="width:100%;display:none;" id="ci_profiler_session_data">'; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 522 | |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 523 | foreach ($this->CI->session->userdata() as $key => $val) |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 524 | { |
Andrey Andreev | 9c068a1 | 2017-07-10 14:40:06 +0300 | [diff] [blame] | 525 | $pre = ''; |
| 526 | $pre_close = ''; |
| 527 | |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 528 | if (is_array($val) OR is_object($val)) |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 529 | { |
| 530 | $val = print_r($val, TRUE); |
Andrey Andreev | 9c068a1 | 2017-07-10 14:40:06 +0300 | [diff] [blame] | 531 | |
| 532 | $pre = '<pre>' ; |
| 533 | $pre_close = '</pre>'; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 534 | } |
| 535 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 536 | $output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">' |
Andrey Andreev | 9c068a1 | 2017-07-10 14:40:06 +0300 | [diff] [blame] | 537 | .$key.' </td><td style="padding:5px;color:#000;background-color:#ddd;">'.$pre.htmlspecialchars($val, ENT_QUOTES, config_item('charset')).$pre_close."</td></tr>\n"; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 538 | } |
| 539 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 540 | return $output."</table>\n</fieldset>"; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | // -------------------------------------------------------------------- |
| 544 | |
| 545 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 546 | * Run the Profiler |
| 547 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 548 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 549 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 550 | public function run() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 552 | $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] | 553 | $fields_displayed = 0; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 554 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 555 | foreach ($this->_available_sections as $section) |
| 556 | { |
| 557 | if ($this->_compile_{$section} !== FALSE) |
| 558 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 559 | $func = '_compile_'.$section; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 560 | $output .= $this->{$func}(); |
| 561 | $fields_displayed++; |
| 562 | } |
| 563 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 565 | if ($fields_displayed === 0) |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 566 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 567 | $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee;">' |
| 568 | .$this->CI->lang->line('profiler_no_profiles').'</p>'; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 569 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 570 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 571 | return $output.'</div>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 572 | } |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 573 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 574 | } |