Mega rename to Devel::Memory commit
[p5sagit/Devel-Size.git] / lib / Devel / Memory.pm
CommitLineData
d3b8a135 1package Devel::Memory;
2
3use strict;
4use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS $warn $dangle);
5
6require 5.005;
7require Exporter;
8require XSLoader;
9
10@ISA = qw(Exporter);
11
12@EXPORT_OK = qw(size total_size perl_size);
13
14# This allows declaration use Devel::Memory ':all';
15%EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
16
17$VERSION = '0.01';
18
19XSLoader::load( __PACKAGE__);
20
21$warn = 1;
22$dangle = 0; ## Set true to enable warnings about dangling pointers
23
241;
25__END__
26
27=pod
28
29Devel::Memory - Perl extension for finding the memory usage of Perl variables
30
31=head1 SYNOPSIS
32
33 use Devel::Memory qw(size total_size);
34
35 my $size = size("A string");
36 my @foo = (1, 2, 3, 4, 5);
37 my $other_size = size(\@foo);
38 my $total_size = total_size( $ref_to_data );
39
40=head1 DESCRIPTION
41
42Acts like Devel::Size 0.77 if the PERL_DMEM env var is not set.
43
44Except that it also provides perl_size() and heap_size() functions.
45
46If PERL_DMEM env var is set to an empty string then all the *_size functions
47dump a textual representation of the memory data to stderr.
48
49If PERL_DMEM env var is set to a string that starts with "|" then the
50remainder of the string is taken to be a command name and popen() is used to
51start the command and the raw memory data is piped to it.
52
53If PERL_DMEM env var is set to anything else it is treated as the name of a
54file the raw memory data should be written to.
55
56The dmemtree.pl script can be used to process the raw memory data.
57Typically run via the PERL_DMEM env var. For example:
58
59 export PERL_DMEM='|./dmemtree.pl --text'
60 export PERL_DMEM='|./dmemtree.pl --dot=dmemtree.dot'
61 export PERL_DMEM='|./dmemtree.pl --db=dmemtree.db'
62
63The --text output is similar to the textual representation output by the module
64when the PERL_DMEM env var is set to an empty string.
65
66The --dot output is suitable for feeding to Graphviz.
67
68The --db output is a SQLite database. (Very subject to change.)
69
70Example usage:
71
72 PERL_DMEM='|dmemtree.pl --db=dmemtree.db' perl -MDevel::Memory=:all -e 'total_size(sub { })'
73
74The dmemview.pl script is a Mojolicious::Lite application that serves data to
75an interactive treemap visualization of the memory use. It can be run as:
76
77 dmemview.pl daemon
78
79and then open http://127.0.0.1:3000
80
81Please report bugs to:
82
83 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-Memory
84
85=head1 COPYRIGHT
86
87Copyright (C) 2005 Dan Sugalski,
88Copyright (C) 2007-2008 Tels,
89Copyright (C) BrowserUK 2008,
90Copyright (C) 2011-2012 Nicholas Clark,
91Copyright (C) 2012 Tim Bunce.
92
93This module is free software; you can redistribute it and/or modify it
94under the same terms as Perl v5.8.8.
95
96=head1 SEE ALSO
97
98perl(1), L<Devel::Size>.
99
100=cut