Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge.pm |
Statements | Executed 413 statements in 18.1ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 5.63ms | 11.7ms | BEGIN@58 | RTP::Webmerge::
1 | 1 | 1 | 4.43ms | 98.6ms | BEGIN@15 | RTP::Webmerge::
74 | 5 | 1 | 3.82ms | 347s | callProcessor | RTP::Webmerge::
1 | 1 | 1 | 3.46ms | 87.9ms | BEGIN@18 | RTP::Webmerge::
1 | 1 | 1 | 970µs | 1.44ms | initConfig | RTP::Webmerge::
1 | 1 | 1 | 933µs | 2.79ms | collectOutputs | RTP::Webmerge::
1 | 1 | 1 | 298µs | 3.40ms | checkConfig | RTP::Webmerge::
1 | 1 | 1 | 112µs | 116µs | collectExecutables | RTP::Webmerge::
1 | 1 | 1 | 86µs | 376µs | BEGIN@8 | RTP::Webmerge::
1 | 1 | 1 | 73µs | 151µs | BEGIN@201 | RTP::Webmerge::
1 | 1 | 1 | 72µs | 211µs | BEGIN@21 | RTP::Webmerge::
1 | 1 | 1 | 57µs | 57µs | BEGIN@34.10 | RTP::Webmerge::
1 | 1 | 1 | 55µs | 87µs | BEGIN@10 | RTP::Webmerge::
1 | 1 | 1 | 52µs | 141µs | BEGIN@9 | RTP::Webmerge::
1 | 1 | 1 | 32µs | 32µs | BEGIN@40 | RTP::Webmerge::
1 | 1 | 1 | 31µs | 31µs | BEGIN@37 | RTP::Webmerge::
1 | 1 | 1 | 26µs | 26µs | checkPrograms | RTP::Webmerge::
1 | 1 | 1 | 25µs | 25µs | BEGIN@31 | RTP::Webmerge::
1 | 1 | 1 | 25µs | 25µs | BEGIN@34 | RTP::Webmerge::
1 | 1 | 1 | 14µs | 14µs | END | RTP::Webmerge::
1 | 1 | 1 | 4µs | 4µs | CORE:sort (opcode) | RTP::Webmerge::
0 | 0 | 0 | 0s | 0s | __ANON__[:470] | RTP::Webmerge::
0 | 0 | 0 | 0s | 0s | callProgram | RTP::Webmerge::
0 | 0 | 0 | 0s | 0s | checkProcesses | RTP::Webmerge::
0 | 0 | 0 | 0s | 0s | range | RTP::Webmerge::
0 | 0 | 0 | 0s | 0s | runProgram | RTP::Webmerge::
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 | package RTP::Webmerge; | ||||
6 | ################################################################################################### | ||||
7 | |||||
8 | 2 | 169µs | 2 | 666µs | # spent 376µs (86+290) within RTP::Webmerge::BEGIN@8 which was called:
# once (86µs+290µs) by main::BEGIN@28 at line 8 # spent 376µs making 1 call to RTP::Webmerge::BEGIN@8
# spent 290µs making 1 call to Exporter::import |
9 | 2 | 142µs | 2 | 231µs | # spent 141µs (52+90) within RTP::Webmerge::BEGIN@9 which was called:
# once (52µs+90µs) by main::BEGIN@28 at line 9 # spent 141µs making 1 call to RTP::Webmerge::BEGIN@9
# spent 90µs making 1 call to strict::import |
10 | 2 | 169µs | 2 | 119µs | # spent 87µs (55+32) within RTP::Webmerge::BEGIN@10 which was called:
# once (55µs+32µs) by main::BEGIN@28 at line 10 # spent 87µs making 1 call to RTP::Webmerge::BEGIN@10
# spent 32µs making 1 call to warnings::import |
11 | |||||
12 | ################################################################################################### | ||||
13 | |||||
14 | # load 3rd party module | ||||
15 | 2 | 708µs | 2 | 98.8ms | # spent 98.6ms (4.43+94.1) within RTP::Webmerge::BEGIN@15 which was called:
# once (4.43ms+94.1ms) by main::BEGIN@28 at line 15 # spent 98.6ms making 1 call to RTP::Webmerge::BEGIN@15
# spent 240µs making 1 call to Exporter::import |
16 | |||||
17 | # override core glob (case insensitive) | ||||
18 | 2 | 755µs | 2 | 88.5ms | # spent 87.9ms (3.46+84.4) within RTP::Webmerge::BEGIN@18 which was called:
# once (3.46ms+84.4ms) by main::BEGIN@28 at line 18 # spent 87.9ms making 1 call to RTP::Webmerge::BEGIN@18
# spent 672µs making 1 call to File::Glob::import |
19 | |||||
20 | # load function from core module | ||||
21 | 2 | 352µs | 2 | 350µs | # spent 211µs (72+139) within RTP::Webmerge::BEGIN@21 which was called:
# once (72µs+139µs) by main::BEGIN@28 at line 21 # spent 211µs making 1 call to RTP::Webmerge::BEGIN@21
# spent 139µs making 1 call to Exporter::import |
22 | |||||
23 | ################################################################################################### | ||||
24 | |||||
25 | # declare local globals | ||||
26 | 1 | 4µs | our (%programs, %executables, %processors, @initers, @checkers); | ||
27 | |||||
28 | ################################################################################################### | ||||
29 | |||||
30 | # define our version string | ||||
31 | 1 | 149µs | 1 | 25µs | # spent 25µs within RTP::Webmerge::BEGIN@31 which was called:
# once (25µs+0s) by main::BEGIN@28 at line 31 # spent 25µs making 1 call to RTP::Webmerge::BEGIN@31 |
32 | |||||
33 | # load exporter and inherit from it | ||||
34 | 3 | 371µs | 2 | 82µs | BEGIN { use Exporter qw(); our @ISA = qw(Exporter) } # spent 57µs making 1 call to RTP::Webmerge::BEGIN@34.10
# spent 25µs making 1 call to RTP::Webmerge::BEGIN@34 |
35 | |||||
36 | # define our functions to be exported | ||||
37 | 1 | 195µs | 1 | 31µs | # spent 31µs within RTP::Webmerge::BEGIN@37 which was called:
# once (31µs+0s) by main::BEGIN@28 at line 37 # spent 31µs making 1 call to RTP::Webmerge::BEGIN@37 |
38 | |||||
39 | # define our functions that can be exported | ||||
40 | 1 | 458µs | 1 | 32µs | # spent 32µs within RTP::Webmerge::BEGIN@40 which was called:
# once (32µs+0s) by main::BEGIN@28 at line 40 # spent 32µs making 1 call to RTP::Webmerge::BEGIN@40 |
41 | |||||
42 | ################################################################################################### | ||||
43 | |||||
44 | sub range | ||||
45 | { | ||||
46 | |||||
47 | my ($value, $from, $to, $max) = @_; | ||||
48 | |||||
49 | my $val = int(($_[2] - $_[1]) / 9 * $_[0] + $_[1] + 0.5); | ||||
50 | |||||
51 | return $val < $max ? $val : $max; | ||||
52 | |||||
53 | } | ||||
54 | |||||
55 | ################################################################################################### | ||||
56 | |||||
57 | # make absolute paths (file may not exist yet) | ||||
58 | 2 | 3.15ms | 2 | 12.1ms | # spent 11.7ms (5.63+6.11) within RTP::Webmerge::BEGIN@58 which was called:
# once (5.63ms+6.11ms) by main::BEGIN@28 at line 58 # spent 11.7ms making 1 call to RTP::Webmerge::BEGIN@58
# spent 382µs making 1 call to Exporter::import |
59 | |||||
60 | # collect all includes | ||||
61 | # return result hash | ||||
62 | sub collectOutputs | ||||
63 | # spent 2.79ms (933µs+1.86) within RTP::Webmerge::collectOutputs which was called:
# once (933µs+1.86ms) by RTP::Webmerge::checkConfig at line 306 | ||||
64 | |||||
65 | # get input variables | ||||
66 | 1 | 3µs | my ($config) = @_; | ||
67 | |||||
68 | # assertion that we only run once | ||||
69 | 1 | 3µs | return if (exists $config->{'outpaths'}); | ||
70 | |||||
71 | # get local variables from config | ||||
72 | 1 | 3µs | my $paths = $config->{'paths'}; | ||
73 | 1 | 5µs | my $doctype = $config->{'doctype'}; | ||
74 | |||||
75 | # get local arrays from loaded xml file | ||||
76 | 1 | 6µs | my $merges = $config->{'xml'}->{'merge'} || []; | ||
77 | 1 | 6µs | my $headers = $config->{'xml'}->{'header'} || []; | ||
78 | |||||
79 | # local variable | ||||
80 | 1 | 4µs | $config->{'outpaths'} = {}; | ||
81 | |||||
82 | # reset webpath after this block (make local) | ||||
83 | 1 | 6µs | local $config->{'webpath'} = $config->{'webpath'}; | ||
84 | |||||
85 | 1 | 5µs | foreach my $block (@{$merges || []}) | ||
86 | { | ||||
87 | |||||
88 | # change directory (restore previous state after this block) | ||||
89 | 1 | 38µs | 1 | 21µs | my $dir = RTP::Webmerge::Path->chdir($block->{'chdir'}); # spent 21µs making 1 call to RTP::Webmerge::Path::chdir |
90 | |||||
91 | # process all types | ||||
92 | 1 | 9µs | foreach my $type ('css', 'js') | ||
93 | { | ||||
94 | |||||
95 | # process all include entries | ||||
96 | 2 | 40µs | foreach my $merge (map { @{$_->{$type} || []} } @{$merges || {} }) | ||
97 | { | ||||
98 | |||||
99 | # change directory (restore previous state after this block) | ||||
100 | 2 | 43µs | 2 | 447µs | my $dir = RTP::Webmerge::Path->chdir($merge->{'chdir'}); # spent 447µs making 2 calls to RTP::Webmerge::Path::chdir, avg 224µs/call |
101 | |||||
102 | # get id of this merge | ||||
103 | 2 | 9µs | my $id = $merge->{'id'}; | ||
104 | |||||
105 | # create and assign info hash for this merge | ||||
106 | 2 | 27µs | my $info = $config->{'outpaths'}->{$id} = { 'out' => {} }; | ||
107 | |||||
108 | # store some important attributes | ||||
109 | 2 | 10µs | $info->{'id'} = $merge->{'id'}; | ||
110 | 2 | 8µs | $info->{'type'} = $type; | ||
111 | 2 | 6µs | $info->{'media'} = $merge->{'media'}; | ||
112 | 2 | 10µs | $info->{'disabled'} = $merge->{'disabled'} || 'false'; | ||
113 | |||||
114 | # process all files to be written for this merge | ||||
115 | 2 | 58µs | 2 | 27µs | foreach my $output (@{$merge->{'output'} || []}) # spent 27µs making 2 calls to RTP::Webmerge::Path::DESTROY, avg 14µs/call |
116 | { | ||||
117 | |||||
118 | # get the class name for this output | ||||
119 | 18 | 57µs | my $class = $output->{'class'} || 'default'; | ||
120 | |||||
121 | # assert that the target has been given for this output | ||||
122 | 18 | 29µs | die 'no target given for output' unless $output->{'target'}; | ||
123 | |||||
124 | # create another sub hash for this class if needed | ||||
125 | 18 | 42µs | $info->{'out'}->{$class} = {} unless exists $info->{'out'}->{$class}; | ||
126 | |||||
127 | # store the filepath for this merge output (by class/target) | ||||
128 | # do not yet check for existence of the path as it may be created later | ||||
129 | 18 | 352µs | 18 | 1.36ms | $info->{'out'}->{$class}->{$output->{'target'}} = res_path($output->{'path'}); # spent 1.36ms making 18 calls to RTP::Webmerge::Path::res_path, avg 76µs/call |
130 | |||||
131 | } | ||||
132 | # EO each output | ||||
133 | |||||
134 | } | ||||
135 | # EO each merge | ||||
136 | |||||
137 | } | ||||
138 | # EO each type (css/js) | ||||
139 | |||||
140 | } | ||||
141 | |||||
142 | # return success | ||||
143 | 1 | 35µs | return 1; | ||
144 | |||||
145 | } | ||||
146 | # EO sub collectOutputs | ||||
147 | |||||
148 | ################################################################################################### | ||||
149 | |||||
150 | # collect available executables | ||||
151 | # add them to the programs hash | ||||
152 | sub collectExecutables | ||||
153 | # spent 116µs (112+4) within RTP::Webmerge::collectExecutables which was called:
# once (112µs+4µs) by RTP::Webmerge::checkConfig at line 296 | ||||
154 | |||||
155 | 1 | 3µs | my ($config) = @_; | ||
156 | |||||
157 | # do checks every executable | ||||
158 | 1 | 13µs | foreach my $executable (keys %executables) | ||
159 | { | ||||
160 | |||||
161 | # get the bin path and the exec template | ||||
162 | 1 | 7µs | my ($program, $tmpl, $prio) = @{$executables{$executable}}; | ||
163 | |||||
164 | # create an array if not yet available | ||||
165 | 1 | 10µs | $programs{$program} = [] unless exists $programs{$program}; | ||
166 | |||||
167 | # skip if we have inline function | ||||
168 | 1 | 18µs | if (ref($tmpl) eq 'CODE') | ||
169 | { | ||||
170 | # finally store the info and found absolute path | ||||
171 | push(@{$programs{$program}}, [$tmpl]); | ||||
172 | } | ||||
173 | # look for external program | ||||
174 | else | ||||
175 | { | ||||
176 | |||||
177 | # get name of executable | ||||
178 | my $exec = $executable; | ||||
179 | |||||
180 | # remove optional suffix | ||||
181 | $exec =~ s/\[[a-zA-Z]+\]$//; | ||||
182 | |||||
183 | # glob finds the executable | ||||
184 | my @files = which($exec) || bsd_glob($exec); | ||||
185 | |||||
186 | if (scalar(@files) == 1 && -e $files[0] && -x $files[0] && ! -d $files[0]) | ||||
187 | { | ||||
188 | # finally store the info and found absolute path | ||||
189 | push(@{$programs{$program}}, [$tmpl, $files[0], $prio]); | ||||
190 | } | ||||
191 | |||||
192 | } | ||||
193 | |||||
194 | } | ||||
195 | # EO each executable | ||||
196 | |||||
197 | # process all collected programs | ||||
198 | 1 | 27µs | foreach my $program (keys %programs) | ||
199 | { | ||||
200 | |||||
201 | 2 | 5.64ms | 2 | 229µs | # spent 151µs (73+78) within RTP::Webmerge::BEGIN@201 which was called:
# once (73µs+78µs) by main::BEGIN@28 at line 201 # spent 151µs making 1 call to RTP::Webmerge::BEGIN@201
# spent 78µs making 1 call to warnings::unimport |
202 | |||||
203 | # sort the programs by priority so they can run in given order | ||||
204 | 1 | 50µs | 1 | 4µs | @{$programs{$program}} = sort { $a->[2] - $b->[2] } @{$programs{$program}}; # spent 4µs making 1 call to RTP::Webmerge::CORE:sort |
205 | |||||
206 | } | ||||
207 | # EO each program | ||||
208 | |||||
209 | } | ||||
210 | # EO sub collectExecutables | ||||
211 | |||||
212 | ################################################################################################### | ||||
213 | |||||
214 | # check each program to have | ||||
215 | # at least one executable | ||||
216 | sub checkPrograms | ||||
217 | # spent 26µs within RTP::Webmerge::checkPrograms which was called:
# once (26µs+0s) by RTP::Webmerge::checkConfig at line 300 | ||||
218 | |||||
219 | 1 | 3µs | my ($config) = @_; | ||
220 | |||||
221 | # do checks every executable | ||||
222 | 1 | 27µs | foreach my $program (keys %programs) | ||
223 | { | ||||
224 | 1 | 8µs | if (scalar(@{$programs{$program}}) == 0) | ||
225 | { | ||||
226 | # we should tell te user which programs | ||||
227 | # he could install to solve to problem | ||||
228 | # for gifopt this would be gifsicle | ||||
229 | die "program $program has no executables"; | ||||
230 | } | ||||
231 | } | ||||
232 | # EO each program | ||||
233 | |||||
234 | } | ||||
235 | # EO sub checkPrograms | ||||
236 | |||||
237 | ################################################################################################### | ||||
238 | |||||
239 | sub checkProcesses | ||||
240 | { | ||||
241 | |||||
242 | # to be implemented | ||||
243 | |||||
244 | } | ||||
245 | # EO sub checkProcesses | ||||
246 | |||||
247 | ################################################################################################### | ||||
248 | |||||
249 | sub initConfig | ||||
250 | # spent 1.44ms (970µs+470µs) within RTP::Webmerge::initConfig which was called:
# once (970µs+470µs) by main::RUNTIME at line 154 of webmerge/scripts/webmerge.pl | ||||
251 | |||||
252 | # get input variables | ||||
253 | 1 | 4µs | my ($config) = @_; | ||
254 | |||||
255 | # declare lexical variable | ||||
256 | 1 | 1µs | my %getopts; | ||
257 | |||||
258 | # process all registered initers | ||||
259 | 1 | 7µs | foreach my $initer (@initers) | ||
260 | { | ||||
261 | |||||
262 | # extend getopts by result from initer | ||||
263 | 12 | 742µs | 12 | 470µs | %getopts = (%getopts, $initer->($config)); # spent 75µs making 1 call to RTP::Webmerge::Embedder::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Embedder.pm:75]
# spent 71µs making 1 call to RTP::Webmerge::Process::CSS::Inlinedata::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Process/CSS/Inlinedata.pm:338]
# spent 66µs making 1 call to RTP::Webmerge::Fingerprint::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Fingerprint.pm:52]
# spent 52µs making 1 call to RTP::Webmerge::Optimize::GZ::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/GZ.pm:47]
# spent 37µs making 1 call to RTP::Webmerge::Optimize::TXT::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/TXT.pm:108]
# spent 28µs making 1 call to RTP::Webmerge::IO::CSS::__ANON__[webmerge/scripts/modules/RTP/Webmerge/IO/CSS.pm:202]
# spent 25µs making 1 call to RTP::Webmerge::Optimize::ZIP::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/ZIP.pm:47]
# spent 25µs making 1 call to RTP::Webmerge::Optimize::GIF::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/GIF.pm:47]
# spent 24µs making 1 call to RTP::Webmerge::Optimize::JPG::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/JPG.pm:48]
# spent 23µs making 1 call to RTP::Webmerge::HeadInc::__ANON__[webmerge/scripts/modules/RTP/Webmerge/HeadInc.pm:49]
# spent 22µs making 1 call to RTP::Webmerge::Optimize::MNG::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/MNG.pm:51]
# spent 22µs making 1 call to RTP::Webmerge::Optimize::PNG::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/PNG.pm:52] |
264 | |||||
265 | } | ||||
266 | # EO each initers | ||||
267 | |||||
268 | # return the hash as list | ||||
269 | 1 | 47µs | return %getopts; | ||
270 | |||||
271 | } | ||||
272 | # EO sub initConfig | ||||
273 | |||||
274 | ################################################################################################### | ||||
275 | |||||
276 | # check everything | ||||
277 | sub checkConfig | ||||
278 | # spent 3.40ms (298µs+3.10) within RTP::Webmerge::checkConfig which was called:
# once (298µs+3.10ms) by main::RUNTIME at line 494 of webmerge/scripts/webmerge.pl | ||||
279 | |||||
280 | # get input variables | ||||
281 | 1 | 3µs | my ($config) = @_; | ||
282 | |||||
283 | # only do the config check once | ||||
284 | 1 | 3µs | return if $config->{'checked'}; | ||
285 | |||||
286 | # process all registered checkers | ||||
287 | 1 | 6µs | foreach my $checker (@checkers) | ||
288 | { | ||||
289 | # just call the sub | ||||
290 | 7 | 100µs | 7 | 168µs | $checker->($config) # spent 42µs making 1 call to RTP::Webmerge::Optimize::TXT::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/TXT.pm:132]
# spent 22µs making 1 call to RTP::Webmerge::Optimize::GIF::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/GIF.pm:72]
# spent 22µs making 1 call to RTP::Webmerge::Optimize::JPG::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/JPG.pm:71]
# spent 21µs making 1 call to RTP::Webmerge::Optimize::ZIP::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/ZIP.pm:72]
# spent 21µs making 1 call to RTP::Webmerge::Optimize::MNG::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/MNG.pm:77]
# spent 20µs making 1 call to RTP::Webmerge::Optimize::PNG::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/PNG.pm:80]
# spent 19µs making 1 call to RTP::Webmerge::Optimize::GZ::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Optimize/GZ.pm:72] |
291 | } | ||||
292 | # EO each checkers | ||||
293 | |||||
294 | # collect available executables, some programs | ||||
295 | # may can use multiple executables (like pngopt) | ||||
296 | 1 | 12µs | 1 | 116µs | collectExecutables($config); # spent 116µs making 1 call to RTP::Webmerge::collectExecutables |
297 | |||||
298 | # check if programs are available | ||||
299 | # each needs at least one executable | ||||
300 | 1 | 12µs | 1 | 26µs | checkPrograms($config); # spent 26µs making 1 call to RTP::Webmerge::checkPrograms |
301 | |||||
302 | # only check the config once | ||||
303 | 1 | 5µs | $config->{'checked'} = 1; | ||
304 | |||||
305 | # collect output information | ||||
306 | 1 | 10µs | 1 | 2.79ms | collectOutputs($config); # spent 2.79ms making 1 call to RTP::Webmerge::collectOutputs |
307 | |||||
308 | # return success | ||||
309 | 1 | 27µs | return $config; | ||
310 | |||||
311 | } | ||||
312 | # EO sub checkConfig | ||||
313 | |||||
314 | ################################################################################################### | ||||
315 | |||||
316 | # call a program with a file | ||||
317 | # also accept files array ref | ||||
318 | sub runProgram ($$$$;$) | ||||
319 | { | ||||
320 | |||||
321 | # get input variables | ||||
322 | my ($config, $program, $files, $pattern, $options) = @_; | ||||
323 | |||||
324 | # get the collected executables | ||||
325 | my $executables = $programs{$program}; | ||||
326 | |||||
327 | # check if we requested a valid program (typo?) | ||||
328 | die "program $program not defined" unless $executables; | ||||
329 | |||||
330 | # process all executables found for this program | ||||
331 | for (my $i = 0; $i < scalar(@{$executables}); $i++) | ||||
332 | { | ||||
333 | |||||
334 | # get options for executable and absolute path | ||||
335 | my ($tmpl, $executable) = @{$executables->[$i]}; | ||||
336 | |||||
337 | if (ref($tmpl) eq 'CODE') | ||||
338 | { | ||||
339 | |||||
340 | # print a status message for execution | ||||
341 | printf "call %s on %s (%d files)\n", | ||||
342 | $program, $pattern, scalar(@{$files}); | ||||
343 | |||||
344 | # process file or all files | ||||
345 | foreach my $file (@{$files || [$files]}) | ||||
346 | { | ||||
347 | |||||
348 | # execute the function | ||||
349 | my $rv = $tmpl->($file, $config, $options); | ||||
350 | |||||
351 | # give a warning if the executable returned an error | ||||
352 | warn "$program execution did not complete successfully\n" | ||||
353 | . " # " . join(' ', $program, $file) unless $rv; | ||||
354 | |||||
355 | } | ||||
356 | # EO each file | ||||
357 | |||||
358 | } | ||||
359 | else | ||||
360 | { | ||||
361 | |||||
362 | # init level from config value | ||||
363 | my $lvl = $config->{'level'}; | ||||
364 | |||||
365 | # get the optimization level from cmd | ||||
366 | $lvl = $1 if $tmpl =~ m/(\-o?[0-9])/i; | ||||
367 | |||||
368 | # print a status message for execution | ||||
369 | printf "exec %s (%s) on %s (%d files)\n", | ||||
370 | $executable, $lvl, $pattern, scalar(@{$files}); | ||||
371 | |||||
372 | # process file or all files | ||||
373 | foreach my $file (@{$files || [$files]}) | ||||
374 | { | ||||
375 | |||||
376 | # execute the executable (sprintf filename into commands) | ||||
377 | my $rv = system join(' ', $executable, sprintf($tmpl, $file, $file)); | ||||
378 | |||||
379 | # give a warning if the executable returned an error | ||||
380 | warn "executable execution did not complete successfully\n" | ||||
381 | . " # " . join(' ', $executable, sprintf($tmpl, $file, $file)) if $rv; | ||||
382 | |||||
383 | } | ||||
384 | # EO each file | ||||
385 | |||||
386 | } | ||||
387 | |||||
388 | } | ||||
389 | # EO each program executable | ||||
390 | |||||
391 | } | ||||
392 | # EO sub runProgram | ||||
393 | |||||
394 | ################################################################################################### | ||||
395 | |||||
396 | # childrens | ||||
397 | 1 | 3µs | my @pids; | ||
398 | |||||
399 | # call a program with a file | ||||
400 | # also accept files array ref | ||||
401 | sub callProgram ($$$$;$) | ||||
402 | { | ||||
403 | |||||
404 | # get input variables | ||||
405 | my ($config, $program, $files, $pattern, $options) = @_; | ||||
406 | |||||
407 | # make array items unqiue | ||||
408 | @{$files} = uniq(@{$files}); | ||||
409 | |||||
410 | # do not run in parallel on windows | ||||
411 | # code has been developed for linux | ||||
412 | if ($^O eq "MSWin32") | ||||
413 | { | ||||
414 | |||||
415 | # run the program with a set of all files | ||||
416 | runProgram($config, $program, $files, $pattern, $options); | ||||
417 | |||||
418 | } | ||||
419 | else | ||||
420 | { | ||||
421 | |||||
422 | # children files | ||||
423 | my (@files); | ||||
424 | |||||
425 | # create an array with all indexes | ||||
426 | my @indexes = (0 .. $#{$files}); | ||||
427 | |||||
428 | # return immediately if nothing to do | ||||
429 | return if scalar @indexes == 0; | ||||
430 | |||||
431 | # loop all jobs to distribute files | ||||
432 | for(my $j = 0; $j < $config->{'jobs'}; $j ++) | ||||
433 | { | ||||
434 | # distribute files accross all available jobs | ||||
435 | $files[$j] = [ @{$files}[grep { $_ % $config->{'jobs'} == $j } @indexes] ]; | ||||
436 | } | ||||
437 | |||||
438 | # do not wait for children | ||||
439 | # local $SIG{CHLD} = 'IGNORE'; | ||||
440 | |||||
441 | my $parent_pid = $$; | ||||
442 | |||||
443 | # hook into termination signal | ||||
444 | # this is the default sent by kill | ||||
445 | local $SIG{INT} = | ||||
446 | local $SIG{TERM} = | ||||
447 | sub | ||||
448 | { | ||||
449 | |||||
450 | # print a debug message | ||||
451 | if ($parent_pid == $$) | ||||
452 | { | ||||
453 | print "\n"; | ||||
454 | print "ABORT EXTERNAL PROGRAM \n"; | ||||
455 | print "WAITING FOR CHILDREN\n"; | ||||
456 | } | ||||
457 | |||||
458 | # wait for all jobs to finish | ||||
459 | foreach (@pids) | ||||
460 | { | ||||
461 | next unless $_; | ||||
462 | kill 'TERM', $_; | ||||
463 | waitpid ($_, 0); | ||||
464 | $_ = undef; | ||||
465 | } | ||||
466 | |||||
467 | # exit now | ||||
468 | exit; | ||||
469 | |||||
470 | }; | ||||
471 | |||||
472 | # loop all jobs to start commands on files | ||||
473 | for(my $j = 0; $j < $config->{'jobs'}; $j ++) | ||||
474 | { | ||||
475 | |||||
476 | # fork a child | ||||
477 | my $pid = fork(); | ||||
478 | |||||
479 | # os error | ||||
480 | if (not defined $pid) | ||||
481 | { | ||||
482 | die "resources not avilable for fork"; | ||||
483 | } | ||||
484 | # this is the child | ||||
485 | elsif ($pid == 0) | ||||
486 | { | ||||
487 | |||||
488 | # set process group | ||||
489 | setpgrp(0,0); | ||||
490 | |||||
491 | # run the program with a subset of files | ||||
492 | runProgram($config, $program, $files[$j], $pattern, $options); | ||||
493 | |||||
494 | # stop child | ||||
495 | exit(0); | ||||
496 | |||||
497 | } | ||||
498 | # this is the parrent | ||||
499 | else | ||||
500 | { | ||||
501 | # add child pid | ||||
502 | push @pids, $pid; | ||||
503 | } | ||||
504 | |||||
505 | } | ||||
506 | # EO forking jobs | ||||
507 | |||||
508 | # wait for all jobs to finish | ||||
509 | foreach (@pids) | ||||
510 | { | ||||
511 | next unless $_; | ||||
512 | waitpid ($_, 0); | ||||
513 | $_ = undef; | ||||
514 | } | ||||
515 | |||||
516 | } | ||||
517 | |||||
518 | } | ||||
519 | # EO sub callProgram | ||||
520 | |||||
521 | ################################################################################################### | ||||
522 | |||||
523 | # make sure to kill children | ||||
524 | END | ||||
525 | # spent 14µs within RTP::Webmerge::END which was called:
# once (14µs+0s) by main::RUNTIME at line 0 of webmerge/scripts/webmerge.pl | ||||
526 | # wait for all jobs to finish | ||||
527 | 1 | 27µs | foreach (@pids) | ||
528 | { | ||||
529 | next unless $_; | ||||
530 | kill ($_); | ||||
531 | $_ = undef; | ||||
532 | } | ||||
533 | } | ||||
534 | # EO END Block | ||||
535 | |||||
536 | ################################################################################################### | ||||
537 | |||||
538 | sub callProcessor | ||||
539 | # spent 347s (3.82ms+347) within RTP::Webmerge::callProcessor which was called 74 times, avg 4.69s/call:
# 18 times (722µs+326s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 455 of webmerge/scripts/modules/RTP/Webmerge/Merge.pm, avg 18.1s/call
# 18 times (1.19ms+21.0s) by RTP::Webmerge::Merge::writer at line 98 of webmerge/scripts/modules/RTP/Webmerge/Merge.pm, avg 1.17s/call
# 18 times (1.15ms+34.2ms) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 454 of webmerge/scripts/modules/RTP/Webmerge/Merge.pm, avg 1.96ms/call
# 18 times (700µs+16.1ms) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 456 of webmerge/scripts/modules/RTP/Webmerge/Merge.pm, avg 932µs/call
# 2 times (54µs+0s) by RTP::Webmerge::Merge::collect at line 245 of webmerge/scripts/modules/RTP/Webmerge/Merge.pm, avg 27µs/call | ||||
540 | |||||
541 | # get input variables | ||||
542 | 74 | 556µs | my ($processors, $data, $config, $item) = @_; | ||
543 | |||||
544 | # do nothing on void input | ||||
545 | 74 | 1.06ms | return unless $processors; | ||
546 | |||||
547 | # call each processor (split string by whitespace) | ||||
548 | 32 | 1.22ms | foreach my $processor (split(/\s+/, $processors)) | ||
549 | { | ||||
550 | |||||
551 | # assert that the selected processor is available | ||||
552 | 32 | 226µs | die "unknown processor $processor" unless $processors{$processor}; | ||
553 | |||||
554 | # call the processor with the given data to alter | ||||
555 | 32 | 775µs | 32 | 347s | $processors{$processor}->($data, $config, $item) or die "processor failed"; # spent 326s making 24 calls to RTP::Webmerge::Process::CSS::Spritesets::spritesets, avg 13.6s/call
# spent 21.0s making 8 calls to RTP::Webmerge::Process::CSS::Inlinedata::inlinedata, avg 2.63s/call |
556 | |||||
557 | } | ||||
558 | # EO each processor | ||||
559 | |||||
560 | } | ||||
561 | # EO sub callProcessor | ||||
562 | |||||
563 | ################################################################################################### | ||||
564 | ################################################################################################### | ||||
565 | 1 | 21µs | 1; | ||
# spent 4µs within RTP::Webmerge::CORE:sort which was called:
# once (4µs+0s) by RTP::Webmerge::collectExecutables at line 204 |