Show
Ignore:
Timestamp:
10/05/2007 01:15:08 AM (14 months ago)
Author:
Shadowhand
Message:

Cleaned up Profiler and related files.

Files:
1 modified

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  
    1212 * @since            Version 2.0 
    1313 * @filesource 
     14 * 
     15 * $Id$ 
    1416 */ 
    1517 
     
    2628 * @link        http://kohanaphp.com/user_guide/general/profiling.html 
    2729 */ 
     30class Profiler_Core { 
    2831 
    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')); 
    3136 
    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        } 
    4339 
    4440        /** 
     
    5046        public function render() 
    5147        { 
    52                 // Get list of benchmarks 
    53                 $benchmarks = Benchmark::get_all(); 
     48                $data = array 
     49                ( 
     50                        'benchmarks' => array(), 
     51                        'queries'    => FALSE 
     52                ); 
    5453 
    5554                // 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) 
    5856                { 
    59                         $name              = str_replace(SYSTEM_BENCHMARK.'_', '', $name); 
    60                         $renamed_bm[$name] = $time; 
     57                        $data['benchmarks'][str_replace(SYSTEM_BENCHMARK.'_', '', $name)] = $time; 
    6158                } 
    6259 
    63                 $data['benchmarks'] = $renamed_bm; 
    64  
    6560                // Get database queries 
    66                 $data['db_exists'] = FALSE; 
    67                 $data['queries']   = array(); 
    68                 if (isset($this->core->db)) 
     61                if (isset(Kohana::instance()->db)) 
    6962                { 
    70                         $data['db_exists'] = TRUE; 
    71                         $data['queries']   = $this->core->db->benchmark; 
     63                        $data['queries'] = Database::$benchmarks; 
    7264                } 
    7365 
    74                 // Get profiler view ready to add to output 
     66                // Load the profiler view 
    7567                $view = new View('kohana_profiler', $data); 
    7668 
    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) 
    8171                { 
    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); 
    8674                } 
    8775                else 
    8876                { 
    89                         // No closing tags, just add profiler to the end 
    90                         $output .= $view; 
     77                        // Append the profiler data to the output 
     78                        Kohana::$output .= $view; 
    9179                } 
    92  
    93                 // Set new page output 
    94                 Kohana::$output = $output; 
    9580        } 
    9681