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