03c4d863dfb1a014ca5514e28372263a0aba39e8
[swifty.git] / src / libswift_udp / mfold / logparse
1 #!/usr/bin/perl -w
2
3 $SERVER=shift;
4 %PORTS = ();
5 %HOSTS = ();
6 %CHANN = ( "#0" => "none" );
7 %EVENTS = ( "#0" => {"+hs"=>0} );
8 %SENT = ();
9 %RCVD = ();
10 %DSENT = ();
11 %DRCVD = ();
12 %CWNDLOG = ();
13 %RTTLOG = ();
14 %OWDLOG = ();
15 %TDATALOG = ();
16 %RDATALOG = ();
17 %INDATALOG = ();
18 $SENTB = 0;
19 $RCVDB = 0;
20
21 open(SRVP,$ENV{"HOME"}."/swift/mfold/servers.txt") or die;
22 while (<SRVP>) {
23     /(\S+):(\d+)/ or next;
24     $PORTS{$1} = $2;
25 }
26 close SRVP;
27
28 open(SRV,$ENV{"HOME"}."/.ssh/config") or die;
29 while (<SRV>) {
30     if (/Host (\S+)/) {
31         $srvname=$1;
32         $port = $PORTS{$srvname};
33     }
34     $HOSTS{$1}{$port}=$srvname if /HostName (\S+)/ && $port;
35 }
36 close SRV;
37
38 while (<>) {
39     /(\d+_\d+_\d+_\d+_\d+) (#\d+) (\S+) (.*)/ or next;
40     my $time = $1;
41     my $channel = $2;
42     my $event = $3;
43     my $rest = $4;
44     my $host = $CHANN{"$channel"};
45     $host = "unknown" if not $host;
46     $time =~ /^(\d+)_(\d+)_(\d+)_(\d+)/;
47     my $ms=$1*60; $ms=($ms+$2)*60; $ms=($ms+$3)*1000; $ms+=$4;
48     if ($event eq "sent") {
49         $rest =~ /(\d+)b ([\d\.]+):(\d+):/;
50         $ip = $2;
51         $port = $3;
52         $host = $HOSTS{$ip}{$port};
53         #$SENT{$h} = 0 if not exists $SENT{$h};
54         $SENT{$host} += $1;
55         $SENTB += $1;
56         $DSENT{$host}++;
57         $CHANN{"$channel"} = $host;
58     } elsif ($event eq "recvd") {
59         $rest =~ /(\d+)/;
60         #$RCVD{$h} = 0 if not exists $RCVD{$h};
61         $DRCVD{$host}++;
62         $RCVD{$host} += $1;
63         $RCVDB += $1;
64     } elsif ($event eq "sendctrl") {
65         if ($rest =~ /cwnd (\d+\.\d+).*data_out (\d+)/) {
66             if (not exists $CWNDLOG{$host}) {
67                 open(my $handle, '>', "$SERVER-harvest/$SERVER-$host-cwnd.log") or die;
68                 $CWNDLOG{$host} = $handle;
69             }
70             print {$CWNDLOG{$host}} "$ms\t$1\t$2\n";
71         } elsif ($rest =~ /ledbat (\-?\d+)\-(\-?\d+)/) {
72             if (not exists $OWDLOG{$host}) {
73                 open(my $handle, '>', "$SERVER-harvest/$SERVER-$host-owd.log") or die;
74                 $OWDLOG{$host} = $handle;
75             }
76             print {$OWDLOG{$host}} "$ms\t$1\t$2\n";
77         } elsif ($rest =~ /rtt (\d+) dev (\d+)/) {
78             if (not exists $RTTLOG{$host}) {
79                 open(my $handle, '>', "$SERVER-harvest/$SERVER-$host-rtt.log") or die;
80                 $RTTLOG{$host} = $handle;
81             }
82             print {$RTTLOG{$host}} "$ms\t$1\t$2\n";
83         }
84     } elsif ($event eq "Tdata") {
85         if (not exists $TDATALOG{$host}) {
86             open(my $handle, '>', "$SERVER-harvest/$SERVER-$host-tdata.log") or die;
87             $TDATALOG{$host} = $handle;
88         }
89         print {$TDATALOG{$host}} "$ms\n";
90     } elsif ($event eq "Rdata") {
91         if (not exists $RDATALOG{$host}) {
92             open(my $handle, '>', "$SERVER-harvest/$SERVER-$host-rdata.log") or die;
93             $RDATALOG{$host} = $handle;
94         }
95         print {$RDATALOG{$host}} "$ms\n";
96     } elsif ($event eq "-data" && $rest =~ /\(0,(\d+)\)/) {
97         my $bin = $1;
98         if (not exists $INDATALOG{$host}) {
99             open(my $handle, '>', "$SERVER-harvest/$SERVER-$host-indata.log") or die;
100             $INDATALOG{$host} = $handle;
101         }
102         print {$INDATALOG{$host}} "$bin\t$ms\n";
103     }
104     $EVENTS{"$host"} = { "+hs"=>0 } if not exists $EVENTS{"$host"};
105     
106     print "$time $SERVER $host$channel $event $rest\n";
107
108     # DO STATS
109     $EVENTS{"$host"}{"$event"} = 0 if not exists $EVENTS{"$host"}{"$event"};
110     $EVENTS{"$host"}{"$event"}++;
111
112 }
113
114 for $host (keys %CWNDLOG) {
115     close($CWNDLOG{$host});
116 }
117 for $host (keys %OWDLOG) {
118     close ($OWDLOG{$host});
119 }
120 for $host (keys %RTTLOG) {
121     close ($RTTLOG{$host});
122 }
123 for $host (keys %TDATALOG) {
124     close ($TDATALOG{$host});
125 }
126 for $host (keys %RDATALOG) {
127     close ($RDATALOG{$host});
128 }
129 for $host (keys %INDATALOG) {
130     close ($INDATALOG{$host});
131 }
132
133 open(LEGEND,"> $SERVER-harvest/$SERVER-legend.txt") or die;
134
135 for $channel (keys %CHANN) {
136     my $host = $CHANN{"$channel"};
137     print LEGEND "$channel\t$host\n";
138     open(STATS,"> $SERVER-harvest/$SERVER-$host.stat") or die;
139     my %events = %{ $EVENTS{"$host"} };
140     for $event ( keys %events ) {
141         print STATS "$event\t".($events{"$event"})."\n";
142     }
143     close STATS;
144     open(HTML,"> $SERVER-harvest/$SERVER-$host.html") or die;
145     print HTML "<table class='channel'><th><td>sent</td><td>rcvd</td></th>\n";
146     my $rcvd = $RCVD{$host};
147     my $sent = $SENT{$host};
148     $rcvd=0.001 if not $rcvd;
149     $sent=0.001 if not $sent;
150     printf HTML 
151         "<tr class='bytes'><td>bytes</td><td>%i/<pp>%.1f%%</pp></td>".
152         "<td>%i/<pp>%.1f%%</pp></td></tr>\n",
153         $sent, $SENTB?$sent/$SENTB*100:0, $rcvd, $RCVDB?$rcvd/$RCVDB*100:0;
154     print HTML
155         "<tr><td>dgrams</td><td>".$DSENT{$host}."</td><td>".$DRCVD{$host}."</td></tr>\n";
156     printf HTML
157         "<tr><td>data</td><td>%i/<pp><b>%.1f%%</b></pp></td><td>%i/<pp><b>%.1f%%</b></pp></td></tr>\n",
158         $events{"+data"}, ($events{"+data"}*1029)/$sent*100,
159         $events{"-data"}, ($events{"-data"}*1029)/$rcvd*100;
160     printf HTML
161         "<tr><td>hash</td><td>%i/<pp>%.1f%%</pp></td><td>%i/<pp>%.1f%%</pp></td></tr>\n",
162         $events{"+hash"}, ($events{"+hash"}*25)/$sent*100,
163         $events{"-hash"}, ($events{"-hash"}*25)/$rcvd*100;
164     printf HTML
165         "<tr><td>ack</td><td>%i/<pp>%.1f%%</pp></td><td>%i/<pp>%.1f%%</pp></td></tr>\n",
166         $events{"+ack"}, ($events{"+ack"}*5)/$sent*100,
167         $events{"-ack"}, ($events{"-ack"}*5)/$rcvd*100;
168     printf HTML
169         "<tr><td>hint</td><td>%i/<pp>%.1f%%</pp></td><td>%i/<pp>%.1f%%</pp></td></tr>\n",
170         $events{"+hint"}, ($events{"+hint"}*5)/$sent*100,
171         $events{"-hint"}, ($events{"-hint"}*5)/$rcvd*100;
172     printf HTML
173         "<tr><td>hs</td><td>%i</td><td>%i</td></tr>\n",
174         $events{"+hs"}, $events{"-hs"};
175     my $losses = $events{"+data"}>0 ? 
176         ($events{"Rdata"}+$events{"Tdata"})/$events{"+data"}*100 : 0;
177     printf HTML
178         "<tr><td>losses</td><td colspan='2'>R:%i+T:%i=%i/<pp>%.1f%%</pp></td></tr>\n",
179         $events{"Rdata"}, $events{"Tdata"},
180         $events{"Rdata"}+$events{"Tdata"}, $losses;
181
182     print HTML "</table>\n";
183     close HTML;
184 }
185 close LEGEND;