mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update execution time debugging, move into include list
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- added DEBUG execution times to included files (Monte)
|
||||
- added support for hidden config variables that cannot be read by
|
||||
templates. (Andrei)
|
||||
- added execution time to DEBUG console, total and inserts. (Monte)
|
||||
|
@@ -693,8 +693,6 @@ function smarty_func_assign_debug_info($args, &$smarty_obj) {
|
||||
|
||||
$smarty_obj->assign("_debug_keys",array_keys($assigned_vars));
|
||||
$smarty_obj->assign("_debug_vals",array_values($assigned_vars));
|
||||
$smarty_obj->assign("_debug_times_keys",$smarty_obj->_smarty_debug_times['var']);
|
||||
$smarty_obj->assign("_debug_times_vals",$smarty_obj->_smarty_debug_times['val']);
|
||||
|
||||
$smarty_obj->assign("_debug_tpls",$included_templates);
|
||||
return true;
|
||||
|
@@ -505,15 +505,15 @@ class Smarty
|
||||
{
|
||||
// capture time for debugging info
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
$this->_included_tpls[] = array('type' => 'template',
|
||||
'filename' => $tpl_file,
|
||||
'depth' => 0);
|
||||
$included_tpls_idx = count($this->_included_tpls) - 1;
|
||||
}
|
||||
|
||||
$this->_compile_id = $compile_id;
|
||||
$this->_inclusion_depth = 0;
|
||||
$this->_included_tpls = array();
|
||||
|
||||
$this->_included_tpls[] = array('type' => 'template',
|
||||
'filename' => $tpl_file,
|
||||
'depth' => 0);
|
||||
|
||||
if ($this->caching) {
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
@@ -530,8 +530,7 @@ class Smarty
|
||||
if ($this->debugging)
|
||||
{
|
||||
// capture time for debugging info
|
||||
$this->_smarty_debug_times['var'][] = 'TOTAL';
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
||||
|
||||
echo $this->_generate_debug_output();
|
||||
}
|
||||
@@ -605,8 +604,7 @@ class Smarty
|
||||
if ($this->debugging)
|
||||
{
|
||||
// capture time for debugging info
|
||||
$this->_smarty_debug_times['var'][] = 'TOTAL';
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time);
|
||||
|
||||
echo $this->_generate_debug_output();
|
||||
}
|
||||
@@ -864,9 +862,14 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
|
||||
{
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
$this->_included_tpls[] = array('type' => 'template',
|
||||
'filename' => $_smarty_include_tpl_file,
|
||||
'depth' => ++$this->_inclusion_depth);
|
||||
$included_tpls_idx = count($this->_included_tpls) - 1;
|
||||
}
|
||||
|
||||
|
||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
||||
extract($this->_tpl_vars);
|
||||
@@ -887,6 +890,13 @@ function _generate_debug_output() {
|
||||
|
||||
array_shift($this->_config);
|
||||
$this->_inclusion_depth--;
|
||||
|
||||
if ($this->debugging) {
|
||||
// capture time for debugging info
|
||||
$this->_included_tpls[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -896,10 +906,9 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _config_load($file, $section, $scope)
|
||||
{
|
||||
$this->_included_tpls[] = array('type' => 'config',
|
||||
'filename' => $file,
|
||||
'depth' => $this->_inclusion_depth);
|
||||
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
}
|
||||
|
||||
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
|
||||
if ($scope == 'parent') {
|
||||
@@ -918,6 +927,13 @@ function _generate_debug_output() {
|
||||
for ($i = 1; $i < count($this->_config); $i++)
|
||||
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
|
||||
}
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
$this->_included_tpls[] = array('type' => 'config',
|
||||
'filename' => $file,
|
||||
'depth' => $this->_inclusion_depth,
|
||||
'exec_time' => $this->_get_microtime() - $debug_start_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -927,8 +943,9 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _process_cached_inserts($results)
|
||||
{
|
||||
if($this->debugging)
|
||||
{ $debug_start_time = $this->_get_microtime(); }
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
}
|
||||
|
||||
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
|
||||
$results, $match);
|
||||
@@ -946,8 +963,10 @@ function _generate_debug_output() {
|
||||
|
||||
$results = str_replace($cached_inserts[$i], $replace, $results);
|
||||
if ($this->debugging) {
|
||||
$this->_smarty_debug_times['var'][] = 'insert_'.$name;
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[] = array('type' => 'insert',
|
||||
'filename' => 'insert_'.$name,
|
||||
'depth' => ++$this->_inclusion_depth,
|
||||
'exec_time' => $this->_get_microtime() - $debug_start_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -962,8 +981,9 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _run_insert_handler($args)
|
||||
{
|
||||
if($this->debugging)
|
||||
{ $debug_start_time = $this->_get_microtime(); }
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
}
|
||||
|
||||
if ($this->caching) {
|
||||
$arg_string = serialize($args);
|
||||
@@ -972,8 +992,10 @@ function _run_insert_handler($args)
|
||||
$function_name = 'insert_'.$args['name'];
|
||||
$content = $function_name($args, $this);
|
||||
if ($this->debugging) {
|
||||
$this->_smarty_debug_times['var'][] = 'insert_'.$args['name'];
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[] = array('type' => 'insert',
|
||||
'filename' => 'insert_'.$args['name'],
|
||||
'depth' => ++$this->_inclusion_depth,
|
||||
'exec_time' => $this->_get_microtime() - $debug_start_time);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@
|
||||
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>");
|
||||
_smarty_console.document.write("<table border=0 width=100%>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files:</b></td></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>");
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{else}green{/if}>{$_debug_tpls[templates].filename}</font></tt></td></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename}</font> - <font size=-1><i>{$_debug_tpls[templates].exec_time|string_format:"%.5f"}{if %templates.index% eq 0} (total){/if}</i></font></tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
|
||||
{/section}
|
||||
@@ -25,10 +25,6 @@
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>Template execution time (in seconds):</b></td></tr>");
|
||||
{section name=exec_time loop=$_debug_times_keys}
|
||||
_smarty_console.document.write("<tr bgcolor={if %exed_time.index% is even}#eeeeee{else}#fafafa{/if}><td><tt>{if $_debug_times_keys[exec_time] eq "TOTAL"}<b>{$_debug_times_keys[exec_time]}</b>{else}{$_debug_times_keys[exec_time]}{/if}</td><td>{$_debug_times_vals[exec_time]}</tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("</table>");
|
||||
_smarty_console.document.write("</BODY></HTML>");
|
||||
_smarty_console.document.close();
|
||||
|
@@ -505,15 +505,15 @@ class Smarty
|
||||
{
|
||||
// capture time for debugging info
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
$this->_included_tpls[] = array('type' => 'template',
|
||||
'filename' => $tpl_file,
|
||||
'depth' => 0);
|
||||
$included_tpls_idx = count($this->_included_tpls) - 1;
|
||||
}
|
||||
|
||||
$this->_compile_id = $compile_id;
|
||||
$this->_inclusion_depth = 0;
|
||||
$this->_included_tpls = array();
|
||||
|
||||
$this->_included_tpls[] = array('type' => 'template',
|
||||
'filename' => $tpl_file,
|
||||
'depth' => 0);
|
||||
|
||||
if ($this->caching) {
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
@@ -530,8 +530,7 @@ class Smarty
|
||||
if ($this->debugging)
|
||||
{
|
||||
// capture time for debugging info
|
||||
$this->_smarty_debug_times['var'][] = 'TOTAL';
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
||||
|
||||
echo $this->_generate_debug_output();
|
||||
}
|
||||
@@ -605,8 +604,7 @@ class Smarty
|
||||
if ($this->debugging)
|
||||
{
|
||||
// capture time for debugging info
|
||||
$this->_smarty_debug_times['var'][] = 'TOTAL';
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time);
|
||||
|
||||
echo $this->_generate_debug_output();
|
||||
}
|
||||
@@ -864,9 +862,14 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
|
||||
{
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
$this->_included_tpls[] = array('type' => 'template',
|
||||
'filename' => $_smarty_include_tpl_file,
|
||||
'depth' => ++$this->_inclusion_depth);
|
||||
$included_tpls_idx = count($this->_included_tpls) - 1;
|
||||
}
|
||||
|
||||
|
||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
||||
extract($this->_tpl_vars);
|
||||
@@ -887,6 +890,13 @@ function _generate_debug_output() {
|
||||
|
||||
array_shift($this->_config);
|
||||
$this->_inclusion_depth--;
|
||||
|
||||
if ($this->debugging) {
|
||||
// capture time for debugging info
|
||||
$this->_included_tpls[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -896,10 +906,9 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _config_load($file, $section, $scope)
|
||||
{
|
||||
$this->_included_tpls[] = array('type' => 'config',
|
||||
'filename' => $file,
|
||||
'depth' => $this->_inclusion_depth);
|
||||
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
}
|
||||
|
||||
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
|
||||
if ($scope == 'parent') {
|
||||
@@ -918,6 +927,13 @@ function _generate_debug_output() {
|
||||
for ($i = 1; $i < count($this->_config); $i++)
|
||||
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
|
||||
}
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
$this->_included_tpls[] = array('type' => 'config',
|
||||
'filename' => $file,
|
||||
'depth' => $this->_inclusion_depth,
|
||||
'exec_time' => $this->_get_microtime() - $debug_start_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -927,8 +943,9 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _process_cached_inserts($results)
|
||||
{
|
||||
if($this->debugging)
|
||||
{ $debug_start_time = $this->_get_microtime(); }
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
}
|
||||
|
||||
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
|
||||
$results, $match);
|
||||
@@ -946,8 +963,10 @@ function _generate_debug_output() {
|
||||
|
||||
$results = str_replace($cached_inserts[$i], $replace, $results);
|
||||
if ($this->debugging) {
|
||||
$this->_smarty_debug_times['var'][] = 'insert_'.$name;
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[] = array('type' => 'insert',
|
||||
'filename' => 'insert_'.$name,
|
||||
'depth' => ++$this->_inclusion_depth,
|
||||
'exec_time' => $this->_get_microtime() - $debug_start_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -962,8 +981,9 @@ function _generate_debug_output() {
|
||||
\*======================================================================*/
|
||||
function _run_insert_handler($args)
|
||||
{
|
||||
if($this->debugging)
|
||||
{ $debug_start_time = $this->_get_microtime(); }
|
||||
if($this->debugging) {
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
}
|
||||
|
||||
if ($this->caching) {
|
||||
$arg_string = serialize($args);
|
||||
@@ -972,8 +992,10 @@ function _run_insert_handler($args)
|
||||
$function_name = 'insert_'.$args['name'];
|
||||
$content = $function_name($args, $this);
|
||||
if ($this->debugging) {
|
||||
$this->_smarty_debug_times['var'][] = 'insert_'.$args['name'];
|
||||
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
|
||||
$this->_included_tpls[] = array('type' => 'insert',
|
||||
'filename' => 'insert_'.$args['name'],
|
||||
'depth' => ++$this->_inclusion_depth,
|
||||
'exec_time' => $this->_get_microtime() - $debug_start_time);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@
|
||||
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>");
|
||||
_smarty_console.document.write("<table border=0 width=100%>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files:</b></td></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>");
|
||||
{section name=templates loop=$_debug_tpls}
|
||||
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{else}green{/if}>{$_debug_tpls[templates].filename}</font></tt></td></tr>");
|
||||
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth} {/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename}</font> - <font size=-1><i>{$_debug_tpls[templates].exec_time|string_format:"%.5f"}{if %templates.index% eq 0} (total){/if}</i></font></tt></td></tr>");
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
|
||||
{/section}
|
||||
@@ -25,10 +25,6 @@
|
||||
{sectionelse}
|
||||
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>Template execution time (in seconds):</b></td></tr>");
|
||||
{section name=exec_time loop=$_debug_times_keys}
|
||||
_smarty_console.document.write("<tr bgcolor={if %exed_time.index% is even}#eeeeee{else}#fafafa{/if}><td><tt>{if $_debug_times_keys[exec_time] eq "TOTAL"}<b>{$_debug_times_keys[exec_time]}</b>{else}{$_debug_times_keys[exec_time]}{/if}</td><td>{$_debug_times_vals[exec_time]}</tt></td></tr>");
|
||||
{/section}
|
||||
_smarty_console.document.write("</table>");
|
||||
_smarty_console.document.write("</BODY></HTML>");
|
||||
_smarty_console.document.close();
|
||||
|
Reference in New Issue
Block a user