Changeset 658 for trunk/system/libraries/Profiler.php
- Timestamp:
- 10/05/2007 01:15:08 AM (14 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/Profiler.php (modified) (3 diffs, 3 props)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Profiler.php
- Property svn:copyright set to Copyright (c) 2007 Kohana Team
- Property svn:eol-style set to LF
- Property svn:keywords set to Id
r654 r658 12 12 * @since Version 2.0 13 13 * @filesource 14 * 15 * $Id$ 14 16 */ 15 17 … … 26 28 * @link http://kohanaphp.com/user_guide/general/profiling.html 27 29 */ 30 class Profiler_Core { 28 31 29 class Profiler_Core 30 { 32 public function __construct() 33 { 34 // Add profiler to page output automatically 35 Event::add('system.output', array($this, 'render')); 31 36 32 private $core; 33 34 public function __construct() 35 { 36 // Add profiler to page output automatically 37 Event::add('system.output', array($this, 'render')); 38 39 $this->core = Kohana::instance(); 40 41 Log::add('debug', 'Profiler initialized'); 42 } 37 Log::add('debug', 'Profiler Library initialized'); 38 } 43 39 44 40 /** … … 50 46 public function render() 51 47 { 52 // Get list of benchmarks 53 $benchmarks = Benchmark::get_all(); 48 $data = array 49 ( 50 'benchmarks' => array(), 51 'queries' => FALSE 52 ); 54 53 55 54 // Clean unique id from system benchmark names 56 $renamed_bm = array(); 57 foreach ($benchmarks as $name => $time) 55 foreach (Benchmark::get_all() as $name => $time) 58 56 { 59 $name = str_replace(SYSTEM_BENCHMARK.'_', '', $name); 60 $renamed_bm[$name] = $time; 57 $data['benchmarks'][str_replace(SYSTEM_BENCHMARK.'_', '', $name)] = $time; 61 58 } 62 59 63 $data['benchmarks'] = $renamed_bm;64 65 60 // Get database queries 66 $data['db_exists'] = FALSE; 67 $data['queries'] = array(); 68 if (isset($this->core->db)) 61 if (isset(Kohana::instance()->db)) 69 62 { 70 $data['db_exists'] = TRUE; 71 $data['queries'] = $this->core->db->benchmark; 63 $data['queries'] = Database::$benchmarks; 72 64 } 73 65 74 // Get profiler view ready to add to output66 // Load the profiler view 75 67 $view = new View('kohana_profiler', $data); 76 68 77 // Get page output 78 $output = Kohana::$output; 79 80 if (preg_match("|</body>.*?</html>|is", $output)) 69 // Add profiler data to the output 70 if (strpos('</body>', Kohana::$output) !== FALSE) 81 71 { 82 // Output has closing body and html tags, put profiler before them 83 $output = preg_replace("|</body>.*?</html>|is", '', $output); 84 $output .= $view; 85 $output .= '</body></html>'; 72 // Closing body tag was found, insert the profiler data before it 73 Kohana::$output = str_replace('</body>', $view.'</body>', Kohana::$output); 86 74 } 87 75 else 88 76 { 89 // No closing tags, just add profiler to the end90 $output .= $view;77 // Append the profiler data to the output 78 Kohana::$output .= $view; 91 79 } 92 93 // Set new page output94 Kohana::$output = $output;95 80 } 96 81
