Benchmarker/Imager.pm

filter: Statementstmt 19.1% 35 / 183 Branchbran 0.0% 0 / 112 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 58.8% 10 / 17 Podpod 14.2% 1 / 7 totaltotal 13.4% 46 / 343 CC 64 SCAR 56.0
CC
64
Cov
11%
load_yaml
506.0
loadtests
342.0
init_options
210.0
CRAP 271.4
« Benchmarker.pm ↑ Summary Benchmarker/GetPOEdists.pm »
1 # Declare our package
2 package POE::Devel::Benchmarker::Imager;
3 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Initialize our version
6 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '0.05';
8  
9 # auto-export the only sub we have
10 1 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT = qw( imager );
12  
13 # import the helper modules
14 1 ▶use YAML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # load our plugins!
17 1 ▶use Module::Pluggable search_path => [ __PACKAGE__ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # load comparison stuff
20 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # Get some stuff from Utils
23 1 ▶use POE::Devel::Benchmarker::Utils qw( currentTestVersion );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # generate some accessors
26 1 ▶use base qw( Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 __PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
28 noxsqueue noasserts litetests quiet
29 ) );
30  
31 # autoflush, please!
32 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 STDOUT->autoflush( 1 );
34  
35 # starts the work of converting our data to images
36 0 ▶sub imager {
Subroutine imager: not called CC=1 SCAR=6.9
Pod undocumented
37 0 my $options = shift;
38  
39 # instantitate ourself
40 0 my $self = __PACKAGE__->new( $options );
41  
42 # parse all of our YAML modules!
43 0 $self->loadtests;
44  
45 # process some stats
46 0 $self->process_data;
47  
48 # generate the images!
49 0 $self->generate_images;
50  
51 0 return;
52 }
53  
54 # creates a new instance
55 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
56 0 my $class = shift;
57 0 my $opts = shift;
58  
59 # instantitate ourself
60 0 my $self = {};
61 0 bless $self, $class;
62  
63 # init the options
64 0 $self->init_options( $opts );
65  
66 0 ▶ if ( ! $self->{'options'}->{'quiet'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"options"}{"quiet"}) 0 0 0
67 0 print "[IMAGER] Starting up...\n";
68 }
69  
70 0 return $self;
71 }
72  
73 0 ▶sub init_options {
Subroutine init_options: not called CC=14 SCAR=53.5
Pod undocumented
74 0 my $self = shift;
75 0 my $options = shift;
76  
77 # set defaults
78 0 $self->{'quiet'} = 0;
79 0 $self->{'litetests'} = 1;
80 0 $self->{'noasserts'} = undef;
81 0 $self->{'noxsqueue'} = undef;
82  
83 # process our options
84 0 ▶ if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options and ref $options and ref $options eq "HASH") 0 0 0
Condition0%0/6
defined $options and ref $options and ref $options eq "HASH"
!ll&&!rl&&r
000
defined $options and ref $options
!ll&&!rl&&r
000
MC/DC0%0/3
defined $options and ref $options and ref $options eq "HASH"
defined $options ref $options ref $options eq "HASH"
Truth table0%0/4
A and B and C
A= defined $optionsB= ref $optionsC= ref $options eq "HASH"
ABCresult
0XX0
10X0
1100
1111
85 # process quiet mode
86 0 ▶ if ( exists $options->{'quiet'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"quiet"}) 0 0 0
87 0 ▶ if ( $options->{'quiet'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'quiet'}) { } 0 0 0
88 0 $self->{'quiet'} = 1;
89 } else {
90 0 $self->{'quiet'} = 0;
91 }
92 }
93  
94 # process the LITE/HEAVY
95 0 ▶ if ( exists $options->{'litetests'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"litetests"}) 0 0 0
96 0 ▶ if ( $options->{'litetests'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'litetests'}) { } 0 0 0
97 0 $self->{'litetests'} = 1;
98 } else {
99 0 $self->{'litetests'} = 0;
100 }
101 }
102  
103 # process the noasserts to load
104 0 ▶ if ( exists $options->{'noasserts'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"noasserts"}) 0 0 0
105 0 ▶ if ( $options->{'noasserts'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'noasserts'}) { } 0 0 0
106 0 $self->{'noasserts'} = 1;
107 } else {
108 0 $self->{'noasserts'} = 0;
109 }
110 }
111  
112 # process the noxsqueue to load
113 0 ▶ if ( exists $options->{'noxsqueue'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"noxsqueue"}) 0 0 0
114 0 ▶ if ( $options->{'noxsqueue'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'noxsqueue'}) { } 0 0 0
115 0 $self->{'noxsqueue'} = 1;
116 } else {
117 0 $self->{'noxsqueue'} = 0;
118 }
119 }
120  
121 # FIXME process the plugins to load -> "types"
122  
123 # FIXME process the versions to load
124  
125 # FIXME process the loops to load
126 }
127  
128 # some sanity tests
129 0 ▶ if ( ! -d 'results' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "results") 0 0 0
130 0 die "The 'results' directory is not found in the working directory!";
131 }
132 0 ▶ if ( ! -d 'images' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "images") 0 0 0
133 0 die "The 'images' directory is not found in the working directory!";
134 }
135  
136 0 return;
137 }
138  
139 # starts the process of loading all of our YAML images
140 0 ▶sub loadtests {
Subroutine loadtests: not called CC=18 SCAR=58.3
Pod undocumented
141 0 my $self = shift;
142  
143 # gather all the YAML dumps
144 0 ▶ if ( opendir( DUMPS, 'results' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir DUMPS, 'results') { } 0 0 0
145 0 foreach my $d ( readdir( DUMPS ) ) {
146 # parse the file structure
147 # POE-1.0002-IO_Poll-LITE-assert-noxsqueue.yml
148 0 ▶ if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/) 0 0 0
149 0 my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
150  
151 # skip this file?
152 0 ▶ if ( $self->noxsqueue ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->noxsqueue) { } 0 0 0
153 0 ▶ if ( $xsqueue eq 'xsqueue' ) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($xsqueue eq "xsqueue") 0 0 0
154 } else {
155 0 ▶ if ( defined $self->noxsqueue ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->noxsqueue) 0 0 0
156 0 ▶ if ( $xsqueue eq 'noxsqueue' ) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($xsqueue eq "noxsqueue") 0 0 0
157 }
158 }
159 0 ▶ if ( $self->noasserts ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->noasserts) { } 0 0 0
160 0 ▶ if ( $assert eq 'assert' ) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($assert eq "assert") 0 0 0
161 } else {
162 0 ▶ if ( defined $self->noasserts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->noasserts) 0 0 0
163 0 ▶ if ( $assert eq 'noassert' ) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($assert eq "noassert") 0 0 0
164 }
165 }
166 0 ▶ if ( $self->litetests ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->litetests) { } 0 0 0
167 0 ▶ if ( $lite eq 'HEAVY' ) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($lite eq "HEAVY") 0 0 0
168 } else {
169 0 ▶ if ( $lite eq 'LITE' ) { next }
Branch: 1 branch
BranchTrueFalseTotal
if ($lite eq "LITE") 0 0 0
170 }
171  
172 # FIXME allow selective loading of tests, so we can control what to image, etc
173  
174 # actually load this file!
175 0 $self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
176 }
177 }
178 0 ▶ closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
Branch: 1 branch
BranchTrueFalseTotal
closedir DUMPS or die q[[IMAGER] Unable to read from 'results' -> ] . $! 0 0 0
179 } else {
180 0 die "[IMAGER] Unable to open 'results' for reading -> " . $!;
181 }
182  
183 # sanity
184 0 ▶ if ( ! exists $self->{'data'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}) 0 0 0
185 0 die "[IMAGER] Unable to find valid POE test result(s) in the 'results' directory!\n";
186 }
187  
188 0 ▶ if ( ! $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
189 0 print "[IMAGER] Done with parsing the YAML files...\n";
190 }
191  
192 0 return;
193 }
194  
195 # loads the yaml of a specific file
196 0 ▶sub load_yaml {
Subroutine load_yaml: not called CC=22 SCAR=62.3
Pod undocumented
197 0 my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
198  
199 0 my $yaml = YAML::Tiny->read( 'results/' . $file );
200 0 ▶ if ( ! defined $yaml ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $yaml) { } 0 0 0
201 0 print "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
202 0 return;
203 } else {
204 # inrospect it!
205 0 my $isvalid = 0;
206 0 eval {
207 # simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
208 0 ▶ if ( defined $yaml->[0] and exists $yaml->[0]->{'x_bench'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yaml->[0] and exists $yaml->[0]{'x_bench'}) { } 0 0 0
Condition0%0/3
defined $yaml->[0] and exists $yaml->[0]{"x_bench"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $yaml->[0] and exists $yaml->[0]{"x_bench"}
defined $yaml->[0] exists $yaml->[0]{"x_bench"}
Truth table0%0/3
A and B
A= defined $yaml->[0]B= exists $yaml->[0]{"x_bench"}
ABresult
0X0
100
111
209 # version must at least match us
210 0 ▶ $isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$yaml->[0]{'x_bench'} eq currentTestVersion() ? : 0 0 0
211 } else {
212 0 $isvalid = undef;
213 }
214 };
215 0 ▶ if ( ! $isvalid or $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $isvalid or $@) { } 0 0 0
Condition0%0/3
not $isvalid or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
not $isvalid or $@
not $isvalid $@
Truth table0%0/3
not(A) or B
A= not $isvalidB= $@
ABresult
1X1
011
000
216 0 print "[IMAGER] Detected outdated/corrupt benchmark result: $file";
217 0 return;
218 } else {
219 # reduce indirection
220 0 $yaml = $yaml->[0];
221 }
222 }
223  
224 # store the POE version
225 0 $self->{'poe_versions'}->{ $ver } = 1;
226  
227 # sanity check the loop master version ( which should always be our "installed" version, not per-POE )
228 0 ▶ if ( exists $yaml->{'poe'}->{'loop_m'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $yaml->{"poe"}{"loop_m"}) 0 0 0
229 0 ▶ if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'poe_loops'}{$loop}) { } 0 0 0
230 0 $self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
231 } else {
232 0 ▶ if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"poe_loops"}{$loop} ne $yaml->{"poe"}{"loop_m"}) 0 0 0
233 die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
234 0 "' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
235 }
236 }
237 }
238  
239 # get the info we're interested in
240 0 $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
241 0 $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
242  
243 0 ▶ if ( exists $yaml->{'pid'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $yaml->{"pid"}) 0 0 0
244 0 $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
245 }
246 0 ▶ if ( exists $yaml->{'poe'}->{'modules'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $yaml->{"poe"}{"modules"}) 0 0 0
247 0 $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
248 }
249  
250 # sanity check the perl stuff
251 0 ▶ if ( exists $yaml->{'perl'}->{'binary'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $yaml->{"perl"}{"binary"}) 0 0 0
252 0 ▶ if ( ! exists $self->{'data'}->{'perlconfig'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'data'}{'perlconfig'}) { } 0 0 0
253 0 $self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
254 0 $self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
255 } else {
256 0 ▶ if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}{"perlconfig"}{"binary"} ne $yaml->{"perl"}{"binary"}) 0 0 0
257 die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
258 0 "' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
259 }
260 0 ▶ if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}{"perlconfig"}{"version"} ne $yaml->{"perl"}{"v"}) 0 0 0
261 die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
262 0 "' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
263 }
264 }
265 }
266  
267 # sanity check the uname
268 0 ▶ if ( exists $yaml->{'uname'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $yaml->{"uname"}) 0 0 0
269 0 ▶ if ( ! exists $self->{'data'}->{'uname'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'data'}{'uname'}) { } 0 0 0
270 0 $self->{'data'}->{'uname'} = $yaml->{'uname'};
271 } else {
272 0 ▶ if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}{"uname"} ne $yaml->{"uname"}) 0 0 0
273 die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
274 0 "' while others had '" . $self->{'data'}->{'uname'} . "'";
275 }
276 }
277 }
278  
279 # sanity check the cpu name
280 0 ▶ if ( exists $yaml->{'cpu'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $yaml->{"cpu"}) 0 0 0
281 0 ▶ if ( ! exists $self->{'data'}->{'cpu'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'data'}{'cpu'}) { } 0 0 0
282 0 $self->{'data'}->{'cpu'} = $yaml->{'cpu'};
283 } else {
284 0 ▶ if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}{"cpu"}{"name"} ne $yaml->{"cpu"}{"name"}) 0 0 0
285 die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
286 0 "' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
287 }
288 }
289 }
290  
291 0 return;
292 }
293  
294 0 ▶sub process_data {
Subroutine process_data: not called CC=2 SCAR=17.9
Pod undocumented
295 0 my $self = shift;
296  
297 # sanitize the versions in an ordered loop
298 0 $self->{'poe_versions_sorted'} = [ map { $_->stringify }
299 0 sort { $a <=> $b }
300 0 map { version->new($_) } keys %{ $self->poe_versions }
301 ];
302  
303 0 ▶ if ( ! $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
304 0 print "[IMAGER] Done with processing the benchmark statistics...\n";
305 }
306  
307 0 return;
308 }
309  
310 0 ▶sub generate_images {
Subroutine generate_images: not called CC=11 SCAR=48.8
Pod undocumented
311 0 my $self = shift;
312  
313 # load our plugins and let them have fun :)
314 0 foreach my $plugin ( $self->plugins ) {
315 # actually load it!
316 ## no critic
317 0 eval "require $plugin";
318 ## use critic
319 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
320 0 ▶ if ( ! $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
321 0 print "[IMAGER] Unable to load plugin $plugin -> $@\n";
322 0 next;
323 }
324 }
325  
326 # sanity checks
327 0 ▶ if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin->can("new") and $plugin->can("imager")) 0 0 0
Condition0%0/3
$plugin->can("new") and $plugin->can("imager")
!ll&&!rl&&r
000
MC/DC0%0/2
$plugin->can("new") and $plugin->can("imager")
$plugin->can("new") $plugin->can("imager")
Truth table0%0/3
A and B
A= $plugin->can("new")B= $plugin->can("imager")
ABresult
0X0
100
111
328 # FIXME did we want this plugin?
329  
330 # create the plugin's home dir
331 0 my $homedir = $plugin;
332 0 ▶ if ( $homedir =~ /\:\:(\w+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($homedir =~ /\:\:(\w+)$/) { } 0 0 0
333 0 $homedir = $1;
334 } else {
335 0 die "barf";
336 }
337 0 ▶ if ( ! -d "images/$homedir" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d "images/$homedir") 0 0 0
338 # create it!
339 0 ▶ if ( ! mkdir( "images/$homedir" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (mkdir "images/$homedir") 0 0 0
340 0 die "[IMAGER] Unable to create plugin directory: $homedir";
341 }
342 }
343  
344 # Okay, get this plugin!
345 0 my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
346  
347 0 ▶ if ( ! $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
348 0 print "[IMAGER] Processing the $plugin plugin...\n";
349 }
350  
351 0 $obj->imager( $self );
352 }
353 }
354  
355 0 ▶ if ( ! $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
356 0 print "[IMAGER] Done with generating images...\n";
357 }
358  
359 0 return;
360 }
361  
362 1 1;
363 __END__
« Benchmarker.pm ↑ Summary Benchmarker/GetPOEdists.pm »