Matthew Horsfall (alh) > Devel-MemoryTrace-Light-0.09 > Devel::MemoryTrace::Light

Download:
Devel-MemoryTrace-Light-0.09.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.09   Source  

NAME ^

Devel::MemoryTrace::Light - Print a message when your program grows in memory

VERSION ^

version 0.09

SYNOPSIS ^

  perl -d:MemoryTrace::Light Program

DESCRIPTION ^

Prints out a message when your program grows in memory containing the pid, package, file, line, and number of bytes (resident set size) your program increased. For example, if your program looked like this:

  #!/usr/bin/perl

  use strict;
  use warnings;

  my @arr;
  $arr[4096] = 'hello';

Then the output will look like:

  >> 324 init, 0 (0) used 8192 bytes
  >> 324 main, ex.pl (7) used 20480 bytes

MEMORYTRACE_LIGHT ENVIRONMENT VARIABLE ^

The MEMORYTRACE_LIGHT environment variable may be used to control some of the behaviors of Devel::MemoryTrace::Light. The format is key=value, and multiple values may be set at one time using the : separator. For example:

  export MEMORYTRACE_LIGHT=start=no:provider=MyClass

provider=...

Forces Devel::MemoryTrace::Light to use whatever class is passed in to determine memory usage.

The provider class must define a get_mem() method which should return the current process' memory size. The built in modules return the resident set size, but a custom provider could use virtual, swap, or whatever it wants, as long as it returns the same type of information consistently.

The provider class should also define a forked() method which will be called if Devel::MemoryTrace::Light detects that the process has forked. This method should do any re-initialization necessary for the provider class to accurately report memory for the new forked process.

The provider setting may also be used to force Devel::MemoryTrace::Light to prefer one of the built-in providers over another if more than one is installed.

start=...

Modify when tracing happens:

  start=begin - trace compilation of the program and beyond
  start=no    - disable tracing until C<DB::enable_trace()> is called

By default, tracing doesn't happen until the beginning of the INIT phase, after compilation. To see where memory growth is happening inside of use statements, use start=begin.

RUN-TIME CONTROL OF TRACING ^

A limited set of functionality is provided for run-time control of tracing.

DB::disable_trace()

DB::enable_trace()

You can control when tracing happens by using DB::enable_trace() and DB::disable_trace. This works well coupled with the start=no setting in the MEMORYTRACE_LIGHT environment variable described above.

DB::set_callback(\&somefunc)

If you would like to override the default behavior of printing to STDOUT whenever the program size increases, you may provide your own callback method.

This causes \&somefunc to be called whenever the debugger detects an increase in memory size. \&somefunc should accept 4 arguments:

DB::restore_callback()

Restores the default callback.

OS SUPPORT ^

Currently works on FreeBSD, Linux, and anywhere else GTop is supported.

On FreeBSD, installing this module will install BSD::Process unless GTop is already installed. BSD::Process will be preferred if both modules are on the system.

CAVEATS ^

BUGS ^

Please report any bugs (or feature requests) through http://rt.cpan.org/.

AUTHOR ^

Matthew Horsfall (alh) - <WolfSage@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2011 by Matthew Horsfall.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: