Rename to Devel::SizeMe
[p5sagit/Devel-Size.git] / lib / Devel / SizeMe.pm
CommitLineData
0e977dbc 1package Devel::SizeMe;
2
eda23e24 3# As a handy convenience, make perl -d:SizeMe automatically call heap_size
4# in an END block, and also set some $^P flags to get more detail.
5my $do_size_at_end; # set true below for "perl -d:SizeMe ..."
6BEGIN {
7 if ($^P) {
8 warn "Note: Devel::SizeMe currently disables perl debugger mode\n";
9 warn scalar keys %INC;
10 # default $^P set by "perl -d" is 0x73f
11 $^P = 0x10 # Keep info about source lines on which a sub is defined
12 | 0x100 # Provide informative "file" names for evals
13 | 0x200 # Provide informative names to anonymous subroutines;
14 ;
15 $do_size_at_end = 1;
16 }
0e977dbc 17}
18
eda23e24 19use strict;
20use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS $warn $dangle);
21
22require 5.005;
23require Exporter;
24require XSLoader;
25
26$VERSION = '0.02';
27@ISA = qw(Exporter);
28
29@EXPORT_OK = qw(size total_size perl_size heap_size);
30%EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); # for use Devel::SizeMe ':all';
31
32$warn = 1;
33$dangle = 0; ## Set true to enable warnings about dangling pointers
34
35$ENV{SIZEME} ||= "| sizeme_store.pl --showid --db=sizeme.db";
36
37XSLoader::load( __PACKAGE__);
38
0e977dbc 39END {
eda23e24 40 Devel::SizeMe::perl_size() if $do_size_at_end;
0e977dbc 41}
42
431;
eda23e24 44__END__
45
46=pod
47
48Devel::SizeMe - Perl extension for finding the memory usage of Perl variables
49
50=head1 SYNOPSIS
51
52 use Devel::SizeMe qw(size total_size);
53
54 my $size = size("A string");
55 my @foo = (1, 2, 3, 4, 5);
56 my $other_size = size(\@foo);
57 my $total_size = total_size( $ref_to_data );
58
59=head1 DESCRIPTION
60
61Acts like Devel::Size 0.77 if the SIZEME env var is not set.
62
63Except that it also provides perl_size() and heap_size() functions.
64
65If SIZEME env var is set to an empty string then all the *_size functions
66dump a textual representation of the memory data to stderr.
67
68If SIZEME env var is set to a string that starts with "|" then the
69remainder of the string is taken to be a command name and popen() is used to
70start the command and the raw memory data is piped to it.
71
72If SIZEME env var is set to anything else it is treated as the name of a
73file the raw memory data should be written to.
74
75The sizeme_store.pl script can be used to process the raw memory data.
76Typically run via the SIZEME env var. For example:
77
78 export SIZEME='|./sizeme_store.pl --text'
79 export SIZEME='|./sizeme_store.pl --dot=sizeme.dot'
80 export SIZEME='|./sizeme_store.pl --db=sizeme.db'
81
82The --text output is similar to the textual representation output by the module
83when the SIZEME env var is set to an empty string.
84
85The --dot output is suitable for feeding to Graphviz.
86
87The --db output is a SQLite database. (Very subject to change.)
88
89Example usage:
90
91 SIZEME='|sizeme_store.pl --db=sizeme.db' perl -MDevel::SizeMe=:all -e 'total_size(sub { })'
92
93The sizeme_graph.pl script is a Mojolicious::Lite application that serves data to
94an interactive treemap visualization of the memory use. It can be run as:
95
96 sizeme_graph.pl daemon
97
98and then open http://127.0.0.1:3000
99
100Please report bugs to:
101
102 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-SizeMe
103
104=head1 COPYRIGHT
105
106Copyright (C) 2005 Dan Sugalski,
107Copyright (C) 2007-2008 Tels,
108Copyright (C) 2008 BrowserUK,
109Copyright (C) 2011-2012 Nicholas Clark,
110Copyright (C) 2012 Tim Bunce.
111
112This module is free software; you can redistribute it and/or modify it
113under the same terms as Perl v5.8.8.
114
115=head1 SEE ALSO
116
117perl(1), L<Devel::Size>.
118
119=cut