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