From: Tim Bunce Date: Sun, 30 Sep 2012 06:56:27 +0000 (+0900) Subject: First steps migrating to SizeMe X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0e977dbc954f8d2e414720230a34bf9a34b4b0d2;p=p5sagit%2FDevel-Size.git First steps migrating to SizeMe --- diff --git a/Makefile.PL b/Makefile.PL index 6633431..de23be8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -21,7 +21,7 @@ WriteMakefile( 'Devel::Dwarn' => 0, XSLoader => 0, }, - EXE_FILES => [ 'bin/dmemtree.pl' ], + EXE_FILES => [ 'bin/sizeme_store.pl' ], (eval $ExtUtils::MakeMaker::VERSION >= 6.47 ? (MIN_PERL_VERSION => '5.005') : ()), (eval $ExtUtils::MakeMaker::VERSION >= 6.31 ? (LICENSE => 'perl') : ()), ); diff --git a/Memory.xs b/Memory.xs index 3420f29..dd1ea7f 100644 --- a/Memory.xs +++ b/Memory.xs @@ -1324,7 +1324,7 @@ new_state(pTHX) #ifdef PATH_TRACKING /* XXX quick hack */ - st->node_stream_name = getenv("PERL_DMEM"); + st->node_stream_name = getenv("SIZEME"); if (st->node_stream_name) { if (*st->node_stream_name) { if (*st->node_stream_name == '|') diff --git a/README b/README index 0bebcc8..1535f09 100644 --- a/README +++ b/README @@ -1,3 +1,28 @@ +TODO + + Rename to Devel::SizeMe + Devel::SizeMe::Core - loads XS and sets options + Devel::SizeMe - loads XS + -d:SizeMe=opts + Devel::SizeMe::Stream - parse raw stream + Devel::SizeMe::Store - db write + Devel::SizeMe::Data - db read / orlite? + Devel::SizeMe::Graph - data reading/processing for sizeme_graph + sizeme_store + sizeme_graph + tests + Add R(un) and E(nd) tokens + Support multiple runs + Name runs to allow total_size (for example) of multiple data structures + +Optimizations: + Remove depth from stream? +Future + Add addr to leaf to visualize memory layout + Add token for ptr to node already seen (identified by addr I presume) + so we can move from a Tree to a DAG and see alternative name paths. + + =pod Devel::Memory - Perl extension for finding the memory usage of Perl variables diff --git a/bin/dmemtree.pl b/bin/sizeme_store.pl similarity index 96% rename from bin/dmemtree.pl rename to bin/sizeme_store.pl index a529bbd..13c8b00 100755 --- a/bin/dmemtree.pl +++ b/bin/sizeme_store.pl @@ -51,6 +51,9 @@ GetOptions( 'showid!' => \my $opt_showid, ) or exit 1; +my $run_size = 0; +my $total_size = 0; + my $j = JSON::XS->new->ascii->pretty(0); my ($dbh, $node_ins_sth); @@ -246,7 +249,8 @@ while (<>) { elsif ($type eq "L") { my $node = $seqn2node{$id} || die; $node->{leaves}{$name} += $val; - printf "%s+%d %s\n", $indent x ($node->{depth}+1), $val, $name + $run_size += $val; + printf "%s+%d=%d %s\n", $indent x ($node->{depth}+1), $val, $run_size, $name if $opt_text; } @@ -291,8 +295,12 @@ while (<>) { } my $top = $stack[0]; # grab top node before we pop all the nodes leave_node(pop @stack) while @stack; +my $top_size = $top->{self_size}+$top->{kids_size}; + +printf "Stored %d nodes recording %s (%d)\n", + $top->{kids_node_count}, fmt_size($top_size), $top_size; -if ($opt_verbose) { +if ($opt_verbose or $run_size != $top_size) { warn "EOF ends $top->{id} d$top->{depth}: size $top->{self_size}+$top->{kids_size}\n"; warn Dumper($top); } diff --git a/lib/Devel/SizeMe.pm b/lib/Devel/SizeMe.pm new file mode 100644 index 0000000..7397395 --- /dev/null +++ b/lib/Devel/SizeMe.pm @@ -0,0 +1,24 @@ +package Devel::SizeMe; + +require Devel::Memory; + +$ENV{SIZEME} = "|sizeme_store.pl --db sizeme.db"; + +# 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; +} + +END { + Devel::Memory::perl_size(); +} + +1;