diff --git a/NEWS b/NEWS
index 3b217c83..bb5a68ee 100644
--- a/NEWS
+++ b/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)
diff --git a/Smarty.addons.php b/Smarty.addons.php
index ec0181c8..dcc2f988 100644
--- a/Smarty.addons.php
+++ b/Smarty.addons.php
@@ -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;
diff --git a/Smarty.class.php b/Smarty.class.php
index 6c5ff0f8..99b85e02 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -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,9 +604,8 @@ 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();
}
return;
@@ -864,9 +862,14 @@ function _generate_debug_output() {
\*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{
- $this->_included_tpls[] = array('type' => 'template',
- 'filename' => $_smarty_include_tpl_file,
- 'depth' => ++$this->_inclusion_depth);
+ 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);
@@ -971,9 +991,11 @@ function _run_insert_handler($args)
} else {
$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;
+ if ($this->debugging) {
+ $this->_included_tpls[] = array('type' => 'insert',
+ 'filename' => 'insert_'.$args['name'],
+ 'depth' => ++$this->_inclusion_depth,
+ 'exec_time' => $this->_get_microtime() - $debug_start_time);
}
return $content;
}
diff --git a/demo/templates/debug.tpl b/demo/templates/debug.tpl
index d55771e5..d7cc04ae 100644
--- a/demo/templates/debug.tpl
+++ b/demo/templates/debug.tpl
@@ -7,9 +7,9 @@
_smarty_console.document.write("
Smarty Debug Console");
_smarty_console.document.write("");
_smarty_console.document.write("Smarty Debug Console |
");
- _smarty_console.document.write("included templates & config files: |
");
+ _smarty_console.document.write("included templates & config files (load time in seconds): |
");
{section name=templates loop=$_debug_tpls}
- _smarty_console.document.write("{section name=indent loop=$_debug_tpls[templates].depth} {/section}{$_debug_tpls[templates].filename} |
");
+ _smarty_console.document.write("{section name=indent loop=$_debug_tpls[templates].depth} {/section}{$_debug_tpls[templates].filename} - {$_debug_tpls[templates].exec_time|string_format:"%.5f"}{if %templates.index% eq 0} (total){/if} |
");
{sectionelse}
_smarty_console.document.write("no templates included |
");
{/section}
@@ -25,10 +25,6 @@
{sectionelse}
_smarty_console.document.write("no config vars assigned |
");
{/section}
- _smarty_console.document.write("Template execution time (in seconds): |
");
- {section name=exec_time loop=$_debug_times_keys}
- _smarty_console.document.write("{if $_debug_times_keys[exec_time] eq "TOTAL"}{$_debug_times_keys[exec_time]}{else}{$_debug_times_keys[exec_time]}{/if} | {$_debug_times_vals[exec_time]} |
");
- {/section}
_smarty_console.document.write("
");
_smarty_console.document.write("");
_smarty_console.document.close();
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 6c5ff0f8..99b85e02 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -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,9 +604,8 @@ 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();
}
return;
@@ -864,9 +862,14 @@ function _generate_debug_output() {
\*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{
- $this->_included_tpls[] = array('type' => 'template',
- 'filename' => $_smarty_include_tpl_file,
- 'depth' => ++$this->_inclusion_depth);
+ 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);
@@ -971,9 +991,11 @@ function _run_insert_handler($args)
} else {
$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;
+ if ($this->debugging) {
+ $this->_included_tpls[] = array('type' => 'insert',
+ 'filename' => 'insert_'.$args['name'],
+ 'depth' => ++$this->_inclusion_depth,
+ 'exec_time' => $this->_get_microtime() - $debug_start_time);
}
return $content;
}
diff --git a/templates/debug.tpl b/templates/debug.tpl
index d55771e5..d7cc04ae 100644
--- a/templates/debug.tpl
+++ b/templates/debug.tpl
@@ -7,9 +7,9 @@
_smarty_console.document.write("Smarty Debug Console");
_smarty_console.document.write("");
_smarty_console.document.write("Smarty Debug Console |
");
- _smarty_console.document.write("included templates & config files: |
");
+ _smarty_console.document.write("included templates & config files (load time in seconds): |
");
{section name=templates loop=$_debug_tpls}
- _smarty_console.document.write("{section name=indent loop=$_debug_tpls[templates].depth} {/section}{$_debug_tpls[templates].filename} |
");
+ _smarty_console.document.write("{section name=indent loop=$_debug_tpls[templates].depth} {/section}{$_debug_tpls[templates].filename} - {$_debug_tpls[templates].exec_time|string_format:"%.5f"}{if %templates.index% eq 0} (total){/if} |
");
{sectionelse}
_smarty_console.document.write("no templates included |
");
{/section}
@@ -25,10 +25,6 @@
{sectionelse}
_smarty_console.document.write("no config vars assigned |
");
{/section}
- _smarty_console.document.write("Template execution time (in seconds): |
");
- {section name=exec_time loop=$_debug_times_keys}
- _smarty_console.document.write("{if $_debug_times_keys[exec_time] eq "TOTAL"}{$_debug_times_keys[exec_time]}{else}{$_debug_times_keys[exec_time]}{/if} | {$_debug_times_vals[exec_time]} |
");
- {/section}
_smarty_console.document.write("
");
_smarty_console.document.write("");
_smarty_console.document.close();