]> git.sesse.net Git - bursty/blob - summarize.pl
Cleanup in summarize.pl.
[bursty] / summarize.pl
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my %buckets = ();
7
8 while (<>) {
9         chomp;
10         my (@x) = split /\s+/, $_;
11
12         my $num_packets = scalar @x;
13         my $num_drops = grep { /\*/ } @x;
14
15         $buckets{$num_packets}->{'num_bursts'}++;
16         $buckets{$num_packets}->{'num_drops'} += $num_drops;
17         if ($num_drops > 0) {
18                 $buckets{$num_packets}->{'bursts_with_drops'}++;
19         }
20 }
21
22 for my $n (sort { $a <=> $b } keys %buckets) {
23         my $num_bursts = $buckets{$n}->{'num_bursts'} // 0;
24         my $num_drops = $buckets{$n}->{'num_drops'} // 0;
25         my $bursts_with_drops = $buckets{$n}->{'bursts_with_drops'} // 0;
26
27         my $drop_rate = $num_drops / ($n * $num_bursts);
28         my $drop_event_rate = $bursts_with_drops / $num_bursts;
29         printf "%3d: drop_rate %.5f  drop_event_rate %.5f\n",
30                 $n, $drop_rate, $drop_event_rate; 
31 }