#!perl -w use strict; $|=1; use open IN => ':raw'; use Getopt::Long; my $ashex; my $summarizethreshold=0; GetOptions( "x"=>\$ashex, "s=s"=>\$summarizethreshold, ); sub readdata { local $/; return <>; } sub escape { return unpack 'H*', $_[0] if ($ashex); my $str=shift; my $quote=shift || "\""; $str =~ s/\\/\\\\/gs; $str =~ s/\x00/\\0/gs; $str =~ s/\x0d/\\r/gs; $str =~ s/\x0a/\\n/gs; $str =~ s/\x09/\\t/gs; $str =~ s/\x1b/\\e/gs; $str =~ s/$quote/\\$quote/gs; $str =~ s/./ord($&)<32||ord($&)>126 ? sprintf("\\x%02x", ord($&)) : $&/gse; return $str; } sub timestamp { my @f= unpack("v*", $_[0]); return sprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d", @f[0,1,3..7]); } my $data= readdata(); my $ofs=0; # first extract the log from the binary file in to an array of hashes my @log; while ($ofs+12$tick, o=>$ofs, dir=>$dir, size=>$size, data=>substr($data, $ofs+12, $size)}; $ofs += 12+$size; } # then sort the log, merging items that are less than 10 ms from each other my @log2; my @last=(); for (sort { $a->{t}<=>$b->{t} || $a->{o}<=>$b->{o} } @log) { my $l=$last[$_->{dir}]; if ($l && ($_->{t}-$l->{t}<$summarizethreshold)) { $l->{data} .= $_->{data}; $l->{size} += $_->{size}; push @{$l->{extents}}, {o=>$_->{ofs}, t=>$_->{t}, size=>$_->{size}}; } else { push @log2, $_; $last[$_->{dir}]= $_; } } @last=({},{}); my $p={}; my @plot; # array of 2 elems, containing arrays of hash with 'dt' and 's' for (@log2) { my $l=$last[$_->{dir}]; printf("%08lx(%6s)(%6s) %d %5d '%s'\n", $_->{t}, diffstr($_->{t},$p?$p->{t}:undef), diffstr($_->{t},$l?$l->{t}:undef), , $_->{dir}, $_->{size}, $_->{dir}==2 ? timestamp($_->{data}) : escape($_->{data}, "'")); push @{$plot[$_->{dir}]}, {dt=>(($l && $l->{t})?$_->{t}-$l->{t}:0) , s=>$_->{size} }; $p= $_; $last[$_->{dir}]= $_; } my @histogram; # array of 2dirs, containing hash of {dt,s} containing hash of total per decade for (my $d=0 ; $d<@plot ; $d++) { my $timesum=0; my $sizesum=0; my $t=0; printf("plottable data for direction %d\n", $d); for (my $n=1 ; $n<@{$plot[$d]} ; $n++) { $timesum+=$plot[$d][$n]{dt}; $sizesum+=$plot[$d][$n]{s}; if ($n>20) { $timesum -= $plot[$d][$n-20]{dt}; $sizesum -= $plot[$d][$n-20]{s}; printf("%8d, %5d, %5d, %5d\n", $t, $plot[$d][$n]{dt}, $plot[$d][$n]{s}, $sizesum/$timesum*8000); } else { printf("%8d, %5d, %5d\n", $t, $plot[$d][$n]{dt}, $plot[$d][$n]{s}); } $histogram[$d]{dt}[int($plot[$d][$n]{dt}/10)]++; $histogram[$d]{s}[int($plot[$d][$n]{s}/10)]++; $t += $plot[$d][$n]{dt}; } } # print histogram for (my $d=0 ; $d<@histogram ; $d++) { for my $type (keys %{$histogram[$d]}) { printf("histogram for direction %d, type %s\n", $d, $type); for (my $val=0 ; $val<@{$histogram[$d]{$type}} ; $val++) { printf("%5d : %3d\n", $val*10, $histogram[$d]{$type}[$val]) if ($histogram[$d]{$type}[$val]); } } } sub diffstr { return "" unless defined $_[0] && defined $_[1]; return sprintf("+%5d", $_[0]-$_[1]); }