Benchmarker/Imager/BasicStatistics.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Benchmarker/GetInstalledLoops.pm ↑ Summary
1 # Declare our package
2 package POE::Devel::Benchmarker::Imager::BasicStatistics;
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 $VERSION = '0.05';
8  
9 # the GD stuff
10 0 ▶use GD::Graph::lines;
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use GD::Graph::colour qw( :lists );
12  
13 # import some stuff
14 use POE::Devel::Benchmarker::Utils qw( currentMetrics );
15  
16 # creates a new instance
17 sub new {
18 my $class = shift;
19 my $opts = shift;
20  
21 # instantitate ourself
22 my $self = {
23 'opts' => $opts,
24 };
25 return bless $self, $class;
26 }
27  
28 # actually generates the graphs!
29 sub imager {
30 my $self = shift;
31 $self->{'imager'} = shift;
32  
33 # generate the loops vs each other graphs
34 $self->generate_loopwars;
35  
36 # generate the single loop performance
37 $self->generate_loopperf;
38  
39 # generate the loop assert/xsqueue ( 4 lines ) per metric
40 $self->generate_loopoptions;
41  
42 return;
43 }
44  
45 # charts a single loop's progress over POE versions
46 sub generate_loopoptions {
47 my $self = shift;
48  
49 if ( ! $self->{'imager'}->quiet ) {
50 print "[BasicStatistics] Generating the Loop-Options graphs...\n";
51 }
52  
53 # go through all the loops we want
54 foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
55 foreach my $metric ( @{ currentMetrics() } ) {
56 my %data;
57  
58 # organize data by POE version
59 foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
60 # go through the combo of assert/xsqueue
61 foreach my $assert ( qw( assert noassert ) ) {
62 if ( ! exists $self->{'imager'}->data->{ $assert } ) {
63 next;
64 }
65 foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
66 if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
67 next;
68 }
69  
70 # sometimes we cannot test a metric
71 if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
72 and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
73 and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
74 ) {
75 push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
76 } else {
77 push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
78 }
79 }
80 }
81 }
82  
83 # it's possible for us to do runs without assert/xsqueue
84 if ( scalar keys %data > 0 ) {
85 # transform %data into something GD likes
86 my @data_for_gd;
87 foreach my $m ( sort keys %data ) {
88 push( @data_for_gd, $data{ $m } );
89 }
90  
91 # send it to GD!
92 $self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
93 [ sort keys %data ],
94 \@data_for_gd,
95 );
96 }
97 }
98 }
99  
100 return;
101 }
102  
103 # charts a single loop's progress over POE versions
104 sub generate_loopperf {
105 my $self = shift;
106  
107 if ( ! $self->{'imager'}->quiet ) {
108 print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
109 }
110  
111 # go through all the loops we want
112 foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
113 # go through the combo of assert/xsqueue
114 foreach my $assert ( qw( assert noassert ) ) {
115 if ( ! exists $self->{'imager'}->data->{ $assert } ) {
116 next;
117 }
118 foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
119 if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
120 next;
121 }
122 my %data;
123  
124 # organize data by POE version
125 foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
126 foreach my $metric ( @{ currentMetrics() } ) {
127 # sometimes we cannot test a metric
128 if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
129 and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
130 and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
131 ) {
132 push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
133 } else {
134 push( @{ $data{ $metric } }, 0 );
135 }
136 }
137 }
138  
139 # transform %data into something GD likes
140 my @data_for_gd;
141 foreach my $m ( sort keys %data ) {
142 push( @data_for_gd, $data{ $m } );
143 }
144  
145 # send it to GD!
146 $self->make_gdgraph( 'Bench_' . $loop,
147 [ sort keys %data ],
148 \@data_for_gd,
149 $assert,
150 $xsqueue,
151 );
152 }
153 }
154 }
155  
156 return;
157 }
158  
159 # loop wars!
160 sub generate_loopwars {
161 my $self = shift;
162  
163 if ( ! $self->{'imager'}->quiet ) {
164 print "[BasicStatistics] Generating the LoopWars graphs...\n";
165 }
166  
167 # go through all the metrics we want
168 foreach my $metric ( @{ currentMetrics() } ) {
169 # go through the combo of assert/xsqueue
170 foreach my $assert ( qw( assert noassert ) ) {
171 if ( ! exists $self->{'imager'}->data->{ $assert } ) {
172 next;
173 }
174 foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
175 if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
176 next;
177 }
178 my %data;
179  
180 # organize data by POE version
181 foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
182 foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
183 # sometimes we cannot test a metric
184 if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
185 and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
186 and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
187 ) {
188 push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
189 } else {
190 push( @{ $data{ $loop } }, 0 );
191 }
192 }
193 }
194  
195 # transform %data into something GD likes
196 my @data_for_gd;
197 foreach my $m ( sort keys %data ) {
198 push( @data_for_gd, $data{ $m } );
199 }
200  
201 # send it to GD!
202 $self->make_gdgraph( "LoopWar_$metric",
203 [ sort keys %{ $self->{'imager'}->poe_loops } ],
204 \@data_for_gd,
205 $assert,
206 $xsqueue,
207 );
208 }
209 }
210 }
211  
212 return;
213 }
214  
215 sub make_gdgraph {
216 my $self = shift;
217 my $metric = shift;
218 my $legend = shift;
219 my $data = shift;
220 my $assert = shift;
221 my $xsqueue = shift;
222  
223 # build the title
224 my $title = $metric;
225 if ( defined $assert ) {
226 $title .= ' (';
227 if ( defined $xsqueue ) {
228 $title .= $assert . ' ' . $xsqueue;
229 } else {
230 $title .= $assert;
231 }
232 $title .= ')';
233 } else {
234 if ( defined $xsqueue ) {
235 $title .= ' (' . $xsqueue . ')';
236 }
237 }
238  
239 # Get the graph object
240 my $graph = new GD::Graph::lines( 800, 600 );
241  
242 # Set some stuff
243 $graph->set(
244 'title' => $title,
245 'line_width' => 1,
246 'boxclr' => 'black',
247 'overwrite' => 0,
248 'x_labels_vertical' => 1,
249 'x_all_ticks' => 1,
250 'legend_placement' => 'BL',
251 'y_label' => 'iterations/sec',
252 'transparent' => 0,
253 'long_ticks' => 1,
254 ) or die $graph->error;
255  
256 # Set the legend
257 $graph->set_legend( @$legend );
258  
259 # Set Font stuff
260 $graph->set_legend_font( GD::gdMediumBoldFont );
261 $graph->set_x_axis_font( GD::gdMediumBoldFont );
262 $graph->set_y_axis_font( GD::gdMediumBoldFont );
263 $graph->set_y_label_font( GD::gdMediumBoldFont );
264 $graph->set_title_font( GD::gdGiantFont );
265  
266 # set the line colors
267 $graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' } sorted_colour_list() ] );
268  
269 # Manufacture the data
270 my $readydata = [
271 [ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
272 @$data,
273 ];
274  
275 # Plot it!
276 $graph->plot( $readydata ) or die $graph->error;
277  
278 # Print it!
279 my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
280 ( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
281 ( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
282 '.png';
283 open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
284 binmode( $fh );
285 print $fh $graph->gd->png();
286 close( $fh );
287  
288 return;
289 }
290  
291 1;
292 __END__
« Benchmarker/GetInstalledLoops.pm ↑ Summary