Treex/Tool/Probe.pm

filter: Statementstmt 51.6% 16 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 100% 4 / 4 totaltotal 53.3% 24 / 45 CC 3 SCAR 11.6
CC
3
Cov
48%
end
6.0
print_stats
6.0
begin
2.0
CRAP 3.2
« Treex/Core/Phrase/Builder.pm ↑ Summary Treex/Core/Types.pm »
1 package Treex::Tool::Probe;
2 1 $Treex::Tool::Probe::VERSION = '2.20151210';
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 sub begin {
19 0 ▶ my $name = shift;
Subroutine begin: not called CC=1 SCAR=6.9
Pod documented
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 sub end {
32 0 ▶ my $name = shift;
Subroutine end: not called CC=2 SCAR=17.9
Pod documented
33 0 ▶ if ( ! defined($time_begin{$name}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $time_begin{$name}) 0 0 0
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 {
54 0 ▶ return %time_total;
Subroutine get_stats: not called CC=1 SCAR=6.9
Pod documented
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 {
67 0 ▶ log_info "Probe Results:";
Subroutine print_stats: not called CC=2 SCAR=17.9
Pod documented
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__
83  
84 =encoding utf-8
85  
86 =head1 NAME
87  
88 Treex::Tool::Probe
89  
90 =head1 VERSION
91  
92 version 2.20151210
93  
94 =head1 DESCRIPTION
95  
96 A module for measuring time consumed.
97  
98 =head1 AUTHORS
99  
100 Martin Majlis <majlis@ufal.mff.cuni.cz>
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 Copyright © 2012 by Institute of Formal and Applied Linguistics, Charles University in Prague
105  
106 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Core/Phrase/Builder.pm ↑ Summary Treex/Core/Types.pm »