David Leadbeater > Devel-Valgrind-Client > Devel::Valgrind::Client

Download:
Devel-Valgrind-Client-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  1
View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Devel::Valgrind::Client - Make valgrind memcheck client requests

SYNOPSIS ^

  # Run the following code under Valgrind

  use Devel::Valgrind::Client qw(leak_check);

  my $result = leak_check {
    # Code to check here.

    # The following two lines are deliberately leaky:
    my $x = "a" x 1_000;
    Internals::SvREFCNT($x, 2); # Don't do this in real code, please
  };

  # Should print just over 1000 (i.e. SvLEN + sizeof(SVPV))
  warn "Lost $result->{leaked} bytes";

DESCRIPTION ^

Valgrind provides the ability for a program that is running under Valgrind's memcheck tool ("being valgrinded") to make requests to the Valgrind VM through macros defined in <valgrind/memcheck.h>.

This module provides a way to access some of these calls from Perl, such as to find out if a program is running under memcheck, to force a leak check operation and retrieve statistics of the check.

The reason this module was created was to test XS code does not leak, however note that for many cases Test::Valgrind will be a better choice. The difference compared to Test::Valgrind is this runs within the same process; it is your responsibility to arrange for the program to run under Valgrind.

(Potentially it can also be used to count how many bytes are allocated -- by deliberately leaking memory -- although there are other choices for that, such as Devel::Mallinfo)

To compile this module you will need Valgrind installed, as it uses a header file Valgrind provides.

EXPORTS ^

Nothing by default. The following are available by request:

LICENSE ^

This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING or Software::License::WTFPL_2 for more details.

AUTHOR ^

David Leadbeater <dgl@dgl.cx>, 2010

syntax highlighting: