PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Modifications Since 08/www/events/system/libraries/Profiler.php

https://github.com/holsinger/openfloor
PHP | 213 lines | 114 code | 30 blank | 69 comment | 10 complexity | e85a99c2bdce5b288b88e2283d32031d MD5 | raw file
  1. <?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 Rick Ellis
  9. * @copyright Copyright (c) 2006, EllisLab, Inc.
  10. * @license http://www.codeignitor.com/user_guide/license.html
  11. * @link http://www.codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter Profiler Class
  18. *
  19. * This class enables you to display benchmark, query, and other data
  20. * in order to help with debugging and optimization.
  21. *
  22. * Note: At some point it would be good to move all the HTML in this class
  23. * into a set of template files in order to allow customization.
  24. *
  25. * @package CodeIgniter
  26. * @subpackage Libraries
  27. * @category Libraries
  28. * @author Rick Ellis
  29. * @link http://www.codeigniter.com/user_guide/general/profiling.html
  30. */
  31. class CI_Profiler {
  32. var $CI;
  33. function CI_Profiler()
  34. {
  35. $this->CI =& get_instance();
  36. $this->CI->load->language('profiler');
  37. }
  38. // --------------------------------------------------------------------
  39. /**
  40. * Auto Profiler
  41. *
  42. * This function cycles through the entire array of mark points and
  43. * matches any two points that are named identically (ending in "_start"
  44. * and "_end" respectively). It then compiles the execution times for
  45. * all points and returns it as an array
  46. *
  47. * @access private
  48. * @return array
  49. */
  50. function _compile_benchmarks()
  51. {
  52. $profile = array();
  53. foreach ($this->CI->benchmark->marker as $key => $val)
  54. {
  55. // We match the "end" marker so that the list ends
  56. // up in the order that it was defined
  57. if (preg_match("/(.+?)_end/i", $key, $match))
  58. {
  59. if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start']))
  60. {
  61. $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key);
  62. }
  63. }
  64. }
  65. // Build a table containing the profile data.
  66. // Note: At some point we should turn this into a template that can
  67. // be modified. We also might want to make this data available to be logged
  68. $output = "\n\n";
  69. $output .= '<fieldset style="border:1px solid #990000;padding:6px 10px 10px 10px;margin:0 0 20px 0;background-color:#eee">';
  70. $output .= "\n";
  71. $output .= '<legend style="color:#990000;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_benchmarks').'&nbsp;&nbsp;</legend>';
  72. $output .= "\n";
  73. $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
  74. foreach ($profile as $key => $val)
  75. {
  76. $key = ucwords(str_replace(array('_', '-'), ' ', $key));
  77. $output .= "<tr><td width='50%' style='color:#000;font-weight:bold;background-color:#ddd;'>".$key."&nbsp;&nbsp;</td><td width='50%' style='color:#990000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
  78. }
  79. $output .= "</table>\n";
  80. $output .= "</fieldset>";
  81. return $output;
  82. }
  83. // --------------------------------------------------------------------
  84. /**
  85. * Compile Queries
  86. *
  87. * @access private
  88. * @return string
  89. */
  90. function _compile_queries()
  91. {
  92. $output = "\n\n";
  93. $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
  94. $output .= "\n";
  95. $output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>';
  96. $output .= "\n";
  97. if ( ! class_exists('CI_DB_driver'))
  98. {
  99. $output .= "<div style='color:#0000FF;font-weight:normal;padding:4px 0 0 0;'>".$this->CI->lang->line('profiler_no_db')."</div>";
  100. }
  101. else
  102. {
  103. if (count($this->CI->db->queries) == 0)
  104. {
  105. $output .= "<div style='color:#0000FF;font-weight:normal;padding:4px 0 4px 0;'>".$this->CI->lang->line('profiler_no_queries')."</div>";
  106. }
  107. else
  108. {
  109. foreach ($this->CI->db->queries as $val)
  110. {
  111. $output .= '<div style="padding:3px;margin:12px 0 12px 0;background-color:#ddd;color:#000">';
  112. $output .= htmlspecialchars($val, ENT_QUOTES);
  113. $output .= "</div>\n";
  114. }
  115. }
  116. }
  117. $output .= "</fieldset>";
  118. return $output;
  119. }
  120. // --------------------------------------------------------------------
  121. /**
  122. * Compile $_POST Data
  123. *
  124. * @access private
  125. * @return string
  126. */
  127. function _compile_post()
  128. {
  129. $output = "\n\n";
  130. $output .= '<fieldset style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
  131. $output .= "\n";
  132. $output .= '<legend style="color:#009900;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_post_data').'&nbsp;&nbsp;</legend>';
  133. $output .= "\n";
  134. if (count($_POST) == 0)
  135. {
  136. $output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_post')."</div>";
  137. }
  138. else
  139. {
  140. $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
  141. foreach ($_POST as $key => $val)
  142. {
  143. if ( ! is_numeric($key))
  144. {
  145. $key = "'".$key."'";
  146. }
  147. // $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;'>".htmlspecialchars(stripslashes($val))."</td></tr>\n";
  148. $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;'>";
  149. if (is_array($val))
  150. {
  151. $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
  152. }
  153. else
  154. {
  155. $output .= htmlspecialchars(stripslashes($val));
  156. }
  157. $output .= "</td></tr>\n";
  158. }
  159. $output .= "</table>\n";
  160. }
  161. $output .= "</fieldset>";
  162. return $output;
  163. }
  164. // --------------------------------------------------------------------
  165. /**
  166. * Run the Profiler
  167. *
  168. * @access private
  169. * @return string
  170. */
  171. function run($output = '')
  172. {
  173. $output = '<br clear="all" />';
  174. $output .= "<div style='background-color:#fff;padding:10px;'>";
  175. $output .= $this->_compile_benchmarks();
  176. $output .= $this->_compile_post();
  177. $output .= $this->_compile_queries();
  178. $output .= '</div>';
  179. return $output;
  180. }
  181. }
  182. // END CI_Profiler class
  183. ?>