Changeset 658
- Timestamp:
- 10/05/2007 01:15:08 AM (12 months ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
application/config/config.php (modified) (1 diff)
-
application/config/database.php (modified) (2 diffs)
-
system/core/Benchmark.php (modified) (3 diffs)
-
system/libraries/Database.php (modified) (3 diffs)
-
system/libraries/Profiler.php (modified) (3 diffs, 3 props)
-
system/views/kohana_profiler.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/application/config/config.php
r651 r658 133 133 $config['autoload'] = array 134 134 ( 135 'libraries' => ' ',135 'libraries' => 'profiler', 136 136 'models' => '' 137 137 ); -
trunk/application/config/database.php
r647 r658 10 10 * 11 11 * @param boolean show_errors - Enable or disable database exceptions 12 * @param boolean benchmark - Enable or disable database benchmarking 12 13 * @param boolean persistent - Enable or disable a persistent connection 13 14 * @param string connection - DSN identifier: driver://user:password@server/database … … 20 21 ( 21 22 'show_errors' => TRUE, 23 'benchmark' => TRUE, 22 24 'persistent' => FALSE, 23 25 'connection' => 'mysql://dbuser:secret@localhost/kohana', -
trunk/system/core/Benchmark.php
r657 r658 49 49 public static function get($name, $decimals = 4) 50 50 { 51 $total = FALSE; 52 51 53 if (isset(self::$marks[$name])) 52 54 { … … 56 58 } 57 59 58 returnnumber_format(self::$marks[$name]['stop'] - self::$marks[$name]['start'], $decimals);60 $total = number_format(self::$marks[$name]['stop'] - self::$marks[$name]['start'], $decimals); 59 61 } 62 63 return $total; 60 64 } 61 65 … … 70 74 { 71 75 $benchmarks = array(); 72 foreach (self::$marks as $name => $times) 76 77 foreach (array_keys(self::$marks) as $name) 73 78 { 74 79 $benchmarks[$name] = self::get($name, $decimals); -
trunk/system/libraries/Database.php
r655 r658 30 30 class Database_Core { 31 31 32 // Global benchmark 33 public static $benchmarks = array(); 34 32 35 // Configuration 33 protected $config = array36 protected $config = array 34 37 ( 38 'show_errors' => TRUE, 39 'benchmark' => TRUE, 40 'persistent' => FALSE, 35 41 'connection' => '', 36 'persistent' => FALSE,37 'show_errors' => TRUE,38 42 'character_set' => 'utf8', 39 'table_prefix' => '' 43 'table_prefix' => '', 44 'object' => TRUE 40 45 ); 41 46 … … 59 64 protected $connected = FALSE; 60 65 protected $last_query = ''; 61 public $benchmark = array();62 66 63 67 /** … … 474 478 $stop = microtime(TRUE); 475 479 476 // benchmark the query 477 $this->benchmark[] = array('query' => $sql, 'time' => $stop - $start); 480 if ($this->config['benchmark'] == TRUE) 481 { 482 // Benchmark the query 483 self::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start); 484 } 478 485 479 486 $this->reset_select(); -
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 -
trunk/system/views/kohana_profiler.php
r654 r658 1 1 <style type="text/css"> 2 #kohana-profiler3 {4 font-family: Courier New;5 background-color: #F8FFF8;6 margin-top: 20px;7 clear: both;8 padding: 10px;9 border: 1px solid #E5EFF8;10 }11 #kohana-profiler table12 {13 font-size: 1.0em;14 color: #4D6171;15 width: 100%;16 border-collapse: collapse;17 border-top: 1px solid #E5EFF8;18 border-right: 1px solid #E5EFF8;19 border-left: 1px solid #E5EFF8;20 margin-bottom: 10px;21 }22 #kohana-profiler th23 {24 text-align: left;25 border-bottom: 1px solid #E5EFF8;26 background-color: #F9FCFE;27 padding: 3px;28 color: #263038;29 }30 #kohana-profiler td31 {32 background-color: #FFFFFF;33 border-bottom: 1px solid #E5EFF8;34 padding: 3px;35 }36 #kohana-profiler .kp-altrow td37 {38 background-color: #F7FBFF;39 }40 #kp-benchmarks th41 {42 background-color: #FFE0E0;43 }44 #kp-queries th45 {46 background-color: #E0FFE0;47 }48 #kp-postdata th49 {50 background-color: #E0E0FF;51 }52 #kohana-profiler .kp-time53 {54 width: 100px;55 background-color: #FAFAFB !important;56 border-left: 1px solid #E5EFF8;57 text-align: center;58 }59 #kohana-profiler .kp-postname60 {61 width: 200px;62 background-color: #FAFAFB !important;63 border-right: 1px solid #E5EFF8;64 }2 #kohana-profiler 3 { 4 font-family: 'Courier New'; 5 background-color: #F8FFF8; 6 margin-top: 20px; 7 clear: both; 8 padding: 10px; 9 border: 1px solid #E5EFF8; 10 } 11 #kohana-profiler table 12 { 13 font-size: 1.0em; 14 color: #4D6171; 15 width: 100%; 16 border-collapse: collapse; 17 border-top: 1px solid #E5EFF8; 18 border-right: 1px solid #E5EFF8; 19 border-left: 1px solid #E5EFF8; 20 margin-bottom: 10px; 21 } 22 #kohana-profiler th 23 { 24 text-align: left; 25 border-bottom: 1px solid #E5EFF8; 26 background-color: #F9FCFE; 27 padding: 3px; 28 color: #263038; 29 } 30 #kohana-profiler td 31 { 32 background-color: #FFFFFF; 33 border-bottom: 1px solid #E5EFF8; 34 padding: 3px; 35 } 36 #kohana-profiler .kp-altrow td 37 { 38 background-color: #F7FBFF; 39 } 40 #kp-benchmarks th 41 { 42 background-color: #FFE0E0; 43 } 44 #kp-queries th 45 { 46 background-color: #E0FFE0; 47 } 48 #kp-postdata th 49 { 50 background-color: #E0E0FF; 51 } 52 #kohana-profiler .kp-time 53 { 54 width: 100px; 55 background-color: #FAFAFB !important; 56 border-left: 1px solid #E5EFF8; 57 text-align: center; 58 } 59 #kohana-profiler .kp-postname 60 { 61 width: 200px; 62 background-color: #FAFAFB !important; 63 border-right: 1px solid #E5EFF8; 64 } 65 65 </style> 66 66 <div id="kohana-profiler"> … … 70 70 <th colspan="2"><?php echo Kohana::lang('profiler.benchmarks') ?></th> 71 71 </tr> 72 <?php 73 $count = 0; 74 foreach ($benchmarks as $name => $time) 75 { 76 $name = ucwords(str_replace(array('_', '-'), ' ', $name)); 77 ?> 78 <tr<?php if ($count % 2) echo ' class="kp-altrow"'; ?>> 72 <?php 73 74 $count = 0; 75 foreach ($benchmarks as $name => $time): 76 77 $name = ucwords(str_replace(array('_', '-'), ' ', $name)); 78 79 ?> 80 <tr<?php if ($count++ % 2): ?> class="kp-altrow"<?php endif; ?>> 79 81 <td><?php echo $name ?></td> 80 82 <td class="kp-time"><?php echo $time ?></td> 81 83 </tr> 82 <?php 83 $count++; 84 } 85 ?> 84 <?php 85 86 endforeach; 87 88 ?> 86 89 </table> 87 90 88 91 <table id="kp-queries"> 89 92 <tr> 90 <th colspan="2"><?php echo Kohana::lang('profiler.queries') ?> (<?php echo count($queries) ?>)</th>93 <th colspan="2"><?php echo Kohana::lang('profiler.queries') ?> (<?php echo ($queries == FALSE ? '0' : count($queries)) ?>)</th> 91 94 </tr> 92 <?php 93 if ( ! $db_exists) 94 { 95 ?> 96 <tr><td colspan="2"><?php echo Kohana::lang('profiler.no_database') ?></td></tr> 97 <?php 98 } 99 else 100 { 101 if (count($queries) == 0) 102 { 103 ?> 104 <tr><td colspan="2"><?php echo Kohana::lang('profiler.no_queries') ?></td></tr> 105 <?php 106 } 107 else 108 { 109 $count = 0; 110 foreach ($queries as $query) 111 { 112 ?> 113 <tr<?php if ($count % 2) echo ' class="kp-altrow"'; ?>> 114 <td><?php echo htmlspecialchars($query['query']) ?></td> 115 <td class="kp-time"><?php echo number_format($query['time'], 4) ?></td> 116 </tr> 117 <?php 118 $count++; 119 } 120 } 121 } 122 ?> 95 <?php 96 97 if ($queries === FALSE): 98 99 ?> 100 <tr><td colspan="2"><?php echo Kohana::lang('profiler.no_database') ?></td></tr> 101 <?php 102 103 else: 104 105 if (count($queries) == 0): 106 107 ?> 108 <tr><td colspan="2"><?php echo Kohana::lang('profiler.no_queries') ?></td></tr> 109 <?php 110 111 else: 112 $count = 0; 113 foreach($queries as $query): 114 115 ?> 116 <tr<?php if ($count++ % 2): ?> class="kp-altrow"<?php endif; ?>> 117 <td><?php echo htmlspecialchars($query['query']) ?></td> 118 <td class="kp-time"><?php echo number_format($query['time'], 4) ?></td> 119 </tr> 120 <?php 121 122 endforeach; 123 endif; 124 endif; 125 126 ?> 123 127 </table> 124 128 … … 127 131 <th colspan="2"><?php echo Kohana::lang('profiler.post_data') ?></th> 128 132 </tr> 129 <?php 130 if (count($_POST) == 0) 131 { 132 ?> 133 <tr><td colspan="2"><?php echo Kohana::lang('profiler.no_post') ?></td></tr> 134 <?php 135 } 136 else 137 { 138 $count = 0; 139 foreach ($_POST as $name => $value) 140 { 141 ?> 142 <tr<?php if ($count % 2) echo ' class="kp-altrow"'; ?>> 143 <td class="kp-postname"><?php echo $name ?></td> 144 <td> 145 <?php 146 if (is_array($value)) 147 { 148 echo '<pre>' . htmlspecialchars(print_r($value, true)) . '</pre>'; 149 } 150 else 151 { 152 echo htmlspecialchars($value); 153 } 154 ?> 155 </td> 156 </tr> 157 <?php 158 $count++; 159 } 160 } 161 ?> 133 <?php 134 135 if (count($_POST) == 0): 136 137 ?> 138 <tr><td colspan="2"><?php echo Kohana::lang('profiler.no_post') ?></td></tr> 139 <?php 140 141 else: 142 $count = 0; 143 foreach($_POST as $name => $value): 144 145 ?> 146 <tr<?php if ($count++ % 2): ?> class="kp-altrow" <?php endif; ?>> 147 <td class="kp-postname"><?php echo $name ?></td> 148 <td> 149 <pre><?php echo htmlspecialchars(is_array($value) ? print_r($value, TRUE) : $value) ?></pre> 150 </td> 151 </tr> 152 <?php 153 154 endforeach; 155 endif; 156 157 ?> 162 158 </table> 163 159
