Windows tcl中进程内的命令计数?

Windows tcl中进程内的命令计数?,windows,tcl,Windows,Tcl,是否有任何方法可以在执行之前从指定的proc name对命令进行计数(可能是包括TCLCMD在内的调用堆栈编号)?我认为需要假设源可用(不适用于预编译)。 谢谢。动态分析 您可以使用跟踪来查找在特定过程的执行过程中执行了多少命令。假设该命令未重新输入(即,不是递归的),则执行以下操作: 您还可以查看commands元素以查看已识别的命令(dict-get[lindex[dict-get$discombled commands]$n]source)。它将检查像for这样的命令,但不会检查带有主体的

是否有任何方法可以在执行之前从指定的proc name对命令进行计数(可能是包括TCLCMD在内的调用堆栈编号)?我认为需要假设源可用(不适用于预编译)。 谢谢。

动态分析 您可以使用跟踪来查找在特定过程的执行过程中执行了多少命令。假设该命令未重新输入(即,不是递归的),则执行以下操作:


您还可以查看
commands
元素以查看已识别的命令(
dict-get[lindex[dict-get$discombled commands]$n]source
)。它将检查像
for
这样的命令,但不会检查带有主体的自定义命令(因为它不理解它们是代码的一部分,而不仅仅是一个有趣的字符串)。它也不知道他们被处决的频率;毕竟是静态分析。

还是说静态分析?我也有一些代码来实现这一点,但这要复杂得多。我需要在执行前进行呼叫计数。我认为这是静态分析。我无法确定解决方案在编译和源代码中的行为。
proc theProcedureOfInterest {} {
    # Whatever in here...
    for {set i 0} {$i < 5} {incr i} {
        puts i=$i
    }
}
trace add execution theProcedureOfInterest {enter leave enterstep} countCalls
proc countCalls {cmd args} {
    global counter
    switch [lindex $args end] {
        enter {
            set counter 0
        }
        enterstep {
            incr counter
            puts >>>$cmd
        }
        leave {
            puts "$counter calls in $cmd"
        }
    }
}

theProcedureOfInterest
>>>for {set i 0} {$i < 5} {incr i} { puts i=$i } >>>set i 0 >>>puts i=0 i=0 >>>incr i >>>puts i=1 i=1 >>>incr i >>>puts i=2 i=2 >>>incr i >>>puts i=3 i=3 >>>incr i >>>puts i=4 i=4 >>>incr i 12 calls in theProcedureOfInterest
set disassembled [::tcl::unsupported::getbytecode script {
    # Whatever in here...
    for {set i 0} {$i < 5} {incr i} {
        puts i=$i
    }
}]
set commandCount [llength [dict get $disassembled commands]]