| 1 | package Net::Statsd::Client::Timer; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Measure event timings and send them to StatsD | ||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.34'; # VERSION | |||||||||||||||||||||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Time::HiRes qw(gettimeofday tv_interval); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | has 'statsd' => ( | |||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | has '_pending' => ( | |||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | default => quote_sub q{1}, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | has ['metric', 'start', '_file', '_line', 'warning_callback', 'sample_rate'] => ( | |||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 6 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 27 | 6 | my (undef, $file, $line) = caller(1); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | $self->start([gettimeofday]); | |||||||||||||||||||||||||||
| 30 | 6 | $self->_file($file); | |||||||||||||||||||||||||||
| 31 | 6 | $self->_line($line); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | sub finish { | ||||||||||||||||||||||||||
|
Subroutine
finish: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 36 | 5 | my $duration = tv_interval($self->{start}) * 1000; | |||||||||||||||||||||||||||
| 37 | $self->{statsd}->timing_ms( | ||||||||||||||||||||||||||||
| 38 | $self->{metric}, | ||||||||||||||||||||||||||||
| 39 | $duration, | ||||||||||||||||||||||||||||
| 40 | $self->{sample_rate}, | ||||||||||||||||||||||||||||
| 41 | 5 | ); | |||||||||||||||||||||||||||
| 42 | 5 | delete $self->{_pending}; | |||||||||||||||||||||||||||
| 43 | 5 | return $duration; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub cancel { | ||||||||||||||||||||||||||
|
Subroutine
cancel: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | delete $self->{_pending}; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub emit_warning { | ||||||||||||||||||||||||||
|
Subroutine
emit_warning: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 1 | ▶ | if (defined $self->warning_callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 1 | $self->warning_callback->(@_); | |||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||
| 56 | 0 | warn(@_); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | ▶ | sub DEMOLISH { | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 62 | 6 | ▶ | if ($self->{_pending}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 1 | my $metric = $self->{metric}; | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | $metric = $self->{statsd}{prefix} . $metric if $self->{statsd} && $self->{statsd}{prefix}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"statsd"} and $self->{"statsd"}{"prefix"}
MC/DC0%0/2
$self->{"statsd"} and $self->{"statsd"}{"prefix"}
$self->{"statsd"}
$self->{"statsd"}{"prefix"}
Truth table33%1/3
A and B
A= $self->{"statsd"}B= $self->{"statsd"}{"prefix"}
| |||||||||||||||||||||||||||||
| 65 | 1 | $self->emit_warning("Unfinished timer for stat $metric (created at $self->{_file} line $self->{_line})"); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 3 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||