update execution time debugging, move into include list

This commit is contained in:
mohrt
2001-10-23 19:04:40 +00:00
parent 08012a6e41
commit e252e9d1f2
6 changed files with 101 additions and 66 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- added DEBUG execution times to included files (Monte)
- added support for hidden config variables that cannot be read by - added support for hidden config variables that cannot be read by
templates. (Andrei) templates. (Andrei)
- added execution time to DEBUG console, total and inserts. (Monte) - added execution time to DEBUG console, total and inserts. (Monte)

View File

@@ -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_keys",array_keys($assigned_vars));
$smarty_obj->assign("_debug_vals",array_values($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); $smarty_obj->assign("_debug_tpls",$included_templates);
return true; return true;

View File

@@ -505,15 +505,15 @@ class Smarty
{ {
// capture time for debugging info // capture time for debugging info
$debug_start_time = $this->_get_microtime(); $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->_compile_id = $compile_id;
$this->_inclusion_depth = 0; $this->_inclusion_depth = 0;
$this->_included_tpls = array();
$this->_included_tpls[] = array('type' => 'template',
'filename' => $tpl_file,
'depth' => 0);
if ($this->caching) { if ($this->caching) {
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
@@ -530,8 +530,7 @@ class Smarty
if ($this->debugging) if ($this->debugging)
{ {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_times['var'][] = 'TOTAL'; $this->_included_tpls[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output(); echo $this->_generate_debug_output();
} }
@@ -605,9 +604,8 @@ class Smarty
if ($this->debugging) if ($this->debugging)
{ {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_times['var'][] = 'TOTAL'; $this->_included_tpls[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time);
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output(); echo $this->_generate_debug_output();
} }
return; return;
@@ -864,9 +862,14 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars) function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{ {
$this->_included_tpls[] = array('type' => 'template', if($this->debugging) {
'filename' => $_smarty_include_tpl_file, $debug_start_time = $this->_get_microtime();
'depth' => ++$this->_inclusion_depth); $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); $this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
extract($this->_tpl_vars); extract($this->_tpl_vars);
@@ -887,6 +890,13 @@ function _generate_debug_output() {
array_shift($this->_config); array_shift($this->_config);
$this->_inclusion_depth--; $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) function _config_load($file, $section, $scope)
{ {
$this->_included_tpls[] = array('type' => 'config', if($this->debugging) {
'filename' => $file, $debug_start_time = $this->_get_microtime();
'depth' => $this->_inclusion_depth); }
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file)); $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') { if ($scope == 'parent') {
@@ -918,6 +927,13 @@ function _generate_debug_output() {
for ($i = 1; $i < count($this->_config); $i++) for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section)); $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) function _process_cached_inserts($results)
{ {
if($this->debugging) if($this->debugging) {
{ $debug_start_time = $this->_get_microtime(); } $debug_start_time = $this->_get_microtime();
}
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
$results, $match); $results, $match);
@@ -946,8 +963,10 @@ function _generate_debug_output() {
$results = str_replace($cached_inserts[$i], $replace, $results); $results = str_replace($cached_inserts[$i], $replace, $results);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_times['var'][] = 'insert_'.$name; $this->_included_tpls[] = array('type' => 'insert',
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time; '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) function _run_insert_handler($args)
{ {
if($this->debugging) if($this->debugging) {
{ $debug_start_time = $this->_get_microtime(); } $debug_start_time = $this->_get_microtime();
}
if ($this->caching) { if ($this->caching) {
$arg_string = serialize($args); $arg_string = serialize($args);
@@ -971,9 +991,11 @@ function _run_insert_handler($args)
} else { } else {
$function_name = 'insert_'.$args['name']; $function_name = 'insert_'.$args['name'];
$content = $function_name($args, $this); $content = $function_name($args, $this);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_times['var'][] = 'insert_'.$args['name']; $this->_included_tpls[] = array('type' => 'insert',
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time; 'filename' => 'insert_'.$args['name'],
'depth' => ++$this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
return $content; return $content;
} }

View File

@@ -7,9 +7,9 @@
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>"); _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("<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><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} {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}&nbsp;&nbsp;&nbsp;{/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}&nbsp;&nbsp;&nbsp;{/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} {sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>"); _smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
{/section} {/section}
@@ -25,10 +25,6 @@
{sectionelse} {sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>"); _smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
{/section} {/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("</table>");
_smarty_console.document.write("</BODY></HTML>"); _smarty_console.document.write("</BODY></HTML>");
_smarty_console.document.close(); _smarty_console.document.close();

View File

@@ -505,15 +505,15 @@ class Smarty
{ {
// capture time for debugging info // capture time for debugging info
$debug_start_time = $this->_get_microtime(); $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->_compile_id = $compile_id;
$this->_inclusion_depth = 0; $this->_inclusion_depth = 0;
$this->_included_tpls = array();
$this->_included_tpls[] = array('type' => 'template',
'filename' => $tpl_file,
'depth' => 0);
if ($this->caching) { if ($this->caching) {
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
@@ -530,8 +530,7 @@ class Smarty
if ($this->debugging) if ($this->debugging)
{ {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_times['var'][] = 'TOTAL'; $this->_included_tpls[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output(); echo $this->_generate_debug_output();
} }
@@ -605,9 +604,8 @@ class Smarty
if ($this->debugging) if ($this->debugging)
{ {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_times['var'][] = 'TOTAL'; $this->_included_tpls[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time);
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output(); echo $this->_generate_debug_output();
} }
return; return;
@@ -864,9 +862,14 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars) function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{ {
$this->_included_tpls[] = array('type' => 'template', if($this->debugging) {
'filename' => $_smarty_include_tpl_file, $debug_start_time = $this->_get_microtime();
'depth' => ++$this->_inclusion_depth); $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); $this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
extract($this->_tpl_vars); extract($this->_tpl_vars);
@@ -887,6 +890,13 @@ function _generate_debug_output() {
array_shift($this->_config); array_shift($this->_config);
$this->_inclusion_depth--; $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) function _config_load($file, $section, $scope)
{ {
$this->_included_tpls[] = array('type' => 'config', if($this->debugging) {
'filename' => $file, $debug_start_time = $this->_get_microtime();
'depth' => $this->_inclusion_depth); }
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file)); $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') { if ($scope == 'parent') {
@@ -918,6 +927,13 @@ function _generate_debug_output() {
for ($i = 1; $i < count($this->_config); $i++) for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section)); $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) function _process_cached_inserts($results)
{ {
if($this->debugging) if($this->debugging) {
{ $debug_start_time = $this->_get_microtime(); } $debug_start_time = $this->_get_microtime();
}
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
$results, $match); $results, $match);
@@ -946,8 +963,10 @@ function _generate_debug_output() {
$results = str_replace($cached_inserts[$i], $replace, $results); $results = str_replace($cached_inserts[$i], $replace, $results);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_times['var'][] = 'insert_'.$name; $this->_included_tpls[] = array('type' => 'insert',
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time; '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) function _run_insert_handler($args)
{ {
if($this->debugging) if($this->debugging) {
{ $debug_start_time = $this->_get_microtime(); } $debug_start_time = $this->_get_microtime();
}
if ($this->caching) { if ($this->caching) {
$arg_string = serialize($args); $arg_string = serialize($args);
@@ -971,9 +991,11 @@ function _run_insert_handler($args)
} else { } else {
$function_name = 'insert_'.$args['name']; $function_name = 'insert_'.$args['name'];
$content = $function_name($args, $this); $content = $function_name($args, $this);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_times['var'][] = 'insert_'.$args['name']; $this->_included_tpls[] = array('type' => 'insert',
$this->_smarty_debug_times['val'][] = $this->_get_microtime() - $debug_start_time; 'filename' => 'insert_'.$args['name'],
'depth' => ++$this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
return $content; return $content;
} }

View File

@@ -7,9 +7,9 @@
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>"); _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("<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><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} {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}&nbsp;&nbsp;&nbsp;{/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}&nbsp;&nbsp;&nbsp;{/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} {sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>"); _smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
{/section} {/section}
@@ -25,10 +25,6 @@
{sectionelse} {sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>"); _smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
{/section} {/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("</table>");
_smarty_console.document.write("</BODY></HTML>"); _smarty_console.document.write("</BODY></HTML>");
_smarty_console.document.close(); _smarty_console.document.close();