← Index
NYTProf Performance Profile   « line view »
For webmerge/scripts/webmerge.pl
  Run on Mon Oct 7 02:42:42 2013
Reported on Mon Oct 7 03:03:18 2013

Filename/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm
StatementsExecuted 118586 statements in 24.8s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
81124.0s24.0sOCBNET::Spritesets::Canvas::Distribute::::CORE:sleepOCBNET::Spritesets::Canvas::Distribute::CORE:sleep (opcode)
12111.47s30.4sOCBNET::Spritesets::Canvas::Distribute::::distributeOCBNET::Spritesets::Canvas::Distribute::distribute
484150.2ms70.3msOCBNET::Spritesets::Canvas::Distribute::::CORE:sortOCBNET::Spritesets::Canvas::Distribute::CORE:sort (opcode)
168118.21ms8.21msOCBNET::Spritesets::Canvas::Distribute::::CORE:substOCBNET::Spritesets::Canvas::Distribute::CORE:subst (opcode)
111134µs237µsOCBNET::Spritesets::Canvas::Distribute::::BEGIN@10OCBNET::Spritesets::Canvas::Distribute::BEGIN@10
11154µs86µsOCBNET::Spritesets::Canvas::Distribute::::BEGIN@11OCBNET::Spritesets::Canvas::Distribute::BEGIN@11
11154µs54µsOCBNET::Spritesets::Canvas::Distribute::::BEGIN@19.5OCBNET::Spritesets::Canvas::Distribute::BEGIN@19.5
11127µs27µsOCBNET::Spritesets::Canvas::Distribute::::BEGIN@22OCBNET::Spritesets::Canvas::Distribute::BEGIN@22
11124µs24µsOCBNET::Spritesets::Canvas::Distribute::::BEGIN@19OCBNET::Spritesets::Canvas::Distribute::BEGIN@19
11123µs23µsOCBNET::Spritesets::Canvas::Distribute::::BEGIN@16OCBNET::Spritesets::Canvas::Distribute::BEGIN@16
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1###################################################################################################
2# Copyright 2013 by Marcel Greter
3# This file is part of Webmerge (GPL3)
4####################################################################################################
5# static helper functions for canvas
6####################################################################################################
7package OCBNET::Spritesets::Canvas::Distribute;
8####################################################################################################
9
102162µs2340µs
# spent 237µs (134+103) within OCBNET::Spritesets::Canvas::Distribute::BEGIN@10 which was called: # once (134µs+103µs) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 10
use strict;
# spent 237µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@10 # spent 103µs making 1 call to strict::import
112192µs2118µs
# spent 86µs (54+32) within OCBNET::Spritesets::Canvas::Distribute::BEGIN@11 which was called: # once (54µs+32µs) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 11
use warnings;
# spent 86µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@11 # spent 32µs making 1 call to warnings::import
12
13###################################################################################################
14
15# define our version string
161141µs123µs
# spent 23µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@16 which was called: # once (23µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 16
BEGIN { $OCBNET::Spritesets::Canvas::Distribute = "0.70"; }
# spent 23µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@16
17
18# load exporter and inherit from it
193353µs277µs
# spent 54µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@19.5 which was called: # once (54µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 19 # spent 24µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@19 which was called: # once (24µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 19
BEGIN { use Exporter qw(); our @ISA = qw(Exporter); }
# spent 54µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@19.5 # spent 24µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@19
20
21# define our functions to be exported
2213.60ms127µs
# spent 27µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@22 which was called: # once (27µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 22
BEGIN { our @EXPORT = qw(distribute); }
# spent 27µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@22
23
24####################################################################################################
25
26# distribute all sprites to areas
27# according to their configurations
28sub distribute
29
# spent 30.4s (1.47+28.9) within OCBNET::Spritesets::Canvas::Distribute::distribute which was called 12 times, avg 2.53s/call: # 12 times (1.47s+28.9s) by OCBNET::Spritesets::CSS::Parser::distribute at line 329 of webmerge/scripts/modules/OCBNET/Spritesets/CSS/Parser.pm, avg 2.53s/call
{
30
31 # get our object
321252µs my ($self) = @_;
33
34 # a sprite that is enclosed can always be fitted. It's not
35 # unnormal to have some offset for the image, but mostly the
36 # container is nearly of the same size as the sprite. In some
37 # cases the dev meant to use it left aligned in a big container.
38 # then we should handle it as a left aligned image and put it
39 # on the edge. This threshold determines when to fit and when
40 # to put the sprite on the edge/stack area. Both padding will
41 # be counted (outerWidth - width > threshold).
421222µs my $threshold = 40;
43
44 ##########################################################
45
46 # reset area childrens (just in case)
4712150µs foreach my $area (@{$self->{'areas'}})
48 { $self->{$area}->{'children'} = []; }
49
50 ##########################################################
51
52 # reset distributed flag on all sprites
5312107µs foreach my $sprite (@{$self->{'sprites'}})
54492812.8ms { $sprite->{'distributed'} = 0; }
55
56 ##########################################################
57 # DISTRIBUTERS
58 ##########################################################
59
6012888µs my @distributers = (
61
62 # distribute one sprite into right top corner
63 # optimum for height enclosed sprite left/bottom aligned
64 # can remove height paddings and offset from top
65 [ $self->{'corner-rt'}, 'isRepeating||alignRight||alignTop||isFixedX', 1 ],
66
67 # distribute one sprite into left bottom corner
68 # optimum for width enclosed sprite right/top aligned
69 # can remove width paddings and offset from left
70 [ $self->{'corner-lb'}, 'isRepeating||alignLeft||alignBottom||isFixedY', 1 ],
71
72 # distribute one sprite into right bottom corners
73 # optimum for non enclosed sprite left/top aligned
74 # can remove all paddings and offset from left/top
75 [ $self->{'corner-rb'}, 'isRepeating||alignRight||alignBottom||isFixedX||isFixedY', 1 ],
76
77 # distribute one sprite into left top corner
78 # optimum for enclosed sprite right/bottom aligned
79 # can remove paddings and offset from left/top
80 [ $self->{'corner-lt'}, 'isRepeating||alignLeft||alignTop||isFlexibleY||isFlexibleX', 1 ],
81
82 # distribute the smaller items to the packed area to save precious space on the edges
83 [ $self->{'middle'}, 'isFlexibleY||isFlexibleX||outerWidth-width>$threshold||outerHeight-height>$threshold' ],
84
85 # distribute sprites into edges/stacks
86 [ $self->{'stack-l'}, 'isRepeating||alignLeft||isFlexibleY||isFlexibleX' ],
87 [ $self->{'stack-t'}, 'isRepeating||alignTop||isFlexibleY||isFlexibleX' ],
88 [ $self->{'stack-b'}, 'isRepeating||alignBottom||isFlexibleX' ],
89 [ $self->{'stack-r'}, 'isRepeating||alignRight||isFlexibleY' ],
90
91 # distribute sprites into the packed center
92 [ $self->{'middle'}, 'isFlexibleY||isFlexibleX' ],
93
94 # distribute sprites into edges
95 [ $self->{'edge-t'}, 'alignBottom||isFlexibleX||isRepeatingBoth' ],
96 [ $self->{'edge-l'}, 'alignRight||isFlexibleY||isRepeatingBoth' ],
97 [ $self->{'edge-r'}, 'alignLeft||isFlexibleY||isRepeatingBoth' ],
98 [ $self->{'edge-b'}, 'alignTop||isFlexibleX||isRepeatingBoth' ],
99
100 );
101
102 ##########################################################
103
104 # process all distributers for all areas
1051264µs foreach my $distributer (@distributers)
106 {
107
108 # get the options for this area distributer
1091681.26ms my ($area, $excludes, $max) = @{$distributer};
110
111 # replace certain keywords to be an actual object call
11216811.7ms1688.21ms $excludes =~ s/\b(?=is|not|align|width|height|outer|padding)/\$_[0]->/g;
# spent 8.21ms making 168 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:subst, avg 49µs/call
113
114 # eval the condition into a pre-compiled subroutine to call
11516865.9ms $excludes = eval sprintf 'sub { return (%s); };', $excludes;
# spent 526ms executing statements in 12 string evals (merged)
# includes 654ms spent executing 4896 calls to 1 sub defined therein. # spent 329ms executing statements in 12 string evals (merged)
# includes 262ms spent executing 4168 calls to 1 sub defined therein. # spent 278ms executing statements in 12 string evals (merged)
# includes 427ms spent executing 4184 calls to 1 sub defined therein. # spent 205ms executing statements in 12 string evals (merged)
# includes 212ms spent executing 4088 calls to 1 sub defined therein. # spent 198ms executing statements in 12 string evals (merged)
# includes 190ms spent executing 4056 calls to 1 sub defined therein. # spent 54.9ms executing statements in 12 string evals (merged)
# includes 26.3ms spent executing 736 calls to 1 sub defined therein. # spent 39.5ms executing statements in 12 string evals (merged)
# includes 27.0ms spent executing 764 calls to 1 sub defined therein. # spent 29.9ms executing statements in 12 string evals (merged)
# includes 14.8ms spent executing 376 calls to 1 sub defined therein. # spent 19.4ms executing statements in 12 string evals (merged)
# includes 23.2ms spent executing 720 calls to 1 sub defined therein. # spent 18.8ms executing statements in 12 string evals (merged)
# includes 21.4ms spent executing 648 calls to 1 sub defined therein. # spent 17.6ms executing statements in 12 string evals (merged)
# includes 72.1ms spent executing 672 calls to 1 sub defined therein. # spent 15.5ms executing statements in 12 string evals (merged)
# includes 17.8ms spent executing 504 calls to 1 sub defined therein. # spent 13.5ms executing statements in 12 string evals (merged)
# includes 34.0ms spent executing 440 calls to 1 sub defined therein. # spent 9.73ms executing statements in 12 string evals (merged)
# includes 11.8ms spent executing 280 calls to 1 sub defined therein.
116
117 # propagate any eval errors
118 # not needed but just in case
119168151µs die $@ if $@;
120
121 # process each sprite to see if it should be
122 # distributed into the currently checked area
12316881.6ms foreach my $sprite (@{$self->{'sprites'}})
124 {
125
126 # skip already distributed sprites
12765792119ms next if $sprite->{'distributed'};
128
129 # check for failed excludes
13026532329ms265324.70s next if $excludes->($sprite);
# spent 2.10s making 4896 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 111)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 428µs/call # spent 766ms making 4184 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 109)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 183µs/call # spent 607ms making 4168 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 107)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 146µs/call # spent 391ms making 4088 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 108)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 96µs/call # spent 371ms making 4056 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 110)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 91µs/call # spent 84.9ms making 672 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 101)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 126µs/call # spent 84.8ms making 440 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 104)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 193µs/call # spent 53.0ms making 648 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 102)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 82µs/call # spent 48.1ms making 764 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 112)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 63µs/call # spent 45.3ms making 736 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 113)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 62µs/call # spent 42.4ms making 280 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 106)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 152µs/call # spent 40.7ms making 504 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 103)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 81µs/call # spent 39.3ms making 720 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 100)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 55µs/call # spent 34.4ms making 376 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 105)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 92µs/call
131
132 # add sprite to area
133474452.1ms474495.7ms $area->add($sprite);
# spent 95.7ms making 4744 calls to OCBNET::Spritesets::Container::add, avg 20µs/call
134
135 # set the distributed flag
136474412.6ms $sprite->{'distributed'} = 1;
137
138 # check if we have distributed enough sprites
139474418.7ms last if $max && scalar(@{$area->{'children'}}) >= $max;
140
141 }
142 # EO each sprite
143
144 }
145 # EO each distributer
146
147 ##########################################################
148
149 # optimize space between repeaters
150963.38ms3203.21ms @{$self->{'edge-l'}->{'children'}} =
# spent 1.97ms making 192 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call # spent 1.24ms making 128 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 10µs/call
151 sort { $a->isRepeatX - $b->isRepeatX || $a->isFixedX - $b->isFixedX }
15212404µs128.18ms @{$self->{'edge-l'}->{'children'}};
# spent 8.18ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 682µs/call
153
154 # optimize space between repeaters
1551926.36ms6406.27ms @{$self->{'edge-r'}->{'children'}} =
# spent 3.80ms making 384 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call # spent 2.47ms making 256 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 10µs/call
156 sort { $b->isRepeatX - $a->isRepeatX || $a->isFixedX - $b->isFixedX }
15712225µs1215.9ms @{$self->{'edge-r'}->{'children'}};
# spent 15.9ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 1.32ms/call
158
159 # optimize space between repeaters
160963.22ms3203.20ms @{$self->{'edge-t'}->{'children'}} =
# spent 1.92ms making 192 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call # spent 1.28ms making 128 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 10µs/call
161 sort { $a->isRepeatY - $b->isRepeatY || $a->isFixedY - $b->isFixedY }
16212198µs128.05ms @{$self->{'edge-t'}->{'children'}};
# spent 8.05ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 671µs/call
163
164 # optimize space between repeaters
1652247.44ms7687.50ms @{$self->{'edge-b'}->{'children'}} =
# spent 4.43ms making 448 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call # spent 3.06ms making 320 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 10µs/call
166 sort { $b->isRepeatY - $a->isRepeatY || $a->isFixedY - $b->isFixedY }
16712179µs1238.3ms @{$self->{'edge-b'}->{'children'}};
# spent 38.3ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 3.19ms/call
168
169 ##########################################################
170
171 # unsupported sprites
1721226µs my $unsupported = 0;
173
174 # check for sprite that have not been distributed
175 # there are quite a few configurations that cannot
176 # be handled - inform the user about these problems
177123.58ms foreach my $sprite (@{$self->{'sprites'}})
178 {
179 # distributed are the ones we like
18049286.73ms next if $sprite->{'distributed'};
181 # only print header warning once
182184140µs unless ($unsupported)
183 {
1848744µs warn "\nWARNING: Some sprites are configured to be included within\n" .
185 "a spriteset, but are not possible to distribute to any area, due\n" .
186 "to invalid styles (like repeating or beeing flexible in both axes)!\n\n";
187 }
188 # print each unsupported sprite to the console
18918421.6ms110411.8ms warn sprintf " url(%s) enc(%s/%s), rep(%s/%s), pos(%s/%s)\n",
# spent 2.24ms making 184 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 12µs/call # spent 2.00ms making 184 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 11µs/call # spent 1.94ms making 184 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 11µs/call # spent 1.90ms making 184 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call # spent 1.90ms making 184 calls to OCBNET::Spritesets::Sprite::positionX, avg 10µs/call # spent 1.86ms making 184 calls to OCBNET::Spritesets::Sprite::positionY, avg 10µs/call
190 substr($sprite->{'filename'}, - 25),
191 $sprite->isFixedX, $sprite->isFixedY,
192 $sprite->isRepeatX, $sprite->isRepeatY,
193 $sprite->positionX, $sprite->positionY;
194 # increase counter
195184883µs $unsupported ++;
196 }
197
198 # wait a second make user more
199 # aware that some problem exists
2001224.0s824.0s sleep 3 if $unsupported;
# spent 24.0s making 8 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sleep, avg 3.00s/call
201
202}
203# EO sub distribute
204
205####################################################################################################
206####################################################################################################
207112µs1;
 
# spent 24.0s within OCBNET::Spritesets::Canvas::Distribute::CORE:sleep which was called 8 times, avg 3.00s/call: # 8 times (24.0s+0s) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 200, avg 3.00s/call
sub OCBNET::Spritesets::Canvas::Distribute::CORE:sleep; # opcode
# spent 70.3ms (50.2+20.2) within OCBNET::Spritesets::Canvas::Distribute::CORE:sort which was called 48 times, avg 1.47ms/call: # 12 times (30.8ms+7.50ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 167, avg 3.19ms/call # 12 times (9.58ms+6.27ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 157, avg 1.32ms/call # 12 times (4.97ms+3.21ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 152, avg 682µs/call # 12 times (4.85ms+3.20ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 162, avg 671µs/call
sub OCBNET::Spritesets::Canvas::Distribute::CORE:sort; # opcode
# spent 8.21ms within OCBNET::Spritesets::Canvas::Distribute::CORE:subst which was called 168 times, avg 49µs/call: # 168 times (8.21ms+0s) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 112, avg 49µs/call
sub OCBNET::Spritesets::Canvas::Distribute::CORE:subst; # opcode