yuu_nkjm blog
2008-09-06(Sat) 編集
[Linux][Network][Troubleshooting] digのtraceオプションでDNSの再帰的問い合わせの状況を調べる
digにtraceオプションをつけると,DNSに関する最後の問い合わせ結果だけでなく,途中の様子が見られる.openSUSE10.3のdigのmanをみても出ていなかった気がするけど使えた.
ICMP系のパケットフィルタリングをしている環境下では使えないことがある.
[nkjm@localhost ~]$ dig +trace yahoo.com ; <<>> DiG 9.4.1-P1 <<>> +trace yahoo.com ;; global options: printcmd . 181704 IN NS J.ROOT-SERVERS.NET. (中略) . 181704 IN NS K.ROOT-SERVERS.NET. ;; Received 500 bytes from 10.228.150.254#53(10.228.150.254) in 9 ms com. 172800 IN NS C.GTLD-SERVERS.NET. (中略) com. 172800 IN NS E.GTLD-SERVERS.NET. ;; Received 487 bytes from 202.12.27.33#53(M.ROOT-SERVERS.NET) in 38 ms yahoo.com. 172800 IN NS ns1.yahoo.com. (中略) yahoo.com. 172800 IN NS ns5.yahoo.com. ;; Received 197 bytes from 192.52.178.30#53(K.GTLD-SERVERS.NET) in 322 ms yahoo.com. 21600 IN A 206.190.60.37 (中略) yahoo.com. 172800 IN NS ns8.yahoo.com. ;; Received 297 bytes from 66.218.71.63#53(ns1.yahoo.com) in 136 ms
[ツッコミを入れる]
2010-09-06(Mon) 編集
[R言語] Rでアサーション
Javaでプログラミングをする時にassertをよく使う.しかし,R言語にはassert構文や関数がなさそうだった.単体テスト用スクリプト@つれづれ:R言語Tipsで自前のassert関数が公開されているのを見かけたので,ちょっと改造してみた.
assert <- function( condition, msg="") {
if ( is.na( condition ) ) {
cat("-------------------------------------\n")
cat( "assert fail, condition is na\n\t")
cat("msg: \t")
cat(msg)
cat("\n")
traceback()
cat("-------------------------------------\n")
return(FALSE)
}
if ( condition == FALSE ) {
cat("-------------------------------------\n")
cat("assert fail:\n\t", sep="")
print(substitute(condition))
cat("\t\t is expected TRUE but it is FALSE\n", sep="" )
cat("msg: \t")
eval(expression(msg))
cat("\n")
traceback()
cat("-------------------------------------\n")
return(FALSE)
}
return(TRUE)
}
↓こんな使い方を想定.第一引数が判定条件,第二引数が判定条件がFALSEだったときに評価される式.
式は一つしかかけないけど,ブロック{}を使えば複数書ける.
assert(hoge!=0) #hogeは0でない.
assert(hoge!=0, print(hoge)) #hogeは0でない.0だったら,print(hoge)
assert(hoge!=0, recover()) #recoverも便利
assert(hoge!=0, {print(hoge);recover()}) #ブロックを使う
if(!assert(hoge!=0)){ #返り値を使ってif文で分岐
print(hoge)
recover()
}
tracebackの挙動がよくわからん.思うところは色々あるが,ひとまず使ってみよう.
hoge <- 5
assert(hoge==0, print(hoge))
-------------------------------------
assert fail:
hoge == 0
is expected TRUE but it is FALSE
msg: [1] 5
No traceback available
-------------------------------------
[ツッコミを入れる]