sgxTools

sgxToolsは、Tclスクリプトの検査用拡張パッケージです。
プロシジャの動きや変数の使用方法等を動的にチェックします。
Tclスクリプトの潜在バグを発見できる大変有用なツールです。
Linux, UNIX, Windows上で動作します。Tcl/Tk8.0以上に対応しています。
sgxToolsは、以下のツールから構成されています。

sgxCP

コードのプロファイルを行うための拡張です。
以下の例は、test.tclをプロファイルします。

package require sgxCP
::sgxCP::init
source test.tcl
puts stderr [::sgxCP::print]

プロファイル結果は、プロシジャ毎に出力されます。
プロシジャのコール回数と実行時間が表示されます。
最後に一度も使われなかったプロシジャが表示されます。

Profiling information for ::pong
-------------------------
            Total calls:  3
    Caller distribution:
                          3     ::ping
           Compile time:  14166
          Total runtime:  43629
        Average runtime:  14543
          Runtime StDev:  367
         Runtime cov(%):  2.5
  Total descendant time:  42594
Average descendant time:  14198
Descendants:
                          3     ::ping

Never used:     1 proc(s)
        ::pongping

[謎の現象]
Tkを使ったスクリプトのプロファイルをし、結果を表示させると以下のエラーが発生します。
バグだと思いますが。。。

puts stderr [::sgxCP::print]
=> divide by zero

sgxCT

コードのトレースを行うための拡張です。
以下の例は、test.tclをトレースします。
正規表現を使ってトレースするプロシジャを限定することもできます。

package require sgxCT
::sgxCT::Init {p.*g} stderr
source test.tcl
::sgxCT::Summary {p.*g}

トレース結果は、プロシジャのコールとリターンの関係が出力されます。
プロシジャのネストレベル、引数、返却値が表示されます。
Summaryは、プロシジャのコール数と呼び出しの関係が表示されます。

# Call Trace    regexp: 'p.*g'

mode    level   proc    args/return
call    1       ::pingpong
call    2       ::ping  1
call    3       ::pong  1
call    4       ::ping  2
call    5       ::pong  2
call    6       ::ping  3
call    7       ::pong  3
call    8       ::ping  4

        BANG    4

return  8       ::ping  BANG
return  7       ::pong  3
return  6       ::ping  3
return  5       ::pong  2
return  4       ::ping  2
return  3       ::pong  1
return  2       ::ping  1
return  1       ::pingpong      1

# Call Trace Summary    regexp: 'p.*g'

        # called:
        4       ::ping
        1       ::pingpong
        3       ::pong

        # caller:
        4       ::ping
        1       ::pingpong
        3       ::pong

        # callings:
        1       ::ping          ::BANG
        3       ::ping          ::pong
        1       ::pingpong      ::ping
        3       ::pong          ::ping
        1       ./test/test_ct.dat        ::pingpong

        # unused:
        0       ::pongping

sgxRSM

リソース測定を行うための拡張です。
以下の例は、test.tclの測定をします。

package require sgxRSM
::sgxRSM::_Files_ test.tcl

測定結果は、コマンドとプロシジャのコール数がプロシジャ毎に出力されます。
コード行数と有効なコード行数とその割合が表示されます。
最後にSummaryとして、コマンドとプロシジャのコール総数が表示されます。

# ------------------------------------------------
Proc :	test_tvc
FPM  :	3	FRPM :	1	FC   :	22
LOC  :	142	eLOC :	57	SCUM :	149.1%

Calls:	62
	3	append
	1	array
	3	break
	1	expr
	1	for
	3	foreach
	3	global
	1	if
	2	incr
	1	info
	3	lappend
	4	list
	1	regexp
	1	regsub
	1	return
	1	scan
	16	set
	1	string
	7	subst
	3	unset
	2	upvar
	3	variable
# ------------------------------------------------

sgxTVC

変数の整合性テストを行うための拡張です。
以下の例は、test.tclをテストします。

package require sgxTVC
::sgxTVC::_Files_ test.tcl

テスト結果は、エラーと警告のある変数一覧が出力されます。

test_tvc	error	undef_14	variable undefined used by incr
test_tvc	error	undef_15	variable undefined used by unset
test_tvc	error	undef_16	variable undefined used by array
test_tvc	error	undef_17	variable undefined used by info
test_tvc	warning	append	bad style variable
test_tvc	warning	lappend	bad style variable
test_tvc	warning	incr	bad style variable
test_tvc	error	unused_01	variable undefined used by append
test_tvc	error	unused_02	variable undefined used by lappend
test_tvc	error	unused_00	argument unused
test_tvc	error	proc	argument unused
test_tvc	warning	proc	bad style argument
test_tvc	error	append	variable unused
test_tvc	warning	append	bad style variable
test_tvc	error	lappend	variable unused
test_tvc	warning	lappend	bad style variable
test_tvc	warning	set	bad style variable
test_tvc	error	incr	variable unused
test_tvc	warning	incr	bad style variable


sgxTools