| 1 | package Treex::Tool::Probe; | ||||||||||
| 2 | 1 | $Treex::Tool::Probe::VERSION = '2.20210102'; | |||||||||
| 3 | 1 | ▶ | use Treex::Core::Common; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Time::HiRes qw(time); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | my %time_begin = (); | |||||||||
| 10 | 1 | my %time_total = (); | |||||||||
| 11 | |||||||||||
| 12 | =head2 begin($name) | ||||||||||
| 13 | |||||||||||
| 14 | Beginning of event C$<name>. | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub begin { | ||||||||
|
Subroutine
begin: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 0 | my $name = shift; | |||||||||
| 20 | 0 | $time_begin{$name} = time(); | |||||||||
| 21 | |||||||||||
| 22 | 0 | return; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | =head2 end(name) | ||||||||||
| 26 | |||||||||||
| 27 | End of event C$<name>. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub end { | ||||||||
|
Subroutine
end: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 32 | 0 | my $name = shift; | |||||||||
| 33 | 0 | ▶ | if ( ! defined($time_begin{$name}) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | return; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | $time_total{$name}{'time'} += time() - $time_begin{$name}; | |||||||||
| 38 | 0 | $time_total{$name}{'count'} += 1; | |||||||||
| 39 | |||||||||||
| 40 | 0 | delete($time_begin{$name}); | |||||||||
| 41 | |||||||||||
| 42 | 0 | return; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | =head2 get_stats | ||||||||||
| 46 | |||||||||||
| 47 | Returns measured statistics in format: | ||||||||||
| 48 | { name1 => { 'time' => ..., 'count' => ...}, name2 => ...} | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | sub get_stats | ||||||||||
| 53 | 0 | ▶ | { | ||||||||
|
Subroutine
get_stats: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 54 | 0 | return %time_total; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | =head2 print_stats | ||||||||||
| 58 | |||||||||||
| 59 | Prints out measured statistics in format: | ||||||||||
| 60 | name1 time1 count1 | ||||||||||
| 61 | name2 time2 count2 | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | sub print_stats | ||||||||||
| 66 | 0 | ▶ | { | ||||||||
|
Subroutine
print_stats: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 67 | 0 | log_info "Probe Results:"; | |||||||||
| 68 | 0 | for my $name (sort keys %time_total) { | |||||||||
| 69 | log_info sprintf("Probe\t%30s\t%10.3f\t%d", | ||||||||||
| 70 | $name, | ||||||||||
| 71 | $time_total{$name}{'time'}, | ||||||||||
| 72 | 0 | $time_total{$name}{'count'} | |||||||||
| 73 | ); | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | return; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | 1 | 1; | |||||||||
| 81 | |||||||||||
| 82 | __END__ | ||||||||||