Документация
HTML CSS PHP PERL другое

smallprofpp

 
Previous Table of Contents Next

smallprofpp


#!/usr/bin/perl

use strict;

use warnings;



use Getopt::Std;

my $USAGE = "Usage: $0 [-c|-w] [profile]\n";

my $MAXLEN = 80;



getopts('cw', \my %opt) or die $USAGE;



my $profile = shift || 'smallprof.out';

open my $fh, '<', $profile

  or die "Can't open profile: $!\n";



my ($header, $filename, @to_sort);

while (<$fh>)

{

  $header = $_, next if /^\s+count/;

  $filename = $1, next if /^\s+Profile of (.*?\S)\s+Page/;

  /^\s+(\d+)\s+([\d.]+)\s+([\d.]+)\s+\d+:/

    and $1 and push @to_sort, [ $_, $2, $3, $filename ];

}

my $which = $opt{c} ? 2 : 1;       # Default: wall clock time

my $other = $which == 1 ? 2 : 1;   # The other time

print $header,

      map  { (my $line = $_->[0]) =~ s/\b\s+(\d+):.*/ /s;

             my $fileline = "$_->[3]:$1";

             if (length($fileline) + length($line) > $MAXLEN)

             {

               substr($fileline,

                      0,

                      length($fileline)+length($line)-$MAXLEN+3,

                      '...');

             }

             "$line$fileline\n";

           }

      sort {   $b->[$which] <=> $a->[$which]

            || $b->[$other] <=> $a->[$other]

           } @to_sort;



__END__



=head1 NAME



smallprofpp - sort profile data from Devel::SmallProf



=head1 SYNOPSIS



smallprofpp [B<-c>|B<-w>] [profile]



=head1 DESCRIPTION



The I<smallprofpp> command sorts and outputs the named file

(default C<smallprof.out>) produced by Devel::SmallProf. Page

headings are removed and only one header line will be printed;

no lines will be printed for source code lines that were never

called (you can prevent Devel::SmallProf from outputting them

in the first place with the statement



  $DB::drop_zeros = 1



which may be placed in a C<.smallprof> file; see

Devel::SmallProf).  Lines will be sorted in descending order

of either cpu time or wall clock time; ties will be sorted by

the other time.



=head1 OPTIONS



=over 4



=item B<-c>



Sort first by cpu time, second by wall clock time.



=item B<-w>



Sort first by wall clock time, second by cpu time.  This is the

default.



=back



=head1 SEE ALSO



L<Devel::SmallProf>.

    Previous Table of Contents Next
    © 2000- NIV