blob: 796db2d6b08dbbf50385f458af866afba0307470 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @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 */
33class CI_Profiler {
34
35 var $CI;
Barry Mienydd671972010-10-04 16:33:58 +020036
Derek Jonesee71c802010-03-10 10:05:05 -060037 var $_available_sections = array(
38 'benchmarks',
Derek Jonesee71c802010-03-10 10:05:05 -060039 'get',
Derek Jonesee71c802010-03-10 10:05:05 -060040 'memory_usage',
41 'post',
Greg Akere6026832010-04-29 13:41:39 -050042 'uri_string',
43 'controller_info',
Derek Jonesee71c802010-03-10 10:05:05 -060044 'queries',
Greg Akere6026832010-04-29 13:41:39 -050045 'http_headers',
46 'config'
Derek Jonesee71c802010-03-10 10:05:05 -060047 );
48
Barry Mienydd671972010-10-04 16:33:58 +020049 function CI_Profiler($config = array())
50 {
51 $this->CI =& get_instance();
52 $this->CI->load->language('profiler');
53
Derek Jonesee71c802010-03-10 10:05:05 -060054 // default all sections to display
55 foreach ($this->_available_sections as $section)
56 {
57 if ( ! isset($config[$section]))
58 {
59 $this->_compile_{$section} = TRUE;
60 }
61 }
Barry Mienydd671972010-10-04 16:33:58 +020062
Derek Jonesee71c802010-03-10 10:05:05 -060063 $this->set_sections($config);
Barry Mienydd671972010-10-04 16:33:58 +020064 }
65
Derek Allard2067d1a2008-11-13 22:59:24 +000066 // --------------------------------------------------------------------
67
68 /**
Derek Jonesee71c802010-03-10 10:05:05 -060069 * Set Sections
70 *
71 * Sets the private _compile_* properties to enable/disable Profiler sections
72 *
73 * @access public
74 * @param mixed
75 * @return void
76 */
77 function set_sections($config)
78 {
79 foreach ($config as $method => $enable)
80 {
81 if (in_array($method, $this->_available_sections))
82 {
Barry Mienydd671972010-10-04 16:33:58 +020083 $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE;
Derek Jonesee71c802010-03-10 10:05:05 -060084 }
85 }
86 }
87
88 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020089
Derek Jonesee71c802010-03-10 10:05:05 -060090 /**
Derek Allard2067d1a2008-11-13 22:59:24 +000091 * Auto Profiler
92 *
93 * This function cycles through the entire array of mark points and
94 * matches any two points that are named identically (ending in "_start"
95 * and "_end" respectively). It then compiles the execution times for
96 * all points and returns it as an array
Derek Jonesee71c802010-03-10 10:05:05 -060097 * @PHP4 - all methods should be declared private
Derek Allard2067d1a2008-11-13 22:59:24 +000098 * @access private
99 * @return array
100 */
Barry Mienydd671972010-10-04 16:33:58 +0200101 function _compile_benchmarks()
102 {
103 $profile = array();
104 foreach ($this->CI->benchmark->marker as $key => $val)
105 {
106 // We match the "end" marker so that the list ends
107 // up in the order that it was defined
108 if (preg_match("/(.+?)_end/i", $key, $match))
109 {
110 if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start']))
111 {
112 $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key);
113 }
114 }
115 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000116
117 // Build a table containing the profile data.
118 // Note: At some point we should turn this into a template that can
119 // be modified. We also might want to make this data available to be logged
Barry Mienydd671972010-10-04 16:33:58 +0200120
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 $output = "\n\n";
Derek Allard76af4092010-01-16 19:20:49 +0000122 $output .= '<fieldset style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 $output .= "\n";
Derek Allard76af4092010-01-16 19:20:49 +0000124 $output .= '<legend style="color:#900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_benchmarks').'&nbsp;&nbsp;</legend>';
Barry Mienydd671972010-10-04 16:33:58 +0200125 $output .= "\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
Barry Mienydd671972010-10-04 16:33:58 +0200127
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 foreach ($profile as $key => $val)
129 {
130 $key = ucwords(str_replace(array('_', '-'), ' ', $key));
Greg Akerc2950702010-09-14 17:52:26 -0500131 $output .= "<tr><td style='width:50%;color:#000;font-weight:bold;background-color:#ddd;'>".$key."&nbsp;&nbsp;</td><td style='width:50%;color:#900;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 }
Barry Mienydd671972010-10-04 16:33:58 +0200133
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 $output .= "</table>\n";
135 $output .= "</fieldset>";
Barry Mienydd671972010-10-04 16:33:58 +0200136
137 return $output;
138 }
139
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 // --------------------------------------------------------------------
141
142 /**
143 * Compile Queries
144 *
145 * @access private
146 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200147 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 function _compile_queries()
149 {
150 $dbs = array();
Derek Jonesf0a9b332009-07-29 14:19:18 +0000151
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 // Let's determine which databases are currently connected to
153 foreach (get_object_vars($this->CI) as $CI_object)
154 {
Derek Jonesf0a9b332009-07-29 14:19:18 +0000155 if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') )
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 {
157 $dbs[] = $CI_object;
158 }
159 }
Barry Mienydd671972010-10-04 16:33:58 +0200160
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 if (count($dbs) == 0)
162 {
163 $output = "\n\n";
164 $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
165 $output .= "\n";
166 $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>';
Barry Mienydd671972010-10-04 16:33:58 +0200167 $output .= "\n";
Greg Akerc2950702010-09-14 17:52:26 -0500168 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' style='width:100%'>\n";
169 $output .="<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 $output .= "</table>\n";
171 $output .= "</fieldset>";
Barry Mienydd671972010-10-04 16:33:58 +0200172
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 return $output;
174 }
Barry Mienydd671972010-10-04 16:33:58 +0200175
Derek Allard2067d1a2008-11-13 22:59:24 +0000176 // Load the text helper so we can highlight the SQL
177 $this->CI->load->helper('text');
178
179 // Key words we want bolded
Greg Aker3424bf72010-09-14 17:53:10 -0500180 $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT&nbsp;JOIN', 'ORDER&nbsp;BY', 'GROUP&nbsp;BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR&nbsp;', 'HAVING', 'OFFSET', 'NOT&nbsp;IN', 'IN', 'LIKE', 'NOT&nbsp;LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')');
Derek Allard2067d1a2008-11-13 22:59:24 +0000181
182 $output = "\n\n";
Barry Mienydd671972010-10-04 16:33:58 +0200183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 foreach ($dbs as $db)
185 {
186 $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
187 $output .= "\n";
188 $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database').':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'&nbsp;&nbsp;&nbsp;</legend>';
Barry Mienydd671972010-10-04 16:33:58 +0200189 $output .= "\n";
Greg Akerc2950702010-09-14 17:52:26 -0500190 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' style='width:100%;'>\n";
Barry Mienydd671972010-10-04 16:33:58 +0200191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 if (count($db->queries) == 0)
193 {
Greg Akerc2950702010-09-14 17:52:26 -0500194 $output .= "<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 }
196 else
Barry Mienydd671972010-10-04 16:33:58 +0200197 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 foreach ($db->queries as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200199 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 $time = number_format($db->query_times[$key], 4);
201
202 $val = highlight_code($val, ENT_QUOTES);
Barry Mienydd671972010-10-04 16:33:58 +0200203
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 foreach ($highlight as $bold)
205 {
Barry Mienydd671972010-10-04 16:33:58 +0200206 $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 }
Barry Mienydd671972010-10-04 16:33:58 +0200208
Greg Akerc2950702010-09-14 17:52:26 -0500209 $output .= "<tr><td valign='top' style='width:1%;color:#900;font-weight:normal;background-color:#ddd;'>".$time."&nbsp;&nbsp;</td><td style='color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 }
211 }
Barry Mienydd671972010-10-04 16:33:58 +0200212
Derek Allard2067d1a2008-11-13 22:59:24 +0000213 $output .= "</table>\n";
214 $output .= "</fieldset>";
Barry Mienydd671972010-10-04 16:33:58 +0200215
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 }
Barry Mienydd671972010-10-04 16:33:58 +0200217
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 return $output;
219 }
220
Barry Mienydd671972010-10-04 16:33:58 +0200221
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 // --------------------------------------------------------------------
223
224 /**
225 * Compile $_GET Data
226 *
227 * @access private
228 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200229 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 function _compile_get()
Barry Mienydd671972010-10-04 16:33:58 +0200231 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 $output = "\n\n";
233 $output .= '<fieldset style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
234 $output .= "\n";
235 $output .= '<legend style="color:#cd6e00;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_get_data').'&nbsp;&nbsp;</legend>';
236 $output .= "\n";
Barry Mienydd671972010-10-04 16:33:58 +0200237
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 if (count($_GET) == 0)
239 {
240 $output .= "<div style='color:#cd6e00;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_get')."</div>";
241 }
242 else
243 {
244 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
Barry Mienydd671972010-10-04 16:33:58 +0200245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 foreach ($_GET as $key => $val)
247 {
248 if ( ! is_numeric($key))
249 {
250 $key = "'".$key."'";
251 }
Barry Mienydd671972010-10-04 16:33:58 +0200252
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>&#36;_GET[".$key."]&nbsp;&nbsp; </td><td width='50%' style='color:#cd6e00;font-weight:normal;background-color:#ddd;'>";
254 if (is_array($val))
255 {
256 $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
257 }
258 else
259 {
260 $output .= htmlspecialchars(stripslashes($val));
261 }
262 $output .= "</td></tr>\n";
263 }
Barry Mienydd671972010-10-04 16:33:58 +0200264
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 $output .= "</table>\n";
266 }
267 $output .= "</fieldset>";
268
Barry Mienydd671972010-10-04 16:33:58 +0200269 return $output;
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 }
Barry Mienydd671972010-10-04 16:33:58 +0200271
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 /**
275 * Compile $_POST Data
276 *
277 * @access private
278 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200279 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 function _compile_post()
Barry Mienydd671972010-10-04 16:33:58 +0200281 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 $output = "\n\n";
283 $output .= '<fieldset style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
284 $output .= "\n";
285 $output .= '<legend style="color:#009900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_post_data').'&nbsp;&nbsp;</legend>';
286 $output .= "\n";
Barry Mienydd671972010-10-04 16:33:58 +0200287
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 if (count($_POST) == 0)
289 {
290 $output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_post')."</div>";
291 }
292 else
293 {
294 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
Barry Mienydd671972010-10-04 16:33:58 +0200295
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 foreach ($_POST as $key => $val)
297 {
298 if ( ! is_numeric($key))
299 {
300 $key = "'".$key."'";
301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>&#36;_POST[".$key."]&nbsp;&nbsp; </td><td width='50%' style='color:#009900;font-weight:normal;background-color:#ddd;'>";
304 if (is_array($val))
305 {
Derek Jones511e3d72010-05-13 09:03:30 -0500306 $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 }
308 else
309 {
310 $output .= htmlspecialchars(stripslashes($val));
311 }
312 $output .= "</td></tr>\n";
313 }
Barry Mienydd671972010-10-04 16:33:58 +0200314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 $output .= "</table>\n";
316 }
317 $output .= "</fieldset>";
318
Barry Mienydd671972010-10-04 16:33:58 +0200319 return $output;
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 }
Barry Mienydd671972010-10-04 16:33:58 +0200321
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 /**
325 * Show query string
326 *
327 * @access private
328 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200329 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 function _compile_uri_string()
Barry Mienydd671972010-10-04 16:33:58 +0200331 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 $output = "\n\n";
333 $output .= '<fieldset style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
334 $output .= "\n";
335 $output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_uri_string').'&nbsp;&nbsp;</legend>';
336 $output .= "\n";
Barry Mienydd671972010-10-04 16:33:58 +0200337
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 if ($this->CI->uri->uri_string == '')
339 {
340 $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_uri')."</div>";
341 }
342 else
343 {
Barry Mienydd671972010-10-04 16:33:58 +0200344 $output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->uri->uri_string."</div>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 }
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 $output .= "</fieldset>";
348
Barry Mienydd671972010-10-04 16:33:58 +0200349 return $output;
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 }
351
352 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200353
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 /**
355 * Show the controller and function that were called
356 *
357 * @access private
358 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200359 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 function _compile_controller_info()
Barry Mienydd671972010-10-04 16:33:58 +0200361 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 $output = "\n\n";
363 $output .= '<fieldset style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
364 $output .= "\n";
365 $output .= '<legend style="color:#995300;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_controller_info').'&nbsp;&nbsp;</legend>';
366 $output .= "\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000367
Barry Mienydd671972010-10-04 16:33:58 +0200368 $output .= "<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."</div>";
369
370
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 $output .= "</fieldset>";
372
Barry Mienydd671972010-10-04 16:33:58 +0200373 return $output;
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 }
Derek Allard76af4092010-01-16 19:20:49 +0000375
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200377
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 /**
379 * Compile memory usage
380 *
381 * Display total used memory
382 *
383 * @access public
384 * @return string
385 */
386 function _compile_memory_usage()
387 {
388 $output = "\n\n";
389 $output .= '<fieldset style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
390 $output .= "\n";
391 $output .= '<legend style="color:#5a0099;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_memory_usage').'&nbsp;&nbsp;</legend>';
392 $output .= "\n";
Barry Mienydd671972010-10-04 16:33:58 +0200393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '')
395 {
396 $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage).' bytes</div>';
397 }
398 else
399 {
Barry Mienydd671972010-10-04 16:33:58 +0200400 $output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory_usage')."</div>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 }
Barry Mienydd671972010-10-04 16:33:58 +0200402
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 $output .= "</fieldset>";
404
405 return $output;
406 }
407
408 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200409
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 /**
Derek Allard76af4092010-01-16 19:20:49 +0000411 * Compile header information
412 *
413 * Lists HTTP headers
414 *
415 * @access public
416 * @return string
417 */
418 function _compile_http_headers()
419 {
420 $output = "\n\n";
421 $output .= '<fieldset style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
422 $output .= "\n";
423 $output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_headers').'&nbsp;&nbsp;</legend>';
424 $output .= "\n";
425
426 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
427
Derek Jones079303e2010-03-02 18:16:23 -0600428 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 Allard76af4092010-01-16 19:20:49 +0000429 {
430 $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : '';
431 $output .= "<tr><td valign='top' style='color:#900;background-color:#ddd;'>".$header."&nbsp;&nbsp;</td><td style='color:#000;background-color:#ddd;'>".$val."</td></tr>\n";
432 }
433
434 $output .= "</table>\n";
435 $output .= "</fieldset>";
436
Derek Allard76af4092010-01-16 19:20:49 +0000437 return $output;
438 }
439
440 // --------------------------------------------------------------------
441
442 /**
443 * Compile config information
444 *
445 * Lists developer config variables
446 *
447 * @access public
448 * @return string
449 */
450 function _compile_config()
451 {
452 $output = "\n\n";
453 $output .= '<fieldset style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
454 $output .= "\n";
455 $output .= '<legend style="color:#000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_config').'&nbsp;&nbsp;</legend>';
456 $output .= "\n";
457
458 $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
459
460 foreach($this->CI->config->config as $config=>$val)
461 {
Greg Akere6026832010-04-29 13:41:39 -0500462 if (is_array($val))
463 {
464 $val = print_r($val, TRUE);
465 }
Barry Mienydd671972010-10-04 16:33:58 +0200466
Derek Jones511e3d72010-05-13 09:03:30 -0500467 $output .= "<tr><td valign='top' style='color:#900;background-color:#ddd;'>".$config."&nbsp;&nbsp;</td><td style='color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n";
Derek Allard76af4092010-01-16 19:20:49 +0000468 }
469
470 $output .= "</table>\n";
471 $output .= "</fieldset>";
472
Derek Allard76af4092010-01-16 19:20:49 +0000473 return $output;
474 }
475
476 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200477
Derek Allard76af4092010-01-16 19:20:49 +0000478 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 * Run the Profiler
480 *
481 * @access private
482 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200483 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 function run()
485 {
486 $output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>";
Derek Jonesee71c802010-03-10 10:05:05 -0600487 $fields_displayed = 0;
Barry Mienydd671972010-10-04 16:33:58 +0200488
Derek Jonesee71c802010-03-10 10:05:05 -0600489 foreach ($this->_available_sections as $section)
490 {
491 if ($this->_compile_{$section} !== FALSE)
492 {
493 $func = "_compile_{$section}";
494 $output .= $this->{$func}();
495 $fields_displayed++;
496 }
497 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000498
Derek Jonesee71c802010-03-10 10:05:05 -0600499 if ($fields_displayed == 0)
500 {
501 $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee">'.$this->CI->lang->line('profiler_no_profiles').'</p>';
502 }
Barry Mienydd671972010-10-04 16:33:58 +0200503
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 $output .= '</div>';
505
506 return $output;
507 }
508
509}
510
511// END CI_Profiler class
512
513/* End of file Profiler.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000514/* Location: ./system/libraries/Profiler.php */