sub profile_memory { use Devel::Gladiator (); use Devel::Size (); use Data::Dumper qw(Dumper); use Scalar::Util (); open(my $fh,">>/tmp/memory_profile_$$.log"); my $all=Devel::Gladiator::walk_arena(); my $size_hash={}; foreach my $sv ( @$all ) { next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($all); next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($size_hash); next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($fh); next if ref($sv) eq 'GLOB'; # Devel::Size segfaults on this my $size=0; eval { #warn(ref($sv)) unless ref($sv) eq 'SCALAR'; $size=Devel::Size::size($sv); #$size=Scalar::Util::refaddr($sv); }; next if $@; my $sv_list=$size_hash->{$size} || []; next if Scalar::Util::refaddr($sv) == Scalar::Util::refaddr($sv_list); push @$sv_list, $sv; $size_hash->{$size}=$sv_list; } print $fh ( "-" x 80 ) . "\n"; # print $fh Dumper($size_hash); foreach my $size ( sort { $b <=> $a } keys %$size_hash ) { foreach my $size ( keys %$size_hash ) { print $fh $size . '=['; foreach my $sv ( @{ $size_hash->{$size} } ) { print $fh ref($sv) . ", "; } print $fh ']' . "\n"; } close($fh); return 1; }