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