Skip Menu |
 

This queue is for tickets about the Devel-Timer CPAN distribution.

Report information
The Basics
Id: 20175
Status: resolved
Worked: 30 min
Priority: 0/
Queue: Devel-Timer

People
Owner: Nobody in particular
Requestors: JHANNAH [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.01
Fixed in: (no value)



Subject: [patch] Feature added: $t->report(collapse => 1);
Download (untitled) / with headers
text/plain 2.2k
Per this thread: http://www.mail-archive.com/module-authors@perl.org/msg04318.html The Devel::Timer author seems to have disappeared. As suggested on the module-authors mailing list, I'm submitting my patch as a "bug report" here. If no one can find JMOORE I'm volunteering to take over maintenance of Devel::Timer. Cheers, j Omaha Perl Mongers $ diff -ruN Timer_orig.pm Timer.pm --- Timer_orig.pm 2006-05-10 15:43:03.000000000 -0500 +++ Timer.pm 2006-05-11 11:10:36.000000000 -0500 @@ -76,7 +76,7 @@ sub report { - my $self = shift; + my ($self, %args) = @_; ## calculate total time (start time vs last time) @@ -84,9 +84,31 @@ $self->print("\n"); $self->print(ref($self) . " Report -- Total time: " . sprintf("%.4f", $total_time) . " secs"); + + if ($args{collapse}) + { + $self->calculate_collapsed; + + $self->print("Count Time Percent"); + $self->print("----------------------------------------------"); + + my $c = $self->{collapsed}; + my $sort_by = $args{sort_by} || "time"; + my @labels = sort { $c->{$b}->{$sort_by} <=> $c->{$a}->{$sort_by} } keys %$c; + foreach (@labels) + { + my $count = $c->{$_}->{count}; + my $time = $c->{$_}->{time}; + my $msg = sprintf("%8s %.4f %5.2f%% %s", + ($count, $time, (($time/$total_time)*100), $_)); + $self->print($msg); + } + return 1; + } + $self->print("Interval Time Percent"); $self->print("----------------------------------------------"); - + ## sort interval structure based on value @{$self->{intervals}} = sort { $b->{value} <=> $a->{value} } @{$self->{intervals}}; @@ -111,6 +133,23 @@ } } + +sub calculate_collapsed +{ + my ($self) = @_; + + my %collapsed; + foreach my $i (0 .. $self->{count} - 2) + { + my $label = $self->{label}->{$i} . ' -> ' . $self->{label}->{$i + 1}; + my $time = Time::HiRes::tv_interval($self->{times}->[$i], $self->{times}->[$i + 1]); + $collapsed{$label}{time} += $time; + $collapsed{$label}{count}++; + } + $self->{collapsed} = \%collapsed; +} + + ## output methods ## note: if you want to send output to somewhere other than stderr, ## you can override the print() method below. The initialize()
Download (untitled) / with headers
text/plain 109b
This is all committed to Gabor's SVN server, so it will go out the door the next time he makes a release. j


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.