缩进函数条目的更好方法

时间:2016-04-08 15:24:06

标签: php nested auto-indent dtrace

我有以下dtrace脚本:

#!/usr/sbin/dtrace -Zs
#pragma D option quiet
php*:::function-entry {
    printf("%Y: PHP function-entry :%*s%s %s%s%s() in %s:%d\n", walltimestamp, ++indent, "", "->", copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2);
}

php*:::function-return {
    printf("%Y: PHP function-return:%*s%s %s%s%s() in %s:%d\n", walltimestamp, indent--, "", "<-", copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2);
}

似乎适用于简单的PHP代码,例如:

<?php
function a() { b(); }
function b() { c(); }
function c() { d(); }
function d() { e(); }
function e() { }
a();

例如:

$ sudo ./trace-php.d 
2016 Apr  9 01:41:29: PHP function-entry : -> a() in foo.php:2
2016 Apr  9 01:41:29: PHP function-entry :  -> b() in foo.php:3
2016 Apr  9 01:41:29: PHP function-entry :   -> c() in foo.php:4
2016 Apr  9 01:41:29: PHP function-entry :    -> d() in foo.php:5
2016 Apr  9 01:41:29: PHP function-entry :     -> e() in foo.php:6
2016 Apr  9 01:41:29: PHP function-return:     <- e() in foo.php:6
2016 Apr  9 01:41:29: PHP function-return:    <- d() in foo.php:5
2016 Apr  9 01:41:29: PHP function-return:   <- c() in foo.php:4
2016 Apr  9 01:41:29: PHP function-return:  <- b() in foo.php:3
2016 Apr  9 01:41:29: PHP function-return: <- a() in foo.php:2

然而,当我用更复杂的脚本测试它时,例如运行drush statusphp index.php(在Drupal站点上),或者使用内置的PHP服务器,它会从屏幕上移到下一行,而另一行则不会回到同一个地方,所以之后几分钟我就有几百个(甚至几千个)太空人物。并且代码不可能如此深入,因为我xdebug.max_nesting_level=256阻止了太深的递归。

导致上述逻辑失败的原因以及如何改进?

0 个答案:

没有答案