|
1 #!/usr/bin/tclsh |
|
2 # |
|
3 # process-log.tcl |
|
4 # |
|
5 # Parse through the dtnsim_log.txt output and generate an aggregated |
|
6 # summary of the various statistics. |
|
7 |
|
8 set summary 0 |
|
9 set ignore "" |
|
10 |
|
11 for {set i 0} {$i < [llength $argv]} {incr i} { |
|
12 set arg [lindex $argv $i] |
|
13 switch -- $arg { |
|
14 -summary - |
|
15 --summary { set summary 1 } |
|
16 |
|
17 -ignore - |
|
18 --ignore { lappend ignore [lindex $argv [incr i]] } |
|
19 |
|
20 default {puts "unknown argument $arg"; exit 1} |
|
21 } |
|
22 } |
|
23 |
|
24 array set counts {} |
|
25 array set delays {} |
|
26 |
|
27 while {![eof stdin]} { |
|
28 set L [gets stdin] |
|
29 |
|
30 foreach {time node what source dest creation_ts length delay} \ |
|
31 [split $L \t] { |
|
32 |
|
33 # hack to consolidate routing messages destined for |
|
34 # dtn://*/dtlsr?lsa_seqno=N into a single class |
|
35 regsub {\?(.*)seqno=[\d]+} $dest {?\1seqno=*} dest |
|
36 |
|
37 if {![info exists counts($node,$source,$dest,$what)]} { |
|
38 set counts($node,$source,$dest,$what) 1 |
|
39 } else { |
|
40 incr counts($node,$source,$dest,$what) |
|
41 } |
|
42 |
|
43 if {$what == "ARR"} { |
|
44 if {![info exists delays($node,$source,$dest)]} { |
|
45 set delays($node,$source,$dest) $delay |
|
46 } else { |
|
47 incr delays($node,$source,$dest) $delay |
|
48 } |
|
49 } |
|
50 } |
|
51 } |
|
52 |
|
53 set types {RECV XMIT DUP GEN ARR EXP INQ delay} |
|
54 |
|
55 foreach what $types { |
|
56 set total($what) 0 |
|
57 } |
|
58 |
|
59 set last_node "" |
|
60 set last_source "" |
|
61 set last_dest "" |
|
62 |
|
63 foreach key [lsort [array names counts]] { |
|
64 foreach {node source dest what} [split $key , ] {} |
|
65 |
|
66 set ign 0 |
|
67 foreach pat $ignore { |
|
68 if {[string match $pat $dest] || [string match $dest $pat]} { |
|
69 set ign 1 |
|
70 break |
|
71 } |
|
72 } |
|
73 if {$ign} { continue } |
|
74 |
|
75 if {! $summary} { |
|
76 if {$last_node != $node || $last_source != $source || $last_dest != $dest} { |
|
77 set last_node $node |
|
78 set last_source $source |
|
79 set last_dest $dest |
|
80 puts "$node: $source -> $dest:" |
|
81 } |
|
82 |
|
83 puts "\t$what: $counts($key)" |
|
84 } |
|
85 incr total($what) $counts($key) |
|
86 |
|
87 if [info exists delays($node,$source,$dest)] { |
|
88 incr total(delay) $delays($node,$source,$dest) |
|
89 } |
|
90 } |
|
91 |
|
92 puts "------" |
|
93 foreach what $types { |
|
94 puts "$what total: $total($what)" |
|
95 } |