File: perl_bloat.pl

package info (click to toggle)
libapache2-mod-perl2 2.0.4-7%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 9,896 kB
  • ctags: 3,820
  • sloc: perl: 56,663; ansic: 14,001; makefile: 93; sh: 38
file content (43 lines) | stat: -rwxr-xr-x 762 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w

# perlbloat.pl 'some perlcode' 'more perl code'
# perlbloat.pl Foo/Bar.pm Bar/Tar.pm
# perlbloat.pl Foo::Bar Bar::Tar

no warnings;

use GTop ();

my $gtop = GTop->new;

my $total = 0;
for (@ARGV) {

    my $code = $_;
    file2package($_) if /\S+\.pm$/;

    my $before = $gtop->proc_mem($$)->size;

    if (eval "require $_" ) {
        eval {
            $_->import;
        };
    }
    else {
        eval $_;
        die $@ if $@;
    }

    my $after = $gtop->proc_mem($$)->size;
    printf "%-30s added %s\n", $_, GTop::size_string($after - $before);
    $total += $after - $before;
}

print "-" x 46, "\n";
printf "Total added %30s\n", GTop::size_string($total);

sub file2package {
    $_[0] =~ s|/|::|g;
    $_[0] =~ s|\.pm$||;
}