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