]> hydra-www.ietfng.org Git - instirc/commitdiff
Add stats.pl, a simplistic statistics collector main
authornwf <nwf@cs.jhu.edu>
Fri, 28 Aug 2009 07:06:57 +0000 (03:06 -0400)
committernwf <nwf@cs.jhu.edu>
Fri, 28 Aug 2009 07:06:57 +0000 (03:06 -0400)
Ignore-this: 592d472d2083480548d346757e15d7cd

darcs-hash:20090828070657-4d648-b7cfedec828d0dd96e8cae0643de29a3cae43038.gz

stats.pl [new file with mode: 0644]

diff --git a/stats.pl b/stats.pl
new file mode 100644 (file)
index 0000000..501bf89
--- /dev/null
+++ b/stats.pl
@@ -0,0 +1,69 @@
+use strict;
+
+use Data::Dumper;
+use Instance::Definitions qw( %known_types
+                    @default_code_chars
+                    $instance_huffman_table1
+                    $MESSAGE_START $MESSAGE_END );
+require Instance::MasterCoder;
+require Instance::HuffmanCoder;
+use Instance::Protoutils qw( dump_message );
+
+my $mc = Instance::MasterCoder->new(\@default_code_chars, $MESSAGE_START, $MESSAGE_END);
+my $hc = Instance::HuffmanCoder->new($mc, $instance_huffman_table1);
+
+my $cmsg_from;
+
+my $taglines = 0;
+my %tags = ( );
+sub cb_it ($$) {
+    my ($t,$v) = @_;
+    die unless $t = $known_types{'InstanceLabelHuffman1'};
+
+    $taglines++;
+
+    my $dcv = $hc->decode($v);
+    $tags{$dcv} = 0 if not exists $tags{$dcv};
+    $tags{$dcv}++;
+}
+
+my $botlines = 0;
+my %bots = ( );
+sub cb_mmf ($$) {
+    my ($t,$v) = @_;
+    my $dcv = $mc->tdecode($v);
+    my $is_bot = $dcv & 1 if ($dcv > 2);
+
+    if($is_bot) {
+        $botlines++;
+        $bots{$cmsg_from}++ if defined $cmsg_from;
+    }
+}
+
+
+while(my $text = <STDIN>) {
+    chomp $text;
+
+    # CTCP
+    $text =~ s/\ 1//g;
+
+    $cmsg_from = $text =~ /^([^<]*<\s*([^>]+)>|.*-!- ([^ ]+) )/
+                    ? ($2 or $3) : undef;
+
+    my ($succ, $rem) = $mc->tlv_run_callbacks(
+        {
+            $known_types{'InstanceLabelHuffman1'} => \&cb_it,
+            $known_types{'MiscMessageFlags'} => \&cb_mmf,
+        },
+        $text
+    );
+}
+
+print "TOTAL OF $taglines INSTANCE LABELS:\n";
+foreach my $l (sort { $tags{$b} <=> $tags{$a} } (keys %tags)) {
+    print "  $l : $tags{$l}\n";
+}
+print "TOTAL OF $botlines MMF BOT TAGS:\n";
+foreach my $b (sort { $bots{$b} <=> $bots{$a} } (keys %bots)) {
+    print "  $b : $bots{$b}\n";
+}