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