DiaColloDB/Timer.pm

filter: Statementstmt 36.6% 11 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 30.0% 3 / 10 Podpod 100% 7 / 7 totaltotal 36.2% 21 / 58 CC 5 SCAR 14.0
CC
5
Cov
28%
new
6.0
start
6.0
stop
6.0
CRAP 4.1
« DiaColloDB/Document.pm ↑ Summary DiaColloDB/Temp.pm »
1 ## -*- Mode: CPerl -*-
2 ## File: DiaColloDB::Client.pm
3 ## Author: Bryan Jurish <moocow@cpan.org>
4 ## Description: collocation db, timer
5  
6 package DiaColloDB::Timer;
7 1 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DiaColloDB::Utils qw(:time);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 ##==============================================================================
13 ## Globals & Constants
14  
15 1 our @ISA = qw();
16  
17 ##==============================================================================
18 ## Constructors etc.
19  
20 ## $timer = CLASS_OR_OBJECT->new(%args)
21 ## + %args, object structure:
22 ## (
23 ## started => $t0, ##-- time last operation started
24 ## elapsed => $elapsed, ##-- elapsed time (after stop())
25 ## )
26 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
27 0 my $that = shift;
28 0 ▶ return bless({
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
29 started=>undef,
30 elapsed=>0,
31 @_
32 }, ref($that)||$that);
33 }
34  
35 ##==============================================================================
36 ## Timing
37  
38 ## $timer = CLASS_OR_OBJECT->start()
39 ## + (re-)starts timer
40 0 ▶sub start {
Subroutine start: not called CC=2 SCAR=17.9
Pod documented
41 0 my $timer = shift;
42 0 ▶ $timer = $timer->new() if (!ref($timer));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $timer 0 0 0
43 0 $timer->{started} = [gettimeofday];
44 0 return $timer;
45 }
46  
47 ## $timer = $timer->stop()
48 ## + stops timer and adds current interval to {elapsed}
49 0 ▶sub stop {
Subroutine stop: not called CC=2 SCAR=17.9
Pod documented
50 0 my $timer = shift;
51 0 ▶ return $timer if (!defined($timer->{started}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timer->{"started"} 0 0 0
52 0 $timer->{elapsed} = $timer->elapsed();
53 0 $timer->{started} = undef;
54 0 return $timer;
55 }
56  
57 ## $timer = $timer->reset()
58 ## + stops and re-sets timer
59 0 ▶sub reset {
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
60 0 my $timer = shift;
61 0 $timer->{started} = undef;
62 0 $timer->{elapsed} = 0;
63 0 return $timer;
64 }
65  
66 ## $elapsed = $timer->elapsed()
67 ## + get total elapsed time for this timer
68 0 ▶sub elapsed {
Subroutine elapsed: not called CC=2 SCAR=17.9
Pod documented
69 0 my $timer = shift;
70 0 ▶ return $timer->{elapsed} + (defined($timer->{started}) ? tv_interval($timer->{started},[gettimeofday]) : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $timer->{'started'} ? : 0 0 0
71 }
72  
73  
74 ## $hms = $timer->hms($sfmt?)
75 ## ($h,$m,$s) = $timer->hms($sfmt?)
76 ## + parses and optionally formats elapsed time as HH:MM:SS.SSS
77 0 ▶sub hms {
Subroutine hms: not called CC=1 SCAR=6.9
Pod documented
78 0 return DiaColloDB::Utils::s2hms($_[0]->elapsed,@_[1..$#_]);
79 }
80  
81 ## $timestr = $timer->timestr($sfmt?)
82 ## + parses and formats elapsed time as Hh?Mm?Ss
83 0 ▶sub timestr {
Subroutine timestr: not called CC=1 SCAR=6.9
Pod documented
84 0 return DiaColloDB::Utils::s2timestr($_[0]->elapsed,@_[1..$#_]);
85 }
86  
87 ##==============================================================================
88 ## Footer
89 1 1;
90  
91 __END__
« DiaColloDB/Document.pm ↑ Summary DiaColloDB/Temp.pm »