XRay/Segment.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 3 totaltotal 77.2% 51 / 66 CC 6 SCAR 7.2
CC
6
Cov
86%
close
3.3
new
3.0
trace_header
2.0
CRAP 2.1
« XRay/Plugin/EC2.pm ↑ Summary XRay/Buffer.pm »
1 package AWS::XRay::Segment;
2  
3 14 ▶use 5.012000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 14 my $header = qq|{"format":"json","version":1}\n|;
11 14 my $json = JSON::XS->new->utf8;
12  
13 4437 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
14 4437 my $class = shift;
15 4437 my $src = shift;
16  
17 4437 ▶ return bless {}, "${class}::NoTrace" if !$AWS::XRay::ENABLED;
Branch: 1 branch
BranchTrueFalseTotal
unless $AWS::XRay::ENABLED 2212 2225 4437
18  
19 2225 my $segment = {
20 id => AWS::XRay::new_id(),
21 start_time => Time::HiRes::time(),
22 trace_id => $AWS::XRay::TRACE_ID,
23 %$src,
24 };
25 2225 ▶ if (my $parent_id = $AWS::XRay::SEGMENT_ID) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_id = $AWS::XRay::SEGMENT_ID) 712 1513 2225
26 # This is a sub segment.
27 712 $segment->{parent_id} = $parent_id;
28 712 $segment->{type} = "subsegment";
29 712 $segment->{namespace} = "remote";
30 }
31 2225 bless $segment, $class;
32 }
33  
34 # alias for backward compatibility
35 14 *send = \&close;
36  
37 2225 ▶sub close {
Subroutine close: called CC=3 SCAR=12.0
Pod undocumented
38 2225 my $self = shift;
39 2225 ▶ $self->{end_time} //= Time::HiRes::time();
Condition33%1/3
$self->{"end_time"} //= &Time::HiRes::time()
l!l&&r!l&&!r
022250
MC/DC0%0/2
$self->{"end_time"} //= &Time::HiRes::time()
$self->{"end_time"} &Time::HiRes::time()
Truth table33%1/3
A //= B
A= $self->{"end_time"}B= &Time::HiRes::time()
ABresult
1X1
011
000
40 2225 ▶ my $sock = AWS::XRay::sock() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sock = AWS::XRay::sock() or return 2225 0 2225
41 2225 $sock->print($header, $json->encode({%$self}));
42 }
43  
44 2 ▶sub trace_header {
Subroutine trace_header: called CC=2 SCAR=7.0
Pod undocumented
45 2 my $self = shift;
46 2 my $h = sprintf("Root=%s;Parent=%s", $self->{trace_id}, $self->{id});
47 2 ▶ if (defined $AWS::XRay::SAMPLED) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AWS::XRay::SAMPLED) 2 0 2
48 2 $h .= ";Sampled=$AWS::XRay::SAMPLED";
49 }
50 2 return $h;
51 }
52  
53 package AWS::XRay::Segment::NoTrace;
54  
55 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
56 0 my $class = shift;
57 0 bless {}, $class;
58 }
59  
60 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=0.0
61 # do not anything
62 }
63  
64 0 ▶sub trace_header {
Subroutine trace_header: not called CC=1 SCAR=6.9
65 0 "";
66 }
67  
68 14 1;
« XRay/Plugin/EC2.pm ↑ Summary XRay/Buffer.pm »