From: Tim Bunce Date: Tue, 2 Oct 2012 14:54:31 +0000 (+0100) Subject: Rename to Devel::SizeMe X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eda23e249e0d33e6d3d071b81ab38e1c523a0fc2;p=p5sagit%2FDevel-Size.git Rename to Devel::SizeMe --- diff --git a/.gitignore b/.gitignore index 1fbab34..478c4b0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ MYMETA.json MYMETA.yml Makefile Makefile.old -Memory.[co] -Memory.bs +SizeMe.[co] +SizeMe.bs diff --git a/CHANGES b/CHANGES index 687688c..95b893e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,10 @@ Revision history for Perl extension Devel::Memory. +0.02 2012-10-02 Tim Bunce + + * Renamed to Devel::SizeMe. + * Assorted fixes, cleanups and polish. + 0.01 2012-09-29 Tim Bunce * Created new Devel::Memory extension using a modified version of diff --git a/MANIFEST b/MANIFEST index c07983a..749ddfe 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,11 +1,11 @@ CHANGES -lib/Devel/Memory.pm +lib/Devel/SizeMe.pm Makefile.PL MANIFEST MANIFEST.SKIP META.yml Module meta-data (added by MakeMaker) README -Memory.xs +SizeMe.xs ppport.h t/basic.t t/code.t diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 3c0fc26..2c8f55a 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -5,12 +5,12 @@ # # command. # -^Devel-Memory.*\.tar\.gz +^Devel-SizeMe.*\.tar\.gz ^Makefile.old ^Makefile\z ^pm_to_blib ^MANIFEST.(bak|old) -^Memory.(c|o|bs) +^SizeMe.(c|o|bs) ^blib.* tmon.out \.txt\z diff --git a/Makefile.PL b/Makefile.PL index de23be8..e27fe4c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -10,8 +10,8 @@ my $ptr_bits = length $1; WriteMakefile( OPTIMIZE => "-g", - NAME => 'Devel::Memory', - VERSION_FROM => 'lib/Devel/Memory.pm', + NAME => 'Devel::SizeMe', + VERSION_FROM => 'lib/Devel/SizeMe.pm', DEFINE => "-DALIGN_BITS=$ptr_bits", PREREQ_PM => { 'Test::More' => 0, diff --git a/README b/README index 2fc4357..d8a3a0e 100644 --- a/README +++ b/README @@ -1,6 +1,5 @@ TODO - Rename to Devel::SizeMe Devel::SizeMe::Core - loads XS and sets options Devel::SizeMe - loads XS -d:SizeMe=opts @@ -26,11 +25,11 @@ Future =pod -Devel::Memory - Perl extension for finding the memory usage of Perl variables +Devel::SizeMe - Perl extension for finding the memory usage of Perl variables =head1 SYNOPSIS - use Devel::Memory qw(size total_size); + use Devel::SizeMe qw(size total_size); my $size = size("A string"); my @foo = (1, 2, 3, 4, 5); @@ -107,12 +106,15 @@ On Windows: Please report bugs to: - http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-Memory + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-SizeMe =head1 COPYRIGHT -Copyright (C) 2005 Dan Sugalski, Copyright (C) 2007-2008 Tels, -Copyright (C) 2011-2012 Nicholas Clark, Copyright 2012 (C) Tim Bunce. +Copyright (C) 2005 Dan Sugalski, +Copyright (C) 2007-2008 Tels, +Copyright (C) 2008 BrowserUK, +Copyright (C) 2011-2012 Nicholas Clark, +Copyright (C) 2012 Tim Bunce. This module is free software; you can redistribute it and/or modify it under the same terms as Perl v5.8.8. diff --git a/Memory.xs b/SizeMe.xs similarity index 99% rename from Memory.xs rename to SizeMe.xs index dd961e3..a887fe0 100644 --- a/Memory.xs +++ b/SizeMe.xs @@ -1482,7 +1482,7 @@ perl_size(pTHX_ struct state *const st, pPATH) } -MODULE = Devel::Memory PACKAGE = Devel::Memory +MODULE = Devel::SizeMe PACKAGE = Devel::SizeMe PROTOTYPES: DISABLE diff --git a/bin/sizeme_store.pl b/bin/sizeme_store.pl index b361007..f9f7e65 100755 --- a/bin/sizeme_store.pl +++ b/bin/sizeme_store.pl @@ -100,8 +100,8 @@ sub enter_node { if ($x->{name} eq 'AVelem' and $parent->{name} eq 'SV(PVAV)') { my $index = $x->{attr}{+NPattr_NOTE}{i}; - Dwarn $x->{attr}; - Dwarn $index; + #Dwarn $x->{attr}; + #Dwarn $index; # If node is an AVelem of a CvPADLIST propagate pad name to AVelem if (@stack >= 4 and (my $cvpl = $stack[-4])->{name} eq 'CvPADLIST') { my $padnames = $cvpl->{_cached}{padnames} ||= do { @@ -267,7 +267,7 @@ while (<>) { warn "Node $id already has attribute $type:$name (value $attr->{$type}{$name})\n" if exists $attr->{$type}{$name}; $attr->{$type}{$name} = $val; - Dwarn $attr; + #Dwarn $attr; $node->{title} = $name if $type == NPattr_NAME and !$val; # XXX hack } # attributes where the number is a key (or always zero) @@ -324,11 +324,14 @@ while (<>) { my $top = $stack[0]; # grab top node before we pop all the nodes leave_node(pop @stack) while @stack; + # if nothing output (ie size(undef)) + $top ||= { self_size=>0, kids_size=>0, kids_node_count=>0 }; + my $top_size = $top->{self_size}+$top->{kids_size}; - printf "Stored %d nodes (${.}n) sizing %s (%d) in %.2fs\n", - $top->{kids_node_count}, fmt_size($top_size), $top_size, - $val; + printf "Stored %d nodes totalling %s [lines=%d size=%d write=%.2fs]\n", + 1+$top->{kids_node_count}, fmt_size($top_size), + $., $top_size, $val; # the duration here ($val) is from Devel::SizeMe perspective # ie doesn't include time to read file/pipe and commit to database. diff --git a/lib/Devel/Memory.pm b/lib/Devel/Memory.pm deleted file mode 100644 index 6572deb..0000000 --- a/lib/Devel/Memory.pm +++ /dev/null @@ -1,100 +0,0 @@ -package Devel::Memory; - -use strict; -use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS $warn $dangle); - -require 5.005; -require Exporter; -require XSLoader; - -@ISA = qw(Exporter); - -@EXPORT_OK = qw(size total_size perl_size); - -# This allows declaration use Devel::Memory ':all'; -%EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); - -$VERSION = '0.01'; - -XSLoader::load( __PACKAGE__); - -$warn = 1; -$dangle = 0; ## Set true to enable warnings about dangling pointers - -1; -__END__ - -=pod - -Devel::Memory - Perl extension for finding the memory usage of Perl variables - -=head1 SYNOPSIS - - use Devel::Memory qw(size total_size); - - my $size = size("A string"); - my @foo = (1, 2, 3, 4, 5); - my $other_size = size(\@foo); - my $total_size = total_size( $ref_to_data ); - -=head1 DESCRIPTION - -Acts like Devel::Size 0.77 if the PERL_DMEM env var is not set. - -Except that it also provides perl_size() and heap_size() functions. - -If PERL_DMEM env var is set to an empty string then all the *_size functions -dump a textual representation of the memory data to stderr. - -If PERL_DMEM env var is set to a string that starts with "|" then the -remainder of the string is taken to be a command name and popen() is used to -start the command and the raw memory data is piped to it. - -If PERL_DMEM env var is set to anything else it is treated as the name of a -file the raw memory data should be written to. - -The dmemtree.pl script can be used to process the raw memory data. -Typically run via the PERL_DMEM env var. For example: - - export PERL_DMEM='|./dmemtree.pl --text' - export PERL_DMEM='|./dmemtree.pl --dot=dmemtree.dot' - export PERL_DMEM='|./dmemtree.pl --db=dmemtree.db' - -The --text output is similar to the textual representation output by the module -when the PERL_DMEM env var is set to an empty string. - -The --dot output is suitable for feeding to Graphviz. - -The --db output is a SQLite database. (Very subject to change.) - -Example usage: - - PERL_DMEM='|dmemtree.pl --db=dmemtree.db' perl -MDevel::Memory=:all -e 'total_size(sub { })' - -The dmemview.pl script is a Mojolicious::Lite application that serves data to -an interactive treemap visualization of the memory use. It can be run as: - - dmemview.pl daemon - -and then open http://127.0.0.1:3000 - -Please report bugs to: - - http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-Memory - -=head1 COPYRIGHT - -Copyright (C) 2005 Dan Sugalski, -Copyright (C) 2007-2008 Tels, -Copyright (C) BrowserUK 2008, -Copyright (C) 2011-2012 Nicholas Clark, -Copyright (C) 2012 Tim Bunce. - -This module is free software; you can redistribute it and/or modify it -under the same terms as Perl v5.8.8. - -=head1 SEE ALSO - -perl(1), L. - -=cut diff --git a/lib/Devel/SizeMe.pm b/lib/Devel/SizeMe.pm index 81e4a88..5391e81 100644 --- a/lib/Devel/SizeMe.pm +++ b/lib/Devel/SizeMe.pm @@ -1,28 +1,119 @@ package Devel::SizeMe; -require Devel::Memory; - -my $gz = (0) ? "gzip -c | gzip -dc |" : ""; # currently saves ~3% -$ENV{SIZEME} = "| $gz sizeme_store.pl -d --text --dot=sizeme.dot --showid --db=sizeme.db"; - -my $do_size_at_end = 0; # set true below for "perl -d:SizeMe ..." - -# It's handy to say "perl -d:SizeMe" but has side effects -# currently we simple disable the debugger (as best we can) -# otherwise it (or rather some bits of $^P) cause memory bloat. -# we might want to provide some smarter compatibility in future. -# We might also want to provide a way to set some bits, such as -# 0x10 Keep info about source lines on which a sub is defined -# 0x100 Provide informative "file" names for evals -# 0x200 Provide informative names to anonymous subroutines -if ($^P) { # default is 0x73f - warn "Note: Devel::SizeMe currently disables perl debugger mode\n"; - $^P = 0; - $do_size_at_end = 1; +# As a handy convenience, make perl -d:SizeMe automatically call heap_size +# in an END block, and also set some $^P flags to get more detail. +my $do_size_at_end; # set true below for "perl -d:SizeMe ..." +BEGIN { + if ($^P) { + warn "Note: Devel::SizeMe currently disables perl debugger mode\n"; + warn scalar keys %INC; + # default $^P set by "perl -d" is 0x73f + $^P = 0x10 # Keep info about source lines on which a sub is defined + | 0x100 # Provide informative "file" names for evals + | 0x200 # Provide informative names to anonymous subroutines; + ; + $do_size_at_end = 1; + } } +use strict; +use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS $warn $dangle); + +require 5.005; +require Exporter; +require XSLoader; + +$VERSION = '0.02'; +@ISA = qw(Exporter); + +@EXPORT_OK = qw(size total_size perl_size heap_size); +%EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); # for use Devel::SizeMe ':all'; + +$warn = 1; +$dangle = 0; ## Set true to enable warnings about dangling pointers + +$ENV{SIZEME} ||= "| sizeme_store.pl --showid --db=sizeme.db"; + +XSLoader::load( __PACKAGE__); + END { - Devel::Memory::perl_size() if $do_size_at_end; + Devel::SizeMe::perl_size() if $do_size_at_end; } 1; +__END__ + +=pod + +Devel::SizeMe - Perl extension for finding the memory usage of Perl variables + +=head1 SYNOPSIS + + use Devel::SizeMe qw(size total_size); + + my $size = size("A string"); + my @foo = (1, 2, 3, 4, 5); + my $other_size = size(\@foo); + my $total_size = total_size( $ref_to_data ); + +=head1 DESCRIPTION + +Acts like Devel::Size 0.77 if the SIZEME env var is not set. + +Except that it also provides perl_size() and heap_size() functions. + +If SIZEME env var is set to an empty string then all the *_size functions +dump a textual representation of the memory data to stderr. + +If SIZEME env var is set to a string that starts with "|" then the +remainder of the string is taken to be a command name and popen() is used to +start the command and the raw memory data is piped to it. + +If SIZEME env var is set to anything else it is treated as the name of a +file the raw memory data should be written to. + +The sizeme_store.pl script can be used to process the raw memory data. +Typically run via the SIZEME env var. For example: + + export SIZEME='|./sizeme_store.pl --text' + export SIZEME='|./sizeme_store.pl --dot=sizeme.dot' + export SIZEME='|./sizeme_store.pl --db=sizeme.db' + +The --text output is similar to the textual representation output by the module +when the SIZEME env var is set to an empty string. + +The --dot output is suitable for feeding to Graphviz. + +The --db output is a SQLite database. (Very subject to change.) + +Example usage: + + SIZEME='|sizeme_store.pl --db=sizeme.db' perl -MDevel::SizeMe=:all -e 'total_size(sub { })' + +The sizeme_graph.pl script is a Mojolicious::Lite application that serves data to +an interactive treemap visualization of the memory use. It can be run as: + + sizeme_graph.pl daemon + +and then open http://127.0.0.1:3000 + +Please report bugs to: + + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-SizeMe + +=head1 COPYRIGHT + +Copyright (C) 2005 Dan Sugalski, +Copyright (C) 2007-2008 Tels, +Copyright (C) 2008 BrowserUK, +Copyright (C) 2011-2012 Nicholas Clark, +Copyright (C) 2012 Tim Bunce. + +This module is free software; you can redistribute it and/or modify it +under the same terms as Perl v5.8.8. + +=head1 SEE ALSO + +perl(1), L. + +=cut diff --git a/t/basic.t b/t/basic.t index 7a67620..1a898fe 100644 --- a/t/basic.t +++ b/t/basic.t @@ -2,15 +2,15 @@ use Test::More tests => 30; use strict; -use Devel::Memory qw(size total_size); +use Devel::SizeMe qw(size total_size); -can_ok ('Devel::Memory', qw/ +can_ok ('Devel::SizeMe', qw/ size total_size /); -die ("Uhoh, test uses an outdated version of Devel::Memory") - unless is ($Devel::Memory::VERSION, '0.01', 'VERSION MATCHES'); +die ("Uhoh, test uses an outdated version of Devel::SizeMe") + unless is ($Devel::SizeMe::VERSION, '0.02', 'VERSION MATCHES'); ############################################################################# # some basic checks: diff --git a/t/code.t b/t/code.t index 598d2c9..c0dafe6 100644 --- a/t/code.t +++ b/t/code.t @@ -2,7 +2,7 @@ use strict; use Test::More tests => 12; -use Devel::Memory ':all'; +use Devel::SizeMe ':all'; sub zwapp; sub swoosh($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$); diff --git a/t/globs.t b/t/globs.t index fe22369..0314143 100644 --- a/t/globs.t +++ b/t/globs.t @@ -2,7 +2,7 @@ use strict; use Test::More tests => 44; -use Devel::Memory ':all'; +use Devel::SizeMe ':all'; use Config; my $warn_count; @@ -169,12 +169,12 @@ gv_grew('bang', 'boff', 'no strict "vars"; @boff = (); 1', 'ARRAY'); gv_grew('clange', 'sock', 'no strict "vars"; %sock = (); 1', 'HASH'); SKIP: { skip("Can't create FORMAT references prior to 5.8.0", 7) if $] < 5.008; - local $Devel::Memory::warn = 0; + local $Devel::SizeMe::warn = 0; gv_grew('biff', 'zapeth', "format zapeth =\n.\n1", 'FORMAT'); } gv_grew('crunch_eth', 'awkkkkkk', 'sub awkkkkkk {}; 1', 'CODE'); -# Devel::Memory isn't even tracking PVIOs from GVs (yet) +# Devel::SizeMe isn't even tracking PVIOs from GVs (yet) # gv_grew('kapow', 'thwape', 'opendir *thwape, "."', 'IO'); is($warn_count, undef, 'No warnings emitted'); diff --git a/t/magic.t b/t/magic.t index 6793a13..b75b97f 100644 --- a/t/magic.t +++ b/t/magic.t @@ -2,7 +2,7 @@ use strict; use Test::More tests => 18; -use Devel::Memory ':all'; +use Devel::SizeMe ':all'; require Tie::Scalar; { diff --git a/t/pod.t b/t/pod.t index 85b26db..ad3e08c 100644 --- a/t/pod.t +++ b/t/pod.t @@ -21,6 +21,6 @@ SKIP: eval "use Test::Pod;"; $@ ? 0 : 1; }; - pod_file_ok( '../lib/Devel/Memory.pm' ); + pod_file_ok( '../lib/Devel/SizeMe.pm' ); } diff --git a/t/pod_cov.t b/t/pod_cov.t index 6da50a9..d2896b0 100644 --- a/t/pod_cov.t +++ b/t/pod_cov.t @@ -21,7 +21,7 @@ SKIP: $@ ? 0 : 1; }; for my $m (qw/ - Devel::Memory + Devel::SizeMe /) { pod_coverage_ok( $m, "$m is covered" ); diff --git a/t/pvbm.t b/t/pvbm.t index d15817d..5a3ee4b 100644 --- a/t/pvbm.t +++ b/t/pvbm.t @@ -2,7 +2,7 @@ use strict; use Test::More tests => 2; -use Devel::Memory ':all'; +use Devel::SizeMe ':all'; use Config; use constant PVBM => 'galumphing'; diff --git a/t/recurse.t b/t/recurse.t index fdfa14d..771d1ad 100644 --- a/t/recurse.t +++ b/t/recurse.t @@ -8,7 +8,7 @@ use Test::More; use strict; -use Devel::Memory ':all'; +use Devel::SizeMe ':all'; my %types = ( NULL => undef,