1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: class Mage_Core_Block_Profiler extends Mage_Core_Block_Abstract
29: {
30: protected function _toHtml()
31: {
32: if (!$this->_beforeToHtml()
33: || !Mage::getStoreConfig('dev/debug/profiler')
34: || !Mage::helper('core')->isDevAllowed()) {
35: return '';
36: }
37:
38: $timers = Varien_Profiler::getTimers();
39:
40:
41:
42: $out = "<a href=\"javascript:void(0)\" onclick=\"$('profiler_section').style.display=$('profiler_section').style.display==''?'none':''\">[profiler]</a>";
43: $out .= '<div id="profiler_section" style="background:white; display:block">';
44: $out .= '<pre>Memory usage: real: '.memory_get_usage(true).', emalloc: '.memory_get_usage().'</pre>';
45: $out .= '<table border="1" cellspacing="0" cellpadding="2" style="width:auto">';
46: $out .= '<tr><th>Code Profiler</th><th>Time</th><th>Cnt</th><th>Emalloc</th><th>RealMem</th></tr>';
47: foreach ($timers as $name=>$timer) {
48: $sum = Varien_Profiler::fetch($name,'sum');
49: $count = Varien_Profiler::fetch($name,'count');
50: $realmem = Varien_Profiler::fetch($name,'realmem');
51: $emalloc = Varien_Profiler::fetch($name,'emalloc');
52: if ($sum<.0010 && $count<10 && $emalloc<10000) {
53: continue;
54: }
55: $out .= '<tr>'
56: .'<td align="left">'.$name.'</td>'
57: .'<td>'.number_format($sum,4).'</td>'
58: .'<td align="right">'.$count.'</td>'
59: .'<td align="right">'.number_format($emalloc).'</td>'
60: .'<td align="right">'.number_format($realmem).'</td>'
61: .'</tr>'
62: ;
63: }
64: $out .= '</table>';
65: $out .= '<pre>';
66: $out .= print_r(Varien_Profiler::getSqlProfiler(Mage::getSingleton('core/resource')->getConnection('core_write')), 1);
67: $out .= '</pre>';
68: $out .= '</div>';
69:
70: return $out;
71: }
72: }
73: