← 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:21 2013

Filename/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm
StatementsExecuted 1624 statements in 94.9ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
21157.6ms419sRTP::Webmerge::Merge::::__ANON__[:480]RTP::Webmerge::Merge::__ANON__[:480]
18117.48ms53.4sRTP::Webmerge::Merge::::writerRTP::Webmerge::Merge::writer
1114.89ms7.20msRTP::Webmerge::Merge::::BEGIN@67RTP::Webmerge::Merge::BEGIN@67
1114.61ms12.6msRTP::Webmerge::Merge::::BEGIN@68RTP::Webmerge::Merge::BEGIN@68
18114.12ms4.12msRTP::Webmerge::Merge::::dataRTP::Webmerge::Merge::data
1801014.10ms4.10msRTP::Webmerge::Merge::::__ANON__[:384]RTP::Webmerge::Merge::__ANON__[:384]
1113.99ms10.0msRTP::Webmerge::Merge::::BEGIN@69RTP::Webmerge::Merge::BEGIN@69
36213.91ms3.91msRTP::Webmerge::Merge::::CORE:prtfRTP::Webmerge::Merge::CORE:prtf (opcode)
1113.71ms5.85msRTP::Webmerge::Merge::::BEGIN@37RTP::Webmerge::Merge::BEGIN@37
1112.41ms3.72msRTP::Webmerge::Merge::::BEGIN@66RTP::Webmerge::Merge::BEGIN@66
1112.36ms50.7msRTP::Webmerge::Merge::::BEGIN@44RTP::Webmerge::Merge::BEGIN@44
2111.64ms8.05sRTP::Webmerge::Merge::::collectRTP::Webmerge::Merge::collect
2021268µs268µsRTP::Webmerge::Merge::::CORE:sortRTP::Webmerge::Merge::CORE:sort (opcode)
111242µs419sRTP::Webmerge::Merge::::mergerRTP::Webmerge::Merge::merger
11189µs365µsRTP::Webmerge::Merge::::BEGIN@8RTP::Webmerge::Merge::BEGIN@8
11163µs539µsRTP::Webmerge::Merge::::BEGIN@70RTP::Webmerge::Merge::BEGIN@70
11162µs292µsRTP::Webmerge::Merge::::BEGIN@47RTP::Webmerge::Merge::BEGIN@47
11161µs541µsRTP::Webmerge::Merge::::BEGIN@71RTP::Webmerge::Merge::BEGIN@71
11160µs60µsRTP::Webmerge::Merge::::BEGIN@18.13RTP::Webmerge::Merge::BEGIN@18.13
11157µs576µsRTP::Webmerge::Merge::::BEGIN@53RTP::Webmerge::Merge::BEGIN@53
11156µs230µsRTP::Webmerge::Merge::::BEGIN@35RTP::Webmerge::Merge::BEGIN@35
11155µs88µsRTP::Webmerge::Merge::::BEGIN@10RTP::Webmerge::Merge::BEGIN@10
11155µs214µsRTP::Webmerge::Merge::::BEGIN@58RTP::Webmerge::Merge::BEGIN@58
11154µs425µsRTP::Webmerge::Merge::::BEGIN@32RTP::Webmerge::Merge::BEGIN@32
11154µs141µsRTP::Webmerge::Merge::::BEGIN@9RTP::Webmerge::Merge::BEGIN@9
11153µs345µsRTP::Webmerge::Merge::::BEGIN@50RTP::Webmerge::Merge::BEGIN@50
11153µs319µsRTP::Webmerge::Merge::::BEGIN@36RTP::Webmerge::Merge::BEGIN@36
11137µs37µsRTP::Webmerge::Merge::::BEGIN@24RTP::Webmerge::Merge::BEGIN@24
11126µs26µsRTP::Webmerge::Merge::::BEGIN@21RTP::Webmerge::Merge::BEGIN@21
11124µs24µsRTP::Webmerge::Merge::::BEGIN@15RTP::Webmerge::Merge::BEGIN@15
11122µs22µsRTP::Webmerge::Merge::::BEGIN@18RTP::Webmerge::Merge::BEGIN@18
2219µs9µsRTP::Webmerge::Merge::::CORE:matchRTP::Webmerge::Merge::CORE:match (opcode)
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###################################################################################################
5package RTP::Webmerge::Merge;
6###################################################################################################
7
82166µs2640µs
# spent 365µs (89+275) within RTP::Webmerge::Merge::BEGIN@8 which was called: # once (89µs+275µs) by main::BEGIN@31 at line 8
use Carp;
# spent 365µs making 1 call to RTP::Webmerge::Merge::BEGIN@8 # spent 275µs making 1 call to Exporter::import
92143µs2229µs
# spent 141µs (54+88) within RTP::Webmerge::Merge::BEGIN@9 which was called: # once (54µs+88µs) by main::BEGIN@31 at line 9
use strict;
# spent 141µs making 1 call to RTP::Webmerge::Merge::BEGIN@9 # spent 88µs making 1 call to strict::import
102197µs2120µs
# spent 88µs (55+33) within RTP::Webmerge::Merge::BEGIN@10 which was called: # once (55µs+33µs) by main::BEGIN@31 at line 10
use warnings;
# spent 88µs making 1 call to RTP::Webmerge::Merge::BEGIN@10 # spent 33µs making 1 call to warnings::import
11
12###################################################################################################
13
14# define our version string
151148µs124µs
# spent 24µs within RTP::Webmerge::Merge::BEGIN@15 which was called: # once (24µs+0s) by main::BEGIN@31 at line 15
BEGIN { $RTP::Webmerge::Merge::VERSION = "0.70" }
# spent 24µs making 1 call to RTP::Webmerge::Merge::BEGIN@15
16
17# load exporter and inherit from it
183399µs282µs
# spent 60µs within RTP::Webmerge::Merge::BEGIN@18.13 which was called: # once (60µs+0s) by main::BEGIN@31 at line 18 # spent 22µs within RTP::Webmerge::Merge::BEGIN@18 which was called: # once (22µs+0s) by main::BEGIN@31 at line 18
BEGIN { use Exporter qw(); our @ISA = qw(Exporter) }
# spent 60µs making 1 call to RTP::Webmerge::Merge::BEGIN@18.13 # spent 22µs making 1 call to RTP::Webmerge::Merge::BEGIN@18
19
20# define our functions to be exported
211282µs126µs
# spent 26µs within RTP::Webmerge::Merge::BEGIN@21 which was called: # once (26µs+0s) by main::BEGIN@31 at line 21
BEGIN { our @EXPORT = qw(merger); }
# spent 26µs making 1 call to RTP::Webmerge::Merge::BEGIN@21
22
23# define our functions to be exported
24142µs
# spent 37µs within RTP::Webmerge::Merge::BEGIN@24 which was called: # once (37µs+0s) by main::BEGIN@31 at line 27
BEGIN { our @EXPORT_OK = qw (
25 merge %reader %writer %importer %exporter
26 %joiner %includer %prefixer %processor %suffixer
271139µs137µs); }
# spent 37µs making 1 call to RTP::Webmerge::Merge::BEGIN@24
28
29###################################################################################################
30
31# load local modules
322163µs2796µs
# spent 425µs (54+371) within RTP::Webmerge::Merge::BEGIN@32 which was called: # once (54µs+371µs) by main::BEGIN@31 at line 32
use RTP::Webmerge qw(callProcessor);
# spent 425µs making 1 call to RTP::Webmerge::Merge::BEGIN@32 # spent 371µs making 1 call to Exporter::import
33
34# load our local modules
352149µs2404µs
# spent 230µs (56+174) within RTP::Webmerge::Merge::BEGIN@35 which was called: # once (56µs+174µs) by main::BEGIN@31 at line 35
use RTP::Webmerge::IO;
# spent 230µs making 1 call to RTP::Webmerge::Merge::BEGIN@35 # spent 174µs making 1 call to Exporter::import
362148µs2585µs
# spent 319µs (53+266) within RTP::Webmerge::Merge::BEGIN@36 which was called: # once (53µs+266µs) by main::BEGIN@31 at line 36
use RTP::Webmerge::Path;
# spent 319µs making 1 call to RTP::Webmerge::Merge::BEGIN@36 # spent 266µs making 1 call to Exporter::import
372689µs26.08ms
# spent 5.85ms (3.71+2.14) within RTP::Webmerge::Merge::BEGIN@37 which was called: # once (3.71ms+2.14ms) by main::BEGIN@31 at line 37
use RTP::Webmerge::Fingerprint;
# spent 5.85ms making 1 call to RTP::Webmerge::Merge::BEGIN@37 # spent 233µs making 1 call to Exporter::import
38
39###################################################################################################
40# implement atomic operations
41###################################################################################################
42
43# module for atomic ops
442601µs250.8ms
# spent 50.7ms (2.36+48.3) within RTP::Webmerge::Merge::BEGIN@44 which was called: # once (2.36ms+48.3ms) by main::BEGIN@31 at line 44
use RTP::IO::AtomicFile;
# spent 50.7ms making 1 call to RTP::Webmerge::Merge::BEGIN@44 # spent 129µs making 1 call to Exporter::import
45
46# use core mdoules for path handling
472194µs2522µs
# spent 292µs (62+230) within RTP::Webmerge::Merge::BEGIN@47 which was called: # once (62µs+230µs) by main::BEGIN@31 at line 47
use File::Basename qw(dirname);
# spent 292µs making 1 call to RTP::Webmerge::Merge::BEGIN@47 # spent 230µs making 1 call to Exporter::import
48
49# override core glob (case insensitive)
502176µs2636µs
# spent 345µs (53+291) within RTP::Webmerge::Merge::BEGIN@50 which was called: # once (53µs+291µs) by main::BEGIN@31 at line 50
use File::Glob qw(:globally :nocase bsd_glob);
# spent 345µs making 1 call to RTP::Webmerge::Merge::BEGIN@50 # spent 291µs making 1 call to File::Glob::import
51
52# import global webroot variable
532194µs21.09ms
# spent 576µs (57+518) within RTP::Webmerge::Merge::BEGIN@53 which was called: # once (57µs+518µs) by main::BEGIN@31 at line 53
use RTP::Webmerge::Path qw($webroot exportURI);
# spent 576µs making 1 call to RTP::Webmerge::Merge::BEGIN@53 # spent 518µs making 1 call to Exporter::import
54
55###################################################################################################
56
57# load flags for file functions
582318µs2374µs
# spent 214µs (55+159) within RTP::Webmerge::Merge::BEGIN@58 which was called: # once (55µs+159µs) by main::BEGIN@31 at line 58
use Fcntl qw(O_RDONLY LOCK_EX);
# spent 214µs making 1 call to RTP::Webmerge::Merge::BEGIN@58 # spent 159µs making 1 call to Exporter::import
59
60###################################################################################################
61
62184.45ms
# spent 4.12ms within RTP::Webmerge::Merge::data which was called 18 times, avg 229µs/call: # 18 times (4.12ms+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 396, avg 229µs/call
sub data { ${$_->{'data'}} };
63
64###################################################################################################
65
662594µs23.99ms
# spent 3.72ms (2.41+1.31) within RTP::Webmerge::Merge::BEGIN@66 which was called: # once (2.41ms+1.31ms) by main::BEGIN@31 at line 66
use RTP::Webmerge::IO::JS;
# spent 3.72ms making 1 call to RTP::Webmerge::Merge::BEGIN@66 # spent 266µs making 1 call to Exporter::import
672589µs27.52ms
# spent 7.20ms (4.89+2.31) within RTP::Webmerge::Merge::BEGIN@67 which was called: # once (4.89ms+2.31ms) by main::BEGIN@31 at line 67
use RTP::Webmerge::IO::CSS;
# spent 7.20ms making 1 call to RTP::Webmerge::Merge::BEGIN@67 # spent 321µs making 1 call to Exporter::import
682615µs212.7ms
# spent 12.6ms (4.61+7.96) within RTP::Webmerge::Merge::BEGIN@68 which was called: # once (4.61ms+7.96ms) by main::BEGIN@31 at line 68
use RTP::Webmerge::Merge::JS;
# spent 12.6ms making 1 call to RTP::Webmerge::Merge::BEGIN@68 # spent 114µs making 1 call to Exporter::import
692550µs210.1ms
# spent 10.0ms (3.99+6.02) within RTP::Webmerge::Merge::BEGIN@69 which was called: # once (3.99ms+6.02ms) by main::BEGIN@31 at line 69
use RTP::Webmerge::Merge::CSS;
# spent 10.0ms making 1 call to RTP::Webmerge::Merge::BEGIN@69 # spent 113µs making 1 call to Exporter::import
702177µs21.02ms
# spent 539µs (63+476) within RTP::Webmerge::Merge::BEGIN@70 which was called: # once (63µs+476µs) by main::BEGIN@31 at line 70
use RTP::Webmerge::Include::JS;
# spent 539µs making 1 call to RTP::Webmerge::Merge::BEGIN@70 # spent 476µs making 1 call to Exporter::import
71210.3ms21.02ms
# spent 541µs (61+480) within RTP::Webmerge::Merge::BEGIN@71 which was called: # once (61µs+480µs) by main::BEGIN@31 at line 71
use RTP::Webmerge::Include::CSS;
# spent 541µs making 1 call to RTP::Webmerge::Merge::BEGIN@71 # spent 480µs making 1 call to Exporter::import
72
73###################################################################################################
74
75# define various handlers for all the different actions
7614µsour (%reader, %writer, %importer, %exporter);
77
78# define joiner for mutliple block parts
79# processors for prepend, input and append
8012µsour (%joiner, %includer, %prefixer, %processor, %suffixer);
81
82###################################################################################################
83
84# write merged data to disk
85# also create checksums etc.
86# ***********************************************************************************************
87sub writer
88
# spent 53.4s (7.48ms+53.4) within RTP::Webmerge::Merge::writer which was called 18 times, avg 2.96s/call: # 18 times (7.48ms+53.4s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 469, avg 2.96s/call
{
89
90 # get input variables
9118167µs my ($type, $config, $output, $data, $collection) = @_;
92
93 # get needed paths from object
9418154µs my $output_path = $output->{'outputpath'};
951881µs my $checksum_path = $output->{'checksumpath'};
96
97 # call processors (will return if nothing is set)
9818418µs1821.0s callProcessor($output->{'process'}, $data, $config, $output);
# spent 21.0s making 18 calls to RTP::Webmerge::callProcessor, avg 1.17s/call
99
100 # assertion if the paths have been defined
1011830µs die "no output path given to write merged file" unless $output_path;
1021823µs die "no crc output path given to write merged file" unless $checksum_path;
103
104 # join all input crcs and list all crcs
10536169µs my $crc_joined = ''; my $crc_listning = '';
106
107 # create md5sum for each item of each kind
10818918µs18250µs foreach my $kind (sort keys %{$collection})
# spent 250µs making 18 calls to RTP::Webmerge::Merge::CORE:sort, avg 14µs/call
109 {
110 # process all items for this kind of input
11190672µs foreach my $item (@{$collection->{$kind}})
112 {
113 # create the md5 sum for this item (only do this once for each path)
114 # $item->{'md5sum'} = md5sum($item->{'data'}) unless ($item->{'md5sum'});
115 # create a relative path from the current checksum file
11618711µs3647.2ms my $rel_path = exportURI($item->{'local_path'}, dirname($checksum_path));
# spent 39.4ms making 18 calls to RTP::Webmerge::Path::exportURI, avg 2.19ms/call # spent 7.79ms making 18 calls to File::Basename::dirname, avg 433µs/call
117 # append checksum for every input file to be appended to our crc file
11818212µs $crc_listning .= join(': ', $rel_path, $item->{'md5sum'}) . "\n";
119 # concatenate md5sums of all items
12018176µs $crc_joined .= $item->{'md5sum'};
121 }
122 }
123
124 # write the real output file ...
12518365µs1826.1s $exporter{$type}->($output_path, $data, $config)
# spent 26.1s making 18 calls to RTP::Webmerge::IO::CSS::exportCSS, avg 1.45s/call
126 or die "could not export <$output_path>: $!";
127
128 # calculate md5sum of joined md5sums
12918541µs363.93ms my $md5_joined = md5sum(\ $crc_joined);
# spent 3.72ms making 18 calls to RTP::Webmerge::Fingerprint::md5sum, avg 206µs/call # spent 210µs making 18 calls to Digest::MD5::DESTROY, avg 12µs/call
130
131 # append the crc of all joined checksums
13218484µs ${$data} .= "\n/* crc: " . $md5_joined . " */\n" if $config->{'crc-comment'};
133
134 # now calculate the output md5sum
13518350µs36515ms my $crc = md5sum($data) . "\n";
# spent 515ms making 18 calls to RTP::Webmerge::Fingerprint::md5sum, avg 28.6ms/call # spent 257µs making 18 calls to Digest::MD5::DESTROY, avg 14µs/call
136
137 # add checksum for joined input file checksums
13818147µs $crc .= "\n" . $md5_joined . "\n";
139
140 # add list of crcs of all sources
1411863µs $crc .= $crc_listning;
142
143 # write the real output file ...
14418422µs185.63s my $rv = $writer{$type}->($output_path, $data, $config)
# spent 5.63s making 18 calls to RTP::Webmerge::IO::CSS::writeCSS, avg 313ms/call
145 or die "could not write <$output_path>: $!";
146
147 # maybe we do not want to write a checksum
14818119µs return $rv unless $config->{'crc-file'};
149
150 # ... and then write the md5 checksum file
15118859µs1850.3ms return $rv && writefile($checksum_path, \ $crc, $config->{'atomic'}, 1)
# spent 50.3ms making 18 calls to RTP::Webmerge::IO::writefile, avg 2.80ms/call
152 or die "could not write <$checksum_path>: $!";
153
154}
155# EO sub writer
156
157###################################################################################################
158
159# collect all files
160# return result hash
161# ***********************************************************************************************
162sub collect
163
# spent 8.05s (1.64ms+8.05) within RTP::Webmerge::Merge::collect which was called 2 times, avg 4.02s/call: # 2 times (1.64ms+8.05s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 339, avg 4.02s/call
{
164
165 # get input variables
166210µs my ($config, $merge, $type) = @_;
167
168 # init data collection
169241µs my %data =
170 (
171 'prefix' => [], # prepend text unaltered
172 'prepend' => [], # prepend but dont minify
173 'input' => [], # main input to be minified
174 'append' => [], # append but dont minify
175 'suffix' => [], # append text unaltered
176 );
177
178 # process all kind of input methods
179291µs217µs foreach my $kind (sort keys %data)
# spent 17µs making 2 calls to RTP::Webmerge::Merge::CORE:sort, avg 9µs/call
180 {
181
182 # make sure that option is an array
1831043µs if(ref $merge->{$kind} eq 'HASH')
184 { $merge->{$kind} = [$merge->{$kind}]; }
185
186 # check if the merged file has been set to load deferred
187 # my $deferred = $merge->{'defer'} && lc $merge->{'defer'} eq 'true';
188
189 # process all items for this merge kind
1901080µs foreach my $item (@{$merge->{$kind} || []})
191 {
192
193 # maybe get input from a script
194 # the script output should be static
195236µs if (ref $item && $item->{'script'} && $item->{'path'})
196 {
197
198 # create absolute path to store the script output
199 my $path = check_path $item->{'path'};
200
201 # create absolute path to execute the script
202 my $script = check_path $item->{'script'};
203
204 # shebang should be given by configuration
205 # otherwise the script must have execute permission
206 my $shebang = $item->{'shebang'} ? $item->{'shebang'} . ' ' : '';
207
208 # open the file to put the script output into
209 # this is needed so we can include the file in dev mode
210 open my $fh_out, ">", $path or die 'could not open generator output - ' . $path;
211
212 # execute the script and open the stdout for us
213 open my $fh_in, "-|", $shebang . $script or die 'could not execute generator script - ' . $script;
214
215 # always read/write in bin mode
216 binmode $fh_in; binmode $fh_out;
217
218 # read script output and write to output file
219 while(defined(my $line = <$fh_in>)) { print $fh_out $line; }
220
221 }
222 # EO if script && path
223
224 # input from path
225 elsif (ref $item && $item->{'path'})
226 {
227
228 # resolve the path via glob (allow filename expansion)
2292208µs41.93ms foreach my $local_path (bsd_glob(check_path $item->{'path'}))
# spent 1.81ms making 2 calls to RTP::Webmerge::Path::check_path, avg 903µs/call # spent 128µs making 2 calls to File::Glob::bsd_glob, avg 64µs/call
230 {
231
232 # create absolute path from the web root
233226µs24.10ms my $web_path = exportURI $local_path;
# spent 4.10ms making 2 calls to RTP::Webmerge::Path::exportURI, avg 2.05ms/call
234
235 # readfile will return a string reference (pointer to the file content)
236240µs26.05s my $data = $reader{$type}->($local_path, $config) or die "could not read <$local_path>: $!";
# spent 6.05s making 2 calls to RTP::Webmerge::IO::CSS::readCSS, avg 3.03s/call
237
238 # get the md5sum of the unaltered data (otherwise crc may not be correct)
2392866µs42.01ms my $md5sum = md5sum(my $org = \ "${$data}") or die "could not get md5sum from data: $!";
# spent 1.98ms making 2 calls to RTP::Webmerge::Fingerprint::md5sum, avg 991µs/call # spent 24µs making 2 calls to Digest::MD5::DESTROY, avg 12µs/call
240
241 # importer can alter the data after the checksum has been taken
242241µs21.98s $importer{$type}->($data, $local_path, $config) or die "could not import <$local_path>: $!";
# spent 1.98s making 2 calls to RTP::Webmerge::IO::CSS::importCSS, avg 992ms/call
243
244 # call processors (will return if nothing is set)
245266µs254µs callProcessor($item->{'process'}, $data, $config, $item);
# spent 54µs making 2 calls to RTP::Webmerge::callProcessor, avg 27µs/call
246
247 # put all informations
248 # on to our data array
249286µs push(@{$data{$kind}}, {
250 'org' => $org,
251 'data' => $data,
252 'item' => $item,
253 'md5sum' => $md5sum,
254 'web_path' => $web_path,
255 'local_path' => $local_path,
256 # 'deferred' => $deferred,
257 });
258
259 }
260 # EO foreach path
261
262 }
263 # EO if path
264
265 # include webmerge id
266 # use other merge as input
267 elsif (ref $item && $item->{'id'})
268 {
269
270 # get the id to include
271 my $id = $item->{'id'};
272
273 # check if referenced id has been merged
274 unless (exists $config->{'merged'}->{$id})
275 { die "id <$id> has not been merged, fatal\n"; }
276
277 # put all informations on to our data array
278 # we just copy the entry from previous merge
279 push(@{$data{$kind}}, $config->{'merged'}->{$id});
280
281 }
282 # EO if id
283
284 elsif (defined $item)
285 {
286
287 # get the md5sum of the unaltered data (otherwise crc may not be correct)
288 my $md5sum = md5sum(\ $item) or die "could not get md5sum for item: $!";
289 push(@{$data{$kind}}, { 'data' => \ $item, 'md5sum' => $md5sum });
290
291 }
292
293 # we have no valid options
294 else
295 {
296
297 # die with error message
298 die "no path or id found for input";
299
300 }
301 # EO if not path
302
303 }
304 # EO foreach item
305
306 }
307 # EO foreach kind
308
309 # result hash
310259µs return \%data;
311
312}
313# EO sub collect
314
315###################################################################################################
316###################################################################################################
317
318###################################################################################################
319# this function does all the joining, minifying and compiling
320# it is very generic and both js and css work as plugins for it
321###################################################################################################
322
323# main merge function
324# ***********************************************************************************************
325my $merger = sub
326
# spent 419s (57.6ms+419) within RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] which was called 2 times, avg 209s/call: # 2 times (57.6ms+419s) by RTP::Webmerge::Merge::merger at line 512, avg 209s/call
{
327
328 # get input variables
329211µs my ($config, $type, $merge) = @_;
330
331 # test if the merge has been disabled
332218µs return if exists $merge->{'disabled'} &&
333 lc $merge->{'disabled'} eq 'true';
334
335 # change directory (restore previous state after this block)
336250µs2369µs my $dir = RTP::Webmerge::Path->chdir($merge->{'chdir'});
# spent 369µs making 2 calls to RTP::Webmerge::Path::chdir, avg 184µs/call
337
338 # collect all data (files) for this merge
339226µs28.05s my $collection = collect($config, $merge, $type);
# spent 8.05s making 2 calls to RTP::Webmerge::Merge::collect, avg 4.02s/call
340
341 # make sure that option is an array
342214µs if(ref $merge->{'output'} eq 'HASH')
343 { $merge->{'output'} = [$merge->{'output'}]; }
344
345 # process all files to be written for this merge
3462131µs foreach my $output (@{$merge->{'output'} || []})
347 {
348
349 # make webroot local to this block and reset if configured
35018107µs local $webroot = check_path $output->{'webroot'} if $output->{'webroot'};
351
352 # create path to store this generated output
35318458µs1819.2ms my $output_path = check_path $output->{'path'};
# spent 19.2ms making 18 calls to RTP::Webmerge::Path::check_path, avg 1.07ms/call
354
355 # create path to store checksum of this output
35618115µs my $checksum_path = join('.', $output_path, 'md5');
357
358 # add these paths to our object
35918154µs $output->{'outputpath'} = $output_path;
3601884µs $output->{'checksumpath'} = $checksum_path;
361
362 # get path to be resolved
36318282µs18115ms my $web_path = exportURI $output_path;
# spent 115ms making 18 calls to RTP::Webmerge::Path::exportURI, avg 6.39ms/call
364
365 # get output target of block
36618130µs my $target = $output->{'target'};
367
368 # local function to collect files to process
369 # will filter out stuff according to given target
370 # usefull for including stuff only in dev or live
371 my $collect = sub
372
# spent 4.10ms within RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384] which was called 180 times, avg 23µs/call: # 18 times (645µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 444, avg 36µs/call # 18 times (631µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 397, avg 35µs/call # 18 times (627µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 442, avg 35µs/call # 18 times (486µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 396, avg 27µs/call # 18 times (388µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 445, avg 22µs/call # 18 times (382µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 394, avg 21µs/call # 18 times (263µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 443, avg 15µs/call # 18 times (235µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 395, avg 13µs/call # 18 times (232µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 398, avg 13µs/call # 18 times (207µs+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 446, avg 12µs/call
{
373 grep
374 {
375 # item has no target - include
37636397µs unless ($_->{'item'}->{'target'}) { 1; }
377 # target is not live, it's a real context
378 elsif ($_->{'item'}->{'target'} ne 'live')
379 { $target eq $_->{'item'}->{'target'}; }
380 # target is live - include if not dev
381 else { $target ne 'dev'; }
382 }
3831804.99ms @{$collection->{$_[0]} || []};
38418534µs };
385
386 # get different joiner for js or css
38718124µs my $joiner = $joiner{$type} || "\n";
388
389 # create a header for joined content (do that for all)
39018439µs my @input = (sprintf($config->{'headtmpl'}, $target));
39118238µs my @prefix = (sprintf($config->{'headtmpl'}, $target));
392
393 # add everything as data/text unaltered (just include data)
39418390µs18382µs push @input, join($joiner, grep { $_ } map data, $collect->('prefix'));
# spent 382µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 21µs/call
39518273µs18235µs push @input, join($joiner, grep { $_ } map data, $collect->('prepend'));
# spent 235µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 13µs/call
396186.48ms364.61ms push @input, join($joiner, grep { $_ } map data, $collect->('input'));
# spent 4.12ms making 18 calls to RTP::Webmerge::Merge::data, avg 229µs/call # spent 486µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 27µs/call
39718636µs18631µs push @input, join($joiner, grep { $_ } map data, $collect->('append'));
# spent 631µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 35µs/call
39818276µs18232µs push @input, join($joiner, grep { $_ } map data, $collect->('suffix'));
# spent 232µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 13µs/call
399
400 # create final joined code
4011815.2ms my $input = join($joiner, grep { $_ } @input);
402
403 # store joined output by id for later use
404 # this id may be referenced by other inputs
405181.12ms $config->{'merged'}->{$merge->{'id'}} =
406 {
407 'data' => \ $input,
408 'web_path' => $web_path,
409 'local_path' => $output_path,
410 # 'path' => $output->{'path'},
411 };
412
413 # delcare additional input
414 # use them for positioning
415 # maybe add a prio to input
4161866µs my (@process, @suffix);
417
418 # should we pretty print the compiled code
4191887µs $config->{'pretty'} = $output->{'pretty'};
420
421 # assertion that we have a output target of block
4221825µs die "no target given for merge block" unless $target;
423
424 # get processor variables for pre and post process
42518192µs my $includer = $includer{$type}->{$target} if $includer{$type};
4261844µs my $prefixer = $prefixer{$type}->{$target} if $prefixer{$type};
42718109µs my $processor = $processor{$type}->{$target} if $processor{$type};
4281830µs my $suffixer = $suffixer{$type}->{$target} if $suffixer{$type};
429
430 # assertion that we have a includer for the given type and target
4311817µs die sprintf "no includer for %s/%s\n", $type, $target unless $includer;
432 # die sprintf "no processor for %s/%s\n", $type, $target unless $processor;
433
434 # is feature enabled
435181.22ms if ($config->{$target})
436 {
437
438 # print a message to the console about the current status
439182.97ms182.15ms printf "creating %s %s <%s>\n", $type, $target, $output->{'path'};
# spent 2.15ms making 18 calls to RTP::Webmerge::Merge::CORE:prtf, avg 119µs/call
440
441 # add everything as data/text unaltered
44218504µs18627µs push @prefix, map data, $collect->('prefix');
# spent 627µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 35µs/call
44318224µs18263µs push @process, map &{$includer}, $collect->('prepend');
# spent 263µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 15µs/call
44418704µs364.70ms push @process, map &{$includer}, $collect->('input');
44518328µs18388µs push @process, map &{$includer}, $collect->('append');
# spent 388µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 22µs/call
44618185µs18207µs push @suffix, map data, $collect->('suffix');
# spent 207µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 12µs/call
447
448 # create code fragment to process
44918287µs my $prefix = join($joiner, grep { $_ } @prefix);
4501882µs my $suffix = join($joiner, grep { $_ } @suffix);
451185.69ms my $process = join($joiner, grep { $_ } @process);
452
453 # call processors (will return immediately if nothing is set)
45418838µs1835.4ms callProcessor($output->{'preprocess'}, \ $prefix, $config, $output);
# spent 35.4ms making 18 calls to RTP::Webmerge::callProcessor, avg 1.96ms/call
45518349µs18326s callProcessor($output->{'preprocess'}, \ $process, $config, $output);
# spent 326s making 18 calls to RTP::Webmerge::callProcessor, avg 18.1s/call
45618356µs1816.8ms callProcessor($output->{'preprocess'}, \ $suffix, $config, $output);
# spent 16.8ms making 18 calls to RTP::Webmerge::callProcessor, avg 932µs/call
457
458 # call target specific processor if available
459182.61ms831.3s $process = $processor->($process, $config) if $processor;
460
461 # call target prefix/suffix processor if available
4621832µs $prefix = $prefixer->(\ $prefix, $merge, $config) if $prefixer;
4631822µs $suffix = $suffixer->(\ $suffix, $merge, $config) if $suffixer;
464
465 # create final joined code (prefix and suffix are unchanged)
4661811.8ms my $code = join($joiner, grep { $_ } ($prefix, $process, $suffix));
467
468 # commit and write out the completely merged block
46918567µs1853.4s my $rv = writer($type, $config, $output, \ $code, $collection);
# spent 53.4s making 18 calls to RTP::Webmerge::Merge::writer, avg 2.96s/call
470
471 # print a message to the console about the current status
472182.36ms181.76ms printf " created %s %s <%s> -> %s\n", $type, $target, $output->{'path'}, $rv ? 'ok' : 'error';
# spent 1.76ms making 18 calls to RTP::Webmerge::Merge::CORE:prtf, avg 98µs/call
473
474 }
475 # EO if target is enabled
476
477 }
478 # EO each output
479
480151µs};
481# EO sub $merge
482
483###################################################################################################
484
485# merge all blocks in config
486# ***********************************************************************************************
487sub merger
488
# spent 419s (242µs+419) within RTP::Webmerge::Merge::merger which was called: # once (242µs+419s) by main::RUNTIME at line 652 of webmerge/scripts/webmerge.pl
{
489
490 # get input variables
49114µs my ($config, $block) = @_;
492
493 # should we commit filesystem changes?
49414µs my $commit = $block->{'commit'} || 0;
495
496 # change directory (restore previous state after this block)
497131µs116µs my $dir = RTP::Webmerge::Path->chdir($block->{'chdir'});
# spent 16µs making 1 call to RTP::Webmerge::Path::chdir
498
499 # commit all changes to the filesystem if configured
500148µs16µs $config->{'atomic'} = {} if $commit =~ m/^\s*(?:bo|be)/i;
# spent 6µs making 1 call to RTP::Webmerge::Merge::CORE:match
501
502 # do not process if disabled attribute is given and set to true
503114µs unless ($block->{'disabled'} && lc $block->{'disabled'} eq 'true')
504 {
505 # process each type (js/css)
506 foreach my $type ('css', 'js')
507 {
508 # process each merge block for type
509224µs foreach my $merge (@{$block->{$type} || []})
510 {
511 # call sub to merge a single block
512291µs4419s $merger->($config, $type, $merge);
# spent 419s making 2 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480], avg 209s/call # spent 46µs making 2 calls to RTP::Webmerge::Path::DESTROY, avg 23µs/call
513 }
514 }
515 }
516
517 # commit all changes to the filesystem if configured
518162µs14µs $config->{'atomic'} = {} if $commit =~ m/^\s*(?:bo|af)/i;
# spent 4µs making 1 call to RTP::Webmerge::Merge::CORE:match
519
520}
521# EO sub merge
522
523###################################################################################################
524###################################################################################################
525122µs1;
 
# spent 9µs within RTP::Webmerge::Merge::CORE:match which was called 2 times, avg 5µs/call: # once (6µs+0s) by RTP::Webmerge::Merge::merger at line 500 # once (4µs+0s) by RTP::Webmerge::Merge::merger at line 518
sub RTP::Webmerge::Merge::CORE:match; # opcode
# spent 3.91ms within RTP::Webmerge::Merge::CORE:prtf which was called 36 times, avg 109µs/call: # 18 times (2.15ms+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 439, avg 119µs/call # 18 times (1.76ms+0s) by RTP::Webmerge::Merge::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm:480] at line 472, avg 98µs/call
sub RTP::Webmerge::Merge::CORE:prtf; # opcode
# spent 268µs within RTP::Webmerge::Merge::CORE:sort which was called 20 times, avg 13µs/call: # 18 times (250µs+0s) by RTP::Webmerge::Merge::writer at line 108, avg 14µs/call # 2 times (17µs+0s) by RTP::Webmerge::Merge::collect at line 179, avg 9µs/call
sub RTP::Webmerge::Merge::CORE:sort; # opcode