00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Core_Block_Profiler extends Mage_Core_Block_Abstract
00029 {
00030 protected function _toHtml()
00031 {
00032 if (!$this->_beforeToHtml()
00033 || !Mage::getStoreConfig('dev/debug/profiler')
00034 || !Mage::helper('core')->isDevAllowed()) {
00035 return '';
00036 }
00037
00038 $timers = Varien_Profiler::getTimers();
00039
00040 #$out = '<div style="position:fixed;bottom:5px;right:5px;opacity:.1;background:white" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.1">';
00041 #$out = '<div style="opacity:.1" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.1">';
00042 $out = "<a href=\"javascript:void(0)\" onclick=\"$('profiler_section').style.display=$('profiler_section').style.display==''?'none':''\">[profiler]</a>";
00043 $out .= '<div id="profiler_section" style="background:white; display:block">';
00044 $out .= '<pre>Memory usage: real: '.memory_get_usage(true).', emalloc: '.memory_get_usage().'</pre>';
00045 $out .= '<table border="1" cellspacing="0" cellpadding="2" style="width:auto">';
00046 $out .= '<tr><th>Code Profiler</th><th>Time</th><th>Cnt</th><th>Emalloc</th><th>RealMem</th></tr>';
00047 foreach ($timers as $name=>$timer) {
00048 $sum = Varien_Profiler::fetch($name,'sum');
00049 $count = Varien_Profiler::fetch($name,'count');
00050 $realmem = Varien_Profiler::fetch($name,'realmem');
00051 $emalloc = Varien_Profiler::fetch($name,'emalloc');
00052 if ($sum<.0010 && $count<10 && $emalloc<10000) {
00053 continue;
00054 }
00055 $out .= '<tr>'
00056 .'<td align="left">'.$name.'</td>'
00057 .'<td>'.number_format($sum,4).'</td>'
00058 .'<td align="right">'.$count.'</td>'
00059 .'<td align="right">'.number_format($emalloc).'</td>'
00060 .'<td align="right">'.number_format($realmem).'</td>'
00061 .'</tr>'
00062 ;
00063 }
00064 $out .= '</table>';
00065 $out .= '<pre>';
00066 $out .= print_r(Varien_Profiler::getSqlProfiler(Mage::getSingleton('core/resource')->getConnection('core_write')), 1);
00067 $out .= '</pre>';
00068 $out .= '</div>';
00069
00070 return $out;
00071 }
00072 }