Receiver/Level2/Codespeed.pm

filter: Statementstmt 100% 36 / 36 Branchbran 60.0% 6 / 10 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 79.4% 54 / 68 CC 10 SCAR 20.7
CC
10
Cov
84%
submit
11.4
BEGIN
1.0
BEGIN
1.0
CRAP 8.0
↑ Summary Receiver/Daemon.pm »
1 package Tapper::Reports::Receiver::Level2::Codespeed;
2 1 our $AUTHORITY = 'cpan:TAPPER';
3 1 $Tapper::Reports::Receiver::Level2::Codespeed::VERSION = '5.0.1';
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::DPath 'dpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Scalar::Util "reftype";
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 sub submit
13 {
14 1 ▶ my ($util, $report, $options) = @_;
Subroutine submit: called CC=10 SCAR=24.4
Pod documented
15  
16 1 my $codespeed_url = $options->{url};
17 1 my $subscribe_dpath = $options->{subscribe_dpath};
18  
19 1 ▶ return unless $codespeed_url && $subscribe_dpath;
Branch: 1 branch
BranchTrueFalseTotal
unless $codespeed_url and $subscribe_dpath 0 1 1
Condition33%1/3
$codespeed_url and $subscribe_dpath
!ll&&!rl&&r
001
MC/DC0%0/2
$codespeed_url and $subscribe_dpath
$codespeed_url $subscribe_dpath
Truth table33%1/3
A and B
A= $codespeed_urlB= $subscribe_dpath
ABresult
0X0
100
111
20  
21 1 my $max_retry = 5;
22 1 my $tap_dom = $report->get_cached_tapdom;
23 1 my @chunks = dpath($subscribe_dpath)->match($tap_dom);
24 1 ▶ @chunks = @{$chunks[0]} while $chunks[0] && reftype $chunks[0] eq "ARRAY"; # deref all array envelops
Branch: 1 branch
BranchTrueFalseTotal
$chunks[0] and builtin::reftype($chunks[0]) eq "ARRAY" and do { @chunks = @{$chunks[0];} } 1 1 2
Condition66%2/3
$chunks[0] and builtin::reftype($chunks[0]) eq "ARRAY"
!ll&&!rl&&r
011
MC/DC50%1/2
$chunks[0] and builtin::reftype($chunks[0]) eq "ARRAY"
$chunks[0] builtin::reftype($chunks[0]) eq "ARRAY"
Truth table66%2/3
A and B
A= $chunks[0]B= builtin::reftype($chunks[0]) eq "ARRAY"
ABresult
0X0
100
111
25  
26 1 ▶ return unless @chunks;
Branch: 1 branch
BranchTrueFalseTotal
unless @chunks 0 1 1
27  
28 1 my $ua = LWP::UserAgent->new;
29 1 $ua->timeout(10);
30 1 foreach my $chunk (@chunks) {
31 4 my $response;
32 4 my $retry = $max_retry;
33 4 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not $response->is_success and $retry-- and do { do { $response = $ua->post($codespeed_url . '/result/add/', $chunk) } } 0 4 4
Condition33%1/3
not $response->is_success and $retry--
!ll&&!rl&&r
400
MC/DC0%0/2
not $response->is_success and $retry--
not $response->is_success $retry--
Truth table33%1/3
not(A) and B
A= not $response->is_successB= $retry--
ABresult
0X0
100
111
34 4 $response = $ua->post($codespeed_url."/result/add/", $chunk);
35 } while ( !$response->is_success and $retry-- );
36 4 ▶ $util->log->warn("Submit to $codespeed_url FAILED.") if !$response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 4 4
37 }
38 }
39  
40 1 1;
41  
42 __END__
43  
44 =pod
45  
46 =encoding UTF-8
47  
48 =head1 NAME
49  
50 Tapper::Reports::Receiver::Level2::Codespeed
51  
52 =head1 SYNOPSIS
53  
54 Used indirectly via L<Tapper::Reports::Receiver|Tapper::Reports::Receiver>.
55  
56 package Tapper::Reports::Receiver::Level2::Codespeed;
57  
58 sub submit
59 {
60 my ($util, $report, $options) = @_;
61 # ... actual data forwarding here
62 }
63  
64 =head2 submit
65  
66 Submit carved out data from a report to a Codespeed application URL.
67  
68 =head1 NAME
69  
70 Tapper::Reports::Receiver::Level2::Codespeed - Tapper - Level2 receiver plugin: Codespeed
71  
72 =head1 ABOUT
73  
74 I<Level 2 receivers> are other data receivers besides Tapper to
75 which data is forwarded when a report is arriving at the
76 Tapper::Reports::Receiver.
77  
78 One example is Codespeed to track benchmark values.
79  
80 By convention, for Codespeed the data is already prepared in the TAP
81 report like this:
82  
83 ok perlformance
84 ---
85 codespeed:
86 -
87 benchmark: Rx.regexes.fieldsplit1
88 commitid: 1b1a3d2a
89 environment: renormalist
90 executable: perl-5.12.1-foo
91 project: perl
92 result_value: 2.58451795578003
93 -
94 benchmark: Rx.regexes.fieldsplit2
95 commitid: 1b1a3d2b
96 environment: renormalist
97 executable: perl-5.12.1-foo
98 project: perl
99 result_value: 1.04680895805359
100 ...
101 ok some other TAP stuff
102  
103 I.e., it requires a key C<codespeed:> containing an array of chunks
104 with keys that Codespeed is expecting.
105  
106 =head1 AUTHOR
107  
108 AMD OSRC Tapper Team <tapper@amd64.org>
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is Copyright (c) 2016 by Advanced Micro Devices, Inc..
113  
114 This is free software, licensed under:
115  
116 The (two-clause) FreeBSD License
117  
118 =cut
↑ Summary Receiver/Daemon.pm »