magento优化-性能-程序运行时间监测
2013-01-25 11:27
447 查看
在网站的优化过程中,通常需要查看程序的运行时间,mangento为我们提供了查看的方法。
这里用到的magento核心类是Varien_Profiler
用Varien_Profiler来监测程序运行时间的使用方法如下:
start和stop函数的参数是监测这段程序的名字,名字可以随便起,只要保证全局唯一就ok了
这样在程序中写上代码后,监测的结果并不能直接显示,要显示结果需要有两个条件:
1、修改seystem/config/developer/调试/配置器 为true
2、在index.php中去掉下面这段程序的注释
当上面这些都配置好后,刷新网页会在网页的底部显示如下的一个表格:
这样的表格是如何显示出来的呢,这里用到一个Block类/app/code/core/Mage/Core/Block/Profiler.php
这里用到的magento核心类是Varien_Profiler
用Varien_Profiler来监测程序运行时间的使用方法如下:
Varien_Profiler::start('self::app::init'); self::$_app->init($code, $type, $options);//初始化APP Varien_Profiler::stop('self::app::init');
start和stop函数的参数是监测这段程序的名字,名字可以随便起,只要保证全局唯一就ok了
这样在程序中写上代码后,监测的结果并不能直接显示,要显示结果需要有两个条件:
1、修改seystem/config/developer/调试/配置器 为true
2、在index.php中去掉下面这段程序的注释
Varien_Profiler::enable();//启用Varien_Profiler
当上面这些都配置好后,刷新网页会在网页的底部显示如下的一个表格:
这样的表格是如何显示出来的呢,这里用到一个Block类/app/code/core/Mage/Core/Block/Profiler.php
class Mage_Core_Block_Profiler extends Mage_Core_Block_Abstract { protected function _toHtml() { if (!$this->_beforeToHtml() || !Mage::getStoreConfig('dev/debug/profiler') || !Mage::helper('core')->isDevAllowed()) { return ''; } $timers = Varien_Profiler::getTimers(); #$out = '<div style="position:fixed;bottom:5px;right:5px;opacity:.1;background:white" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.1">'; #$out = '<div style="opacity:.1" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.1">'; $out = "<a href=\"javascript:void(0)\" onclick=\"$('profiler_section').style.display=$('profiler_section').style.display==''?'none':''\">[profiler]</a>"; $out .= '<div id="profiler_section" style="background:white; display:block">'; $out .= '<pre>Memory usage: real: '.memory_get_usage(true).', emalloc: '.memory_get_usage().'</pre>'; $out .= '<table border="1" cellspacing="0" cellpadding="2" style="width:auto">'; $out .= '<tr><th>Code Profiler</th><th>Time</th><th>Cnt</th><th>Emalloc</th><th>RealMem</th></tr>'; foreach ($timers as $name=>$timer) { $sum = Varien_Profiler::fetch($name,'sum'); $count = Varien_Profiler::fetch($name,'count'); $realmem = Varien_Profiler::fetch($name,'realmem'); $emalloc = Varien_Profiler::fetch($name,'emalloc'); if ($sum<.0010 && $count<10 && $emalloc<10000) { continue; } $out .= '<tr>' .'<td align="left">'.$name.'</td>' .'<td>'.number_format($sum,4).'</td>' .'<td align="right">'.$count.'</td>' .'<td align="right">'.number_format($emalloc).'</td>' .'<td align="right">'.number_format($realmem).'</td>' .'</tr>' ; } $out .= '</table>'; $out .= '<pre>'; $out .= print_r(Varien_Profiler::getSqlProfiler(Mage::getSingleton('core/resource')->getConnection('core_write')), 1); $out .= '</pre>'; $out .= '</div>'; return $out; } }
相关文章推荐
- VC中监测程序运行时间(二)-毫秒级
- 优化性能,保证程序顺畅运行的方案
- C# ASP.NET 优化程序性能、降低内存使用、提高程序运行速度
- Android程序运行性能优化
- 如何理解Android程序运行性能优化
- Android程序运行性能优化
- 监测程序运行的时间,stopWatch
- Android程序运行性能优化
- DSP程序开发与优化经验之二:程序运行时间测量方法总结
- Android程序运行性能优化
- 优化matlab程序的运行时间
- DSP程序开发与优化经验之二:程序运行时间测量方法总结
- C++程序运行时间优化
- 【fun】自制程序运行时间监测头文件
- Java程序时间和空间性能优化Tip
- paip.程序功能时间性能优化及SQL语句优化
- oracle性能优化--控制单次任务规模,减少总体运行时间
- 监测程序运行时间的类
- Android程序运行性能优化
- 【性能测试】验证程序运行时所占用的时间Cycle