Analyzer/BenchmarkAnything.pm

filter: Statementstmt 43.3% 65 / 150 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 60.8% 14 / 23 Podpod 100% 2 / 2 totaltotal 37.3% 81 / 217 SCAR 47.6
CC
19
Cov
35%
run
90.0
_print_to_template
30.0
_print_to_template_multi
20.0
CRAP 116.7
↑ Summary Analyzer.pm »
1 package Benchmark::Perl::Formance::Analyzer::BenchmarkAnything;
2 1 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: Benchmark::Perl::Formance - analyze results using BenchmarkAnything backend store
4 1 $Benchmark::Perl::Formance::Analyzer::BenchmarkAnything::VERSION = '0.007';
5 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::DPath "dpath";
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use TryCatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use version 0.77;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Structure::Util 'unbless';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::ShareDir 'dist_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use BenchmarkAnything::Storage::Frontend::Lib;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use JSON 'decode_json';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 with 'MooseX::Getopt::Usage',
20 'MooseX::Getopt::Usage::Role::Man';
21  
22 0 ▶has 'subdir' => ( is => 'rw', isa => 'ArrayRef', documentation => "where to search for benchmark results", default => sub{[]} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
23 1 has 'name' => ( is => 'rw', isa => 'ArrayRef', documentation => "file name pattern" );
24 1 has 'outfile' => ( is => 'rw', isa => 'Str', documentation => "output file" );
25 1 has 'verbose' => ( is => 'rw', isa => 'Bool', documentation => "Switch on verbosity" );
26 1 has 'debug' => ( is => 'rw', isa => 'Bool', documentation => "Switch on debugging output" );
27 1 has 'whitelist' => ( is => 'rw', isa => 'Str', documentation => "metrics to use (regular expression)" );
28 1 has 'blacklist' => ( is => 'rw', isa => 'Str', documentation => "metrics to skip (regular expression)" );
29 1 has 'dropnull' => ( is => 'rw', isa => 'Bool', documentation => "Drop metrics with null values", default => 0 );
30 1 has 'query' => ( is => 'rw', isa => 'Str', documentation => "Search query file or '-' for STDIN", default => "-" );
31 0 ▶has 'balib' => ( is => 'rw', documentation => "where to search for benchmark results", default => sub { BenchmarkAnything::Storage::Frontend::Lib->new } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
32 1 has 'template' => ( is => 'rw', isa => 'Str',
33 documentation => 'output template file',
34 default => 'google-chart-area',
35 #default => 'google-chart-line',
36 );
37 has 'tt' => ( is => 'rw',
38 documentation => "template renderer",
39 default => sub
40 {
41 0 ▶ Template->new({
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 INCLUDE_PATH => dist_dir('Benchmark-Perl-Formance-Analyzer')."/templates", # or list ref
43 INTERPOLATE => 0, # expand "$var" in plain text
44 POST_CHOMP => 0, # cleanup whitespace
45 EVAL_PERL => 0, # evaluate Perl code blocks
46 });
47 }
48 1 );
49 1 has 'x_key' => ( is => 'rw', isa => 'Str', documentation => "x-axis key", default => "perlconfig_version" );
50 1 has 'x_type' => ( is => 'rw', isa => 'Str', documentation => "x-axis type", default => "version" ); # version, numeric, string, date
51 1 has 'y_key' => ( is => 'rw', isa => 'Str', documentation => "y-axis key", default => "VALUE" );
52 1 has 'y_type' => ( is => 'rw', isa => 'Str', documentation => "y-axis type", default => "numeric" );
53 1 has 'aggregation' => ( is => 'rw', isa => 'Str', documentation => "which aggregation to use (avg, stdv, ci_95_lower, ci_95_upper)", default => "avg" ); # sub entries of {stats}: avg, stdv, ci_95_lower, ci_95_upper
54 1 has 'querybundle' => ( is => 'rw', isa => 'Str', documentation => "which chartqueries/ subdirectory (e.g., perlformance, perlstone2015)", default => 'perlstone2015' );
55 1 has '_rawnumbers' => ( is => 'rw', isa => 'Str', default => "" );
56  
57 1 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 __PACKAGE__->meta->make_immutable;
59 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 sub print_version
62 {
63 0 ▶ my ($self) = @_;
Subroutine print_version: not called CC=2 SCAR=17.9
Pod documented
64  
65 0 ▶ if ($self->verbose)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) { } 0 0 0
66 {
67 0 print STDERR "Benchmark::Perl::Formance::Analyzer version $Benchmark::Perl::Formance::Analyzer::VERSION\n";
68 }
69 else
70 {
71 0 print STDERR $Benchmark::Perl::Formance::Analyzer::VERSION, "\n";
72 }
73 }
74  
75 sub _print_to_template
76 {
77 0 ▶ my ($self, $RESULTMATRIX, $options) = @_;
Subroutine _print_to_template: not called CC=5 SCAR=34.0
78  
79 0 require JSON;
80 0 my $outfile = $options->{outfile};
81  
82 my $vars = {
83 RESULTMATRIX => JSON->new->pretty->encode($RESULTMATRIX),
84 title => ($options->{charttitle} || ""),
85 modulename => ($options->{modulename} || ""),
86 outfile => $outfile,
87 x_key => $options->{x_key},
88 isStacked => $options->{isStacked},
89 interpolateNulls => $options->{interpolateNulls},
90 areaOpacity => $options->{areaOpacity},
91 0 ▶ width => 700,
Condition0%0/4
$options->{'charttitle'} || ''
l!l
00
$options->{'modulename'} || ''
l!l
00
MC/DC0%0/1
$options->{'charttitle'} || ''
$options->{'charttitle'}
MC/DC0%0/1
$options->{'modulename'} || ''
$options->{'modulename'}
Truth table0%0/2
A
A= $options->{'charttitle'}
Aresult
11
00
Truth table0%0/2
A
A= $options->{'modulename'}
Aresult
11
00
92 height => 500,
93 };
94  
95 0 my $template = $self->template.".tt";
96 0 ▶ $self->tt->process($template, $vars, ($outfile eq '-' ? () : $outfile))
Branch: 2 branches
BranchTrueFalseTotal
$self->tt->process($template, $vars, $outfile eq "-" ? () : $outfile) or die $self->tt->error . "\n" 0 0 0
$outfile eq '-' ? : 0 0 0
97 or die $self->tt->error."\n";
98 }
99  
100 sub _print_to_template_multi
101 {
102 0 ▶ my ($self, $chartlist, $options) = @_;
Subroutine _print_to_template_multi: not called CC=4 SCAR=30.0
103  
104 0 require JSON;
105  
106 0 my $number = 0;
107 my @extended_chartlist = map
108 {
109 0 $_->{json} = JSON->new->pretty->encode($_->{data});
110 0 $_->{number} = $number++;
111 0 $_
112 } @$chartlist;
113  
114 # print
115 my $vars = {
116 querybundle => $options->{querybundle},
117 chartlist => \@extended_chartlist,
118 width => $options->{width} || 300,
119 height => $options->{height} || 200,
120 x_key => $options->{x_key},
121 isStacked => $options->{isStacked},
122 interpolateNulls => $options->{interpolateNulls},
123 areaOpacity => $options->{areaOpacity},
124 0 ▶ };
Condition0%0/4
$options->{'width'} || 300
l!l
00
$options->{'height'} || 200
l!l
00
MC/DC0%0/1
$options->{'width'} || 300
$options->{'width'}
MC/DC0%0/1
$options->{'height'} || 200
$options->{'height'}
Truth table0%0/2
A
A= $options->{'width'}
Aresult
11
00
Truth table0%0/2
A
A= $options->{'height'}
Aresult
11
00
125 0 my $template_multi = $self->template."_multi.tt";
126 0 my $resultbuffer;
127 0 ▶ $self->tt->process($template_multi, $vars, \$resultbuffer)
Branch: 1 branch
BranchTrueFalseTotal
$self->tt->process($template_multi, $vars, \$resultbuffer) or die $self->tt->error . "\n" 0 0 0
128 or die $self->tt->error."\n";
129 0 return $resultbuffer;
130 }
131  
132 sub _get_chart
133 {
134 0 ▶ my ($self, $chartname) = @_;
Subroutine _get_chart: not called CC=2 SCAR=17.9
135  
136 0 require File::Slurper;
137  
138 0 my $querybundle = $self->querybundle;
139 0 my $filename = dist_dir('Benchmark-Perl-Formance-Analyzer')."/chartqueries/$querybundle/$chartname.json";
140 0 my $json = File::Slurper::read_text($filename);
141 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
142 0 say STDERR "READ: $chartname - $filename";
143 0 say STDERR "JSON:\n$json";
144 }
145 0 return decode_json($json);
146 }
147  
148 sub _search
149 {
150 0 ▶ my ($self, $chartline_queries) = @_;
Subroutine _search: not called CC=2 SCAR=17.9
151  
152 0 $self->balib->connect;
153  
154 0 my @results;
155 0 foreach my $q (@{$chartline_queries})
156 {
157 push @results,
158 {
159 title => $q->{title},
160 0 results => $self->balib->search($q->{query}),
161 };
162 }
163  
164 0 return \@results;
165 }
166  
167 sub run
168 {
169 0 ▶ my ($self) = @_;
Subroutine run: not called CC=9 SCAR=45.0
Pod documented
170  
171 0 require File::Find::Rule;
172 0 require File::Basename;
173 0 require BenchmarkAnything::Evaluations;
174  
175 0 my $timestamp = ~~gmtime;
176 0 my $headline = "Perl::Formance - charts rendered at: $timestamp\n\n";
177 0 $headline .= "ci95l - confidence intervall 95 lower\n";
178 0 $headline .= "ci95u - confidence intervall 95 upper\n";
179 0 $headline .= "avg - average\n";
180 0 $headline .= "stdv - standard deviation\n";
181 0 ▶ say STDERR sprintf($headline) if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
182 0 $self->_rawnumbers($self->_rawnumbers.$headline);
183  
184 0 my $querybundle = $self->querybundle;
185  
186 my @chartnames =
187 0 map { File::Basename::basename($_, ".json") }
188 File::Find::Rule
189 ->file
190 ->name( '*.json' )
191 ->in( dist_dir('Benchmark-Perl-Formance-Analyzer')."/chartqueries/$querybundle/" );
192  
193 0 my @chartlist;
194 0 foreach my $chartname (sort @chartnames)
195 {
196  
197 0 my $chart = $self->_get_chart($chartname);
198 0 my $chartlines = $self->_search($chart->{chartlines});
199 0 my $transform_options = {
200 x_key => $self->x_key,
201 x_type => $self->x_type,
202 y_key => $self->y_key,
203 y_type => $self->y_type,
204 aggregation => $self->aggregation,
205 verbose => $self->verbose,
206 debug => $self->debug,
207 };
208 0 my ($result_matrix, $rawnumbers) = BenchmarkAnything::Evaluations::transform_chartlines($chartlines, $transform_options);
209 0 $self->_rawnumbers($self->_rawnumbers."\n$rawnumbers");
210  
211 0 my $outfile;
212 0 ▶ if (not $outfile = $self->outfile)
Branch: 1 branch
BranchTrueFalseTotal
unless ($outfile = $self->outfile) 0 0 0
213 {
214 0 require File::HomeDir;
215 0 $outfile = $chartname;
216 0 $outfile =~ s/[\s\W:]+/-/g;
217 0 $outfile .= ".html";
218 0 $outfile = File::HomeDir->my_home . "/perlformance/results/$querybundle/".$outfile;
219 }
220  
221 my $render_options = {
222 x_key => $self->x_key,
223 charttitle => ($chart->{charttitle} || $chartname),
224 modulename => $chart->{modulename},
225 0 ▶ isStacked => "false", # true, false, 'relative'
Condition0%0/3
$chart->{'charttitle'} || $chartname
l!l&&r!l&&!r
000
MC/DC0%0/2
$chart->{'charttitle'} || $chartname
$chart->{'charttitle'} $chartname
Truth table0%0/3
A || B
A= $chart->{'charttitle'}B= $chartname
ABresult
1X1
011
000
226 interpolateNulls => "true", # true, false -- only works with isStacked=false
227 areaOpacity => 0.0,
228 outfile => $outfile,
229 };
230 0 $self->_print_to_template($result_matrix, $render_options);
231  
232 push @chartlist, {
233 outfile => File::Basename::basename($outfile),
234 data => $result_matrix,
235 charttitle => ($chart->{charttitle} || $chartname),
236 modulename => $chart->{modulename},
237 0 ▶ };
Condition0%0/3
$chart->{'charttitle'} || $chartname
l!l&&r!l&&!r
000
MC/DC0%0/2
$chart->{'charttitle'} || $chartname
$chart->{'charttitle'} $chartname
Truth table0%0/3
A || B
A= $chart->{'charttitle'}B= $chartname
ABresult
1X1
011
000
238 0 ▶ say STDERR "Done." if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
239  
240 }
241  
242 # DASHBOARD
243 0 my $dashboard_options = {
244 x_key => $self->x_key,
245 isStacked => "false", # true, false, 'relative'
246 interpolateNulls => "true", # true, false -- only works with isStacked=false
247 areaOpacity => 0.0,
248 querybundle => $querybundle,
249 };
250 0 my $dashboard_file = File::HomeDir->my_home . "/perlformance/results/$querybundle/index.html";
251 0 my $dashboard_content = $self->_print_to_template_multi(\@chartlist, $dashboard_options);
252 0 ▶ open my $DASHBOARD, ">", $dashboard_file or die "Could not write to $dashboard_file";
Branch: 1 branch
BranchTrueFalseTotal
open my $DASHBOARD, ">", $dashboard_file or die "Could not write to $dashboard_file" 0 0 0
253 0 print $DASHBOARD $dashboard_content;
254 0 close $DASHBOARD;
255  
256 # RAW NUMBERS
257 0 my $rawnumbers_file = File::HomeDir->my_home . "/perlformance/results/$querybundle/raw-numbers.txt";
258 0 ▶ open my $RAWNUMBERS, ">", $rawnumbers_file or die "Could not write to $rawnumbers_file";
Branch: 1 branch
BranchTrueFalseTotal
open my $RAWNUMBERS, ">", $rawnumbers_file or die "Could not write to $rawnumbers_file" 0 0 0
259 0 print $RAWNUMBERS $self->_rawnumbers;
260 0 close $RAWNUMBERS;
261  
262 # Done
263 0 return;
264 }
265  
266 1 1;
267  
268 __END__
269  
270 =pod
271  
272 =encoding UTF-8
273  
274 =head1 NAME
275  
276 Benchmark::Perl::Formance::Analyzer::BenchmarkAnything - Benchmark::Perl::Formance - analyze results using BenchmarkAnything backend store
277  
278 =head1 SYNOPSIS
279  
280 Usage:
281  
282 $ benchmark-perlformance-process-benchmarkanything
283  
284 =head1 ABOUT
285  
286 Analyze L<Benchmark::Perl::Formance|Benchmark::Perl::Formance> results.
287  
288 This is a commandline tool to process Benchmark::Perl::Formance
289 results which follow the
290 L<BenchmarkAnything|http://benchmarkanything.org> schema as produced
291 with C<benchmark-perlformance --benchmarkanything>.
292  
293 =head1 METHODS
294  
295 =head2 run
296  
297 Entry point to actually start.
298  
299 =head2 print_version
300  
301 Print version.
302  
303 =head1 AUTHOR
304  
305 Steffen Schwigon <ss5@renormalist.net>
306  
307 =head1 COPYRIGHT AND LICENSE
308  
309 This software is copyright (c) 2016 by Steffen Schwigon.
310  
311 This is free software; you can redistribute it and/or modify it under
312 the same terms as the Perl 5 programming language system itself.
313  
314 =cut
↑ Summary Analyzer.pm »