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 |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, 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 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 78 | /** |
| 79 | * Constructor |
| 80 | * |
| 81 | * Initialize Profiler |
| 82 | * |
| 83 | * @param array $config |
| 84 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 85 | public function __construct($config = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 86 | { |
| 87 | $this->CI =& get_instance(); |
| 88 | $this->CI->load->language('profiler'); |
| 89 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 90 | if (isset($config['query_toggle_count'])) |
| 91 | { |
| 92 | $this->_query_toggle_count = (int) $config['query_toggle_count']; |
| 93 | unset($config['query_toggle_count']); |
| 94 | } |
| 95 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 96 | // default all sections to display |
| 97 | foreach ($this->_available_sections as $section) |
| 98 | { |
| 99 | if ( ! isset($config[$section])) |
| 100 | { |
| 101 | $this->_compile_{$section} = TRUE; |
| 102 | } |
| 103 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 104 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 105 | $this->set_sections($config); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 106 | } |
| 107 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | // -------------------------------------------------------------------- |
| 109 | |
| 110 | /** |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 111 | * Set Sections |
| 112 | * |
| 113 | * Sets the private _compile_* properties to enable/disable Profiler sections |
| 114 | * |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 115 | * @param mixed |
| 116 | * @return void |
| 117 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 118 | public function set_sections($config) |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 119 | { |
Andrey Andreev | 0140ddd | 2012-06-16 01:12:56 +0300 | [diff] [blame] | 120 | if (isset($config['query_toggle_count'])) |
| 121 | { |
| 122 | $this->_query_toggle_count = (int) $config['query_toggle_count']; |
| 123 | unset($config['query_toggle_count']); |
| 124 | } |
| 125 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 126 | foreach ($config as $method => $enable) |
| 127 | { |
| 128 | if (in_array($method, $this->_available_sections)) |
| 129 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 130 | $this->_compile_{$method} = ($enable !== FALSE); |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 136 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 137 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | * Auto Profiler |
| 139 | * |
| 140 | * This function cycles through the entire array of mark points and |
| 141 | * matches any two points that are named identically (ending in "_start" |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 142 | * and "_end" respectively). It then compiles the execution times for |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | * all points and returns it as an array |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 144 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | * @return array |
| 146 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 147 | protected function _compile_benchmarks() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 148 | { |
| 149 | $profile = array(); |
| 150 | foreach ($this->CI->benchmark->marker as $key => $val) |
| 151 | { |
| 152 | // We match the "end" marker so that the list ends |
| 153 | // up in the order that it was defined |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 154 | if (preg_match('/(.+?)_end/i', $key, $match) |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 155 | && 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] | 156 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 157 | $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 158 | } |
| 159 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | |
| 161 | // Build a table containing the profile data. |
| 162 | // 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] | 163 | // 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] | 164 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 165 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 166 | .'<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 167 | ."\n" |
| 168 | .'<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks')." </legend>" |
| 169 | ."\n\n\n<table style=\"width:100%;\">\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 170 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | foreach ($profile as $key => $val) |
| 172 | { |
| 173 | $key = ucwords(str_replace(array('_', '-'), ' ', $key)); |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 174 | $output .= '<tr><td style="padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;">' |
| 175 | .$key.' </td><td style="padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;">' |
| 176 | .$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 177 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 178 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 179 | return $output."</table>\n</fieldset>"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | // -------------------------------------------------------------------- |
| 183 | |
| 184 | /** |
| 185 | * Compile Queries |
| 186 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 187 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 188 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 189 | protected function _compile_queries() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | { |
| 191 | $dbs = array(); |
Derek Jones | f0a9b33 | 2009-07-29 14:19:18 +0000 | [diff] [blame] | 192 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | // Let's determine which databases are currently connected to |
| 194 | foreach (get_object_vars($this->CI) as $CI_object) |
| 195 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 196 | 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] | 197 | { |
| 198 | $dbs[] = $CI_object; |
| 199 | } |
| 200 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 201 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 202 | if (count($dbs) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 204 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 205 | .'<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 206 | ."\n" |
| 207 | .'<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>' |
| 208 | ."\n\n\n<table style=\"border:none; width:100%;\">\n" |
| 209 | .'<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' |
| 210 | .$this->CI->lang->line('profiler_no_db') |
| 211 | ."</td></tr>\n</table>\n</fieldset>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | // Load the text helper so we can highlight the SQL |
| 215 | $this->CI->load->helper('text'); |
| 216 | |
| 217 | // Key words we want bolded |
Greg Aker | 3424bf7 | 2010-09-14 17:53:10 -0500 | [diff] [blame] | 218 | $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] | 219 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 220 | $output = "\n\n"; |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 221 | $count = 0; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 222 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | foreach ($dbs as $db) |
| 224 | { |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 225 | $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 226 | |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 227 | $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] | 228 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 229 | if ($hide_queries !== '') |
Greg Aker | e6e6e64 | 2011-04-18 15:54:13 -0500 | [diff] [blame] | 230 | { |
| 231 | $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>)'; |
| 232 | } |
Razican | c24f49b | 2011-04-25 13:43:57 +0200 | [diff] [blame] | 233 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 234 | $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 235 | ."\n" |
| 236 | .'<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database') |
| 237 | .': '.$db->database.' '.$this->CI->lang->line('profiler_queries') |
| 238 | .': '.count($db->queries).' '.$show_hide_js."</legend>\n\n\n" |
| 239 | .'<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] | 240 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 241 | if (count($db->queries) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 242 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 243 | $output .= '<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' |
| 244 | .$this->CI->lang->line('profiler_no_queries')."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | } |
| 246 | else |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 247 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | foreach ($db->queries as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 249 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | $time = number_format($db->query_times[$key], 4); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | $val = highlight_code($val, ENT_QUOTES); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 252 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | foreach ($highlight as $bold) |
| 254 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 255 | $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 257 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 258 | $output .= '<tr><td style="padding:5px;vertical-align:top;width:1%;color:#900;font-weight:normal;background-color:#ddd;">' |
| 259 | .$time.' </td><td style="padding:5px;color:#000;font-weight:normal;background-color:#ddd;">' |
| 260 | .$val."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 263 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 264 | $output .= "</table>\n</fieldset>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 266 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 267 | return $output; |
| 268 | } |
| 269 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | // -------------------------------------------------------------------- |
| 271 | |
| 272 | /** |
| 273 | * Compile $_GET Data |
| 274 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 276 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 277 | protected function _compile_get() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 278 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 279 | $output = "\n\n" |
| 280 | .'<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 281 | ."\n" |
| 282 | .'<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] | 283 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 284 | if (count($_GET) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 285 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 286 | $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] | 287 | } |
| 288 | else |
| 289 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 290 | $output .= "\n\n<table style=\"width:100%;border:none;\">\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 291 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | foreach ($_GET as $key => $val) |
| 293 | { |
| 294 | if ( ! is_numeric($key)) |
| 295 | { |
| 296 | $key = "'".$key."'"; |
| 297 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 298 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 299 | $output .= '<tr><td style="width:50%;color:#000;background-color:#ddd;padding:5px;">$_GET[' |
| 300 | .$key.'] </td><td style="width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;">' |
| 301 | .((is_array($val) OR is_object($val)) ? '<pre>'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'</pre>' : htmlspecialchars(stripslashes($val))) |
| 302 | ."</td></tr>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 304 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | $output .= "</table>\n"; |
| 306 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 308 | return $output.'</fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 310 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 312 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | /** |
| 314 | * Compile $_POST Data |
| 315 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 317 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 318 | protected function _compile_post() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 319 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 320 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 321 | .'<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 322 | ."\n" |
| 323 | .'<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] | 324 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 325 | if (count($_POST) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 327 | $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] | 328 | } |
| 329 | else |
| 330 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 331 | $output .= "\n\n<table style=\"width:100%;\">\n"; |
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 | foreach ($_POST as $key => $val) |
| 334 | { |
| 335 | if ( ! is_numeric($key)) |
| 336 | { |
| 337 | $key = "'".$key."'"; |
| 338 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 339 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 340 | $output .= '<tr><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">$_POST[' |
| 341 | .$key.'] </td><td style="width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;">'; |
| 342 | |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 343 | if (is_array($val) OR is_object($val)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 345 | $output .= '<pre>'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'</pre>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | } |
| 347 | else |
| 348 | { |
| 349 | $output .= htmlspecialchars(stripslashes($val)); |
| 350 | } |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 351 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 352 | $output .= "</td></tr>\n"; |
| 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 | $output .= "</table>\n"; |
| 356 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 358 | return $output.'</fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 359 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 360 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 362 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 363 | /** |
| 364 | * Show query string |
| 365 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 366 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 367 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 368 | protected function _compile_uri_string() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 369 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 370 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 371 | .'<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 372 | ."\n" |
| 373 | .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string')." </legend>\n" |
| 374 | .'<div style="color:#000;font-weight:normal;padding:4px 0 4px 0;">' |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 375 | .($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] | 376 | .'</div></fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 380 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | /** |
| 382 | * Show the controller and function that were called |
| 383 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 384 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 385 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 386 | protected function _compile_controller_info() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 387 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 388 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 389 | .'<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 390 | ."\n" |
| 391 | .'<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info')." </legend>\n" |
| 392 | .'<div style="color:#995300;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->router->fetch_class().'/'.$this->CI->router->fetch_method() |
| 393 | .'</div></fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 394 | } |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 395 | |
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 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | /** |
| 399 | * Compile memory usage |
| 400 | * |
| 401 | * Display total used memory |
| 402 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | * @return string |
| 404 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 405 | protected function _compile_memory_usage() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 407 | return "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 408 | .'<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 409 | ."\n" |
| 410 | .'<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage')." </legend>\n" |
| 411 | .'<div style="color:#5a0099;font-weight:normal;padding:4px 0 4px 0;">' |
Andrey Andreev | c839d28 | 2012-06-07 14:35:27 +0300 | [diff] [blame] | 412 | .(($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] | 413 | .'</div></fieldset>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 417 | |
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 | * Compile header information |
| 420 | * |
| 421 | * Lists HTTP headers |
| 422 | * |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 423 | * @return string |
| 424 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 425 | protected function _compile_http_headers() |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 426 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 427 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 428 | .'<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 429 | ."\n" |
| 430 | .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_headers') |
| 431 | .' (<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" |
| 432 | .'<table style="width:100%;display:none;" id="ci_profiler_httpheaders_table">'."\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 433 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 434 | 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] | 435 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 436 | $val = isset($_SERVER[$header]) ? $_SERVER[$header] : ''; |
| 437 | $output .= '<tr><td style="vertical-align:top;width:50%;padding:5px;color:#900;background-color:#ddd;">' |
| 438 | .$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] | 439 | } |
| 440 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 441 | return $output."</table>\n</fieldset>"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | // -------------------------------------------------------------------- |
| 445 | |
| 446 | /** |
| 447 | * Compile config information |
| 448 | * |
| 449 | * Lists developer config variables |
| 450 | * |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 451 | * @return string |
| 452 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 453 | protected function _compile_config() |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 454 | { |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 455 | $output = "\n\n" |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 456 | .'<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 457 | ."\n" |
| 458 | .'<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" |
| 459 | .'<table style="width:100%;display:none;" id="ci_profiler_config_table">'."\n"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 460 | |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 461 | foreach ($this->CI->config->config as $config => $val) |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 462 | { |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 463 | if (is_array($val) OR is_object($val)) |
Greg Aker | e602683 | 2010-04-29 13:41:39 -0500 | [diff] [blame] | 464 | { |
| 465 | $val = print_r($val, TRUE); |
| 466 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 467 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 468 | $output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">' |
| 469 | .$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] | 470 | } |
| 471 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 472 | return $output."</table>\n</fieldset>"; |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 476 | |
Derek Allard | 76af409 | 2010-01-16 19:20:49 +0000 | [diff] [blame] | 477 | /** |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 478 | * Compile session userdata |
| 479 | * |
| 480 | * @return string |
| 481 | */ |
yterajima | 8310c9a | 2011-08-22 07:26:54 +0900 | [diff] [blame] | 482 | protected function _compile_session_data() |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 483 | { |
| 484 | if ( ! isset($this->CI->session)) |
| 485 | { |
| 486 | return; |
| 487 | } |
| 488 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 489 | $output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' |
| 490 | .'<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>' |
| 491 | .'<table style="width:100%;display:none;" id="ci_profiler_session_data">'; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 492 | |
| 493 | foreach ($this->CI->session->all_userdata() as $key => $val) |
| 494 | { |
Andrey Andreev | 963386b | 2012-03-02 01:52:01 +0200 | [diff] [blame] | 495 | if (is_array($val) OR is_object($val)) |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 496 | { |
| 497 | $val = print_r($val, TRUE); |
| 498 | } |
| 499 | |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 500 | $output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">' |
| 501 | .$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] | 502 | } |
| 503 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 504 | return $output."</table>\n</fieldset>"; |
Greg Aker | 62df131 | 2011-04-18 11:18:02 -0500 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | // -------------------------------------------------------------------- |
| 508 | |
| 509 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 510 | * Run the Profiler |
| 511 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 513 | */ |
Greg Aker | 5ac5594 | 2010-11-10 14:59:47 -0600 | [diff] [blame] | 514 | public function run() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 516 | $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] | 517 | $fields_displayed = 0; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 518 | |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 519 | foreach ($this->_available_sections as $section) |
| 520 | { |
| 521 | if ($this->_compile_{$section} !== FALSE) |
| 522 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 523 | $func = '_compile_'.$section; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 524 | $output .= $this->{$func}(); |
| 525 | $fields_displayed++; |
| 526 | } |
| 527 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 528 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 529 | if ($fields_displayed === 0) |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 530 | { |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 531 | $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee;">' |
| 532 | .$this->CI->lang->line('profiler_no_profiles').'</p>'; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 533 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 534 | |
Andrey Andreev | 195d311 | 2011-12-25 03:59:13 +0200 | [diff] [blame] | 535 | return $output.'</div>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 536 | } |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 537 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 540 | /* End of file Profiler.php */ |
Andrey Andreev | 0d1c0a7 | 2012-04-03 16:59:54 +0300 | [diff] [blame] | 541 | /* Location: ./system/libraries/Profiler.php */ |