Show template rendering time in debug log

This commit is contained in:
Frederic Guillot 2016-01-16 21:35:50 -05:00
parent ee19c62648
commit 41e900fc7a
2 changed files with 52 additions and 2 deletions

View File

@ -16,6 +16,7 @@ Improvements:
* Reduce the number of SQL queries for project daily column stats
* Remove event subscriber to update date_moved field
* Make sure that some event subscribers are not executed multiple times
* Show rendering time of individual templates when debug mode is enabled
Bug fixes:

View File

@ -18,6 +18,50 @@ class Template extends Helper
*/
private $overrides = array();
/**
* Rendering start time
*
* @access private
* @var float
*/
private $startTime = 0;
/**
* Total rendering time
*
* @access private
* @var float
*/
private $renderingTime = 0;
/**
* Method executed before the rendering
*
* @access protected
* @param string $template
*/
protected function beforeRender($template)
{
if (DEBUG) {
$this->startTime = microtime(true);
}
}
/**
* Method executed after the rendering
*
* @access protected
* @param string $template
*/
protected function afterRender($template)
{
if (DEBUG) {
$duration = microtime(true) - $this->startTime;
$this->renderingTime += $duration;
$this->container['logger']->debug('Rendering '.$template.' in '.$duration.'s, total='.$this->renderingTime);
}
}
/**
* Render a template
*
@ -32,11 +76,16 @@ class Template extends Helper
*/
public function render($__template_name, array $__template_args = array())
{
extract($__template_args);
$this->beforeRender($__template_name);
extract($__template_args);
ob_start();
include $this->getTemplateFile($__template_name);
return ob_get_clean();
$html = ob_get_clean();
$this->afterRender($__template_name);
return $html;
}
/**