Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Not long ago I was hunting a memory leak in a long-running AnyEvent-based application. I thought it would be a great idea to put a special guard object into every closure, so that I could see them created and destroyed.

The interface was very simple:

    # in initial section
    use My::Stat::Guard;
    my $stat = My::Stat::Guard->new;

    # when running
    my $guard = $stat->guard;
    my $callback = sub { 
        $guard->finish("taken route 1"); 
        # now do useful stuff
    # ... do whatever I need and call $callback eventually

    # in diagnostic procedures started via external event
    my $data = $stat->get_stat;
    # now I have some useful numbers in %$data
    # total: 100
    # alive: 19
    # dead: 81
    # etc.

get_stat also shows data for finished callbacks that still float around, and unfinished ones that left scope (typically both mean something went wrong).

The module also allows (when used with want_time => 1 parameter to new) to display (very rough) statistical distribution of guard lifetimes (== total time to process request).

I have searched CPAN for such a module before rolling out my own, but haven't found anything except several Guard-like modules.

So my question is: does such a module exist, and if not, is there a demand for one?

In reply to RFC: A closure guard with overall usage statistics by Dallaylaen

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (5)
    As of 2018-05-20 23:53 GMT
    Find Nodes?
      Voting Booth?