This is what i came up with based on your recommendations. Works nicely. Thanks a lot. (Obviously this includes a couple of choices specific to my own requirements.) One nice thing is the $DB::record variable. Which can be used to enable profiling from the client code. This is useful if you only want to profile a small section of code.

{ package DB; use B; use Time::HiRes qw(time); use Data::Dump::Streamer; BEGIN { my $PROFILE = "$0.profile"; open PROFILE, ">", $PROFILE or die "$PROFILE:$!"; } sub DB { } my $last; my @elapse= (0); my %total; my %only; my %name; my %hits; our $record=0; sub sub { my $name = $name{$sub}; unless ($name) { if ( ref $sub ) { my $Bobj = B::svref_2object($sub); $name = $Bobj->GV->NAME(); } else { $name=$sub; } $name =~ s/^main::/::/; $name{$sub}=$name; } return &$sub if !$record or $name=~/^(?:__ANON__|Data::Dump::S +treamer)/;#DB[ID]| #printf PROFILE "> %s%s\n", ( " " x @elapse ), $name; push @elapse, 0; my $start_time=time(); my (@array,$scalar); if (wantarray) { @array = &$sub; } elsif ( defined wantarray ) { $scalar = &$sub; } else { &$sub; } my $time=time()-$start_time; $total{$name} += $time; $only{$name} += $time; $only{$name} -= pop @elapse; printf PROFILE "< %s%s\t<%.6f>\n", ( " " x @elapse ), $name,$t +ime; $elapse[-1] += $time; $hits{$name}++; if (wantarray) { return @array; } elsif ( defined wantarray ) { return $scalar; } else { return; } } END { open my $out,">","$0.callstats" or die $!; local $record; Dump(\%total,\%only,\%hits)->Names(qw(*total *only *hits +)) ->To($out)->Out(); close $out,PROFILE; } } 1 __END__

---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi



In reply to Re^2: Stats from a Handrolled Profiler by demerphq
in thread Stats from a Handrolled Profiler by demerphq

Title:
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, details, 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, summary, 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.