Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

p6spy hog report script

2008-03-26
2013-04-25
  • David Bennett
    David Bennett
    2008-03-26

    This perl script shows hogs.  Call like this:

      ./p6spylogtophogs.pl < spy.log  > hog_report.txt

    <pre>
    #!/usr/bin/perl -w
    use strict;

    use Digest::MD5 qw(md5 md5_hex md5_base64);

    my %hogs;
    my %hogtime;
    my %hogcount;

    # read the data
    while (<>) {
      chomp;
      my($ct,$et,$cat,$num,$stmt,$prep)=split(/\|/);
      my $key=md5_base64($stmt);

      $hogtime{$key} += $et;
      $hogcount{$key}++;
      $hogs{$key}=$stmt;
    }

    # output the hogs

    print "Total Time\tQueries\tStatement\n";
    print "----------\t-------\t---------\n";

    my $key;
    foreach $key (sort by_value keys %hogtime) {
      print "$hogtime{$key}\t\t$hogcount{$key}\t$hogs{$key}\n";
    }
    sub by_value { $hogtime{$b} <=> $hogtime{$a}; }
    </pre>

    --Dave