Mercurial > pub > Impl
diff Lib/IMPL/Profiler/Memory.pm @ 49:16ada169ca75
migrating to the Eclipse IDE
author | wizard@linux-odin.local |
---|---|
date | Fri, 26 Feb 2010 10:49:21 +0300 |
parents | 03e58a454b20 |
children | 029c9610528c |
line wrap: on
line diff
--- a/Lib/IMPL/Profiler/Memory.pm Fri Feb 26 01:43:42 2010 +0300 +++ b/Lib/IMPL/Profiler/Memory.pm Fri Feb 26 10:49:21 2010 +0300 @@ -1,57 +1,57 @@ -package IMPL::Profiler::Memory; - -use strict; -use Carp qw(longmess shortmess); -use Scalar::Util qw(refaddr weaken isweak); - -my %instances; - -BEGIN { - *CORE::GLOBAL::bless = sub { - $_[1] |= caller unless $_[1]; - my $ref = CORE::bless $_[0],$_[1]; - - my $id = refaddr($ref); - - $instances{$id} = { - Class => $_[1], - WeakRef => $ref - }; - - weaken($instances{$id}{WeakRef}); - - return $ref; - } -} - -sub DumpAlive { - my ($hout) = @_; - $hout = *STDOUT unless $hout; - print $hout "Alive objects table\n"; - print $hout "-------------------\n"; - while (my ($id,$info) = each %instances) { - delete $instances{$id} and next unless $info->{WeakRef}; - print "$info->{Class} $id: $info->{WeakRef}\n"; - } -} - -sub StatClasses { - my ($hout) = @_; - $hout = *STDOUT unless $hout; - print $hout "Statistics by class\n"; - print $hout "-------------------\n"; - my %stat; - while (my ($id,$info) = each %instances) { - #$stat{$info->{Class}}{total} ++; - delete $instances{$id} and next unless $info->{WeakRef}; - $stat{$info->{Class}}{alive} ++; - } - - print $hout "$_ $stat{$_}{alive} \n" foreach sort keys %stat; -} - -sub Clear { - undef %instances; -} - -1; \ No newline at end of file +package IMPL::Profiler::Memory; + +use strict; +use Carp qw(longmess shortmess); +use Scalar::Util qw(refaddr weaken isweak); + +my %instances; + +BEGIN { + *CORE::GLOBAL::bless = sub { + $_[1] |= caller unless $_[1]; + my $ref = CORE::bless $_[0],$_[1]; + + my $id = refaddr($ref); + + $instances{$id} = { + Class => $_[1], + WeakRef => $ref + }; + + weaken($instances{$id}{WeakRef}); + + return $ref; + } +} + +sub DumpAlive { + my ($hout) = @_; + $hout = *STDOUT unless $hout; + print $hout "Alive objects table\n"; + print $hout "-------------------\n"; + while (my ($id,$info) = each %instances) { + delete $instances{$id} and next unless $info->{WeakRef}; + print "$info->{Class} $id: $info->{WeakRef}\n"; + } +} + +sub StatClasses { + my ($hout) = @_; + $hout = *STDOUT unless $hout; + print $hout "Statistics by class\n"; + print $hout "-------------------\n"; + my %stat; + while (my ($id,$info) = each %instances) { + #$stat{$info->{Class}}{total} ++; + delete $instances{$id} and next unless $info->{WeakRef}; + $stat{$info->{Class}}{alive} ++; + } + + print $hout "$_ $stat{$_}{alive} \n" foreach sort keys %stat; +} + +sub Clear { + undef %instances; +} + +1;