Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Merge.pm |
Statements | Executed 1624 statements in 94.9ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 57.6ms | 419s | __ANON__[:480] | RTP::Webmerge::Merge::
18 | 1 | 1 | 7.48ms | 53.4s | writer | RTP::Webmerge::Merge::
1 | 1 | 1 | 4.89ms | 7.20ms | BEGIN@67 | RTP::Webmerge::Merge::
1 | 1 | 1 | 4.61ms | 12.6ms | BEGIN@68 | RTP::Webmerge::Merge::
18 | 1 | 1 | 4.12ms | 4.12ms | data | RTP::Webmerge::Merge::
180 | 10 | 1 | 4.10ms | 4.10ms | __ANON__[:384] | RTP::Webmerge::Merge::
1 | 1 | 1 | 3.99ms | 10.0ms | BEGIN@69 | RTP::Webmerge::Merge::
36 | 2 | 1 | 3.91ms | 3.91ms | CORE:prtf (opcode) | RTP::Webmerge::Merge::
1 | 1 | 1 | 3.71ms | 5.85ms | BEGIN@37 | RTP::Webmerge::Merge::
1 | 1 | 1 | 2.41ms | 3.72ms | BEGIN@66 | RTP::Webmerge::Merge::
1 | 1 | 1 | 2.36ms | 50.7ms | BEGIN@44 | RTP::Webmerge::Merge::
2 | 1 | 1 | 1.64ms | 8.05s | collect | RTP::Webmerge::Merge::
20 | 2 | 1 | 268µs | 268µs | CORE:sort (opcode) | RTP::Webmerge::Merge::
1 | 1 | 1 | 242µs | 419s | merger | RTP::Webmerge::Merge::
1 | 1 | 1 | 89µs | 365µs | BEGIN@8 | RTP::Webmerge::Merge::
1 | 1 | 1 | 63µs | 539µs | BEGIN@70 | RTP::Webmerge::Merge::
1 | 1 | 1 | 62µs | 292µs | BEGIN@47 | RTP::Webmerge::Merge::
1 | 1 | 1 | 61µs | 541µs | BEGIN@71 | RTP::Webmerge::Merge::
1 | 1 | 1 | 60µs | 60µs | BEGIN@18.13 | RTP::Webmerge::Merge::
1 | 1 | 1 | 57µs | 576µs | BEGIN@53 | RTP::Webmerge::Merge::
1 | 1 | 1 | 56µs | 230µs | BEGIN@35 | RTP::Webmerge::Merge::
1 | 1 | 1 | 55µs | 88µs | BEGIN@10 | RTP::Webmerge::Merge::
1 | 1 | 1 | 55µs | 214µs | BEGIN@58 | RTP::Webmerge::Merge::
1 | 1 | 1 | 54µs | 425µs | BEGIN@32 | RTP::Webmerge::Merge::
1 | 1 | 1 | 54µs | 141µs | BEGIN@9 | RTP::Webmerge::Merge::
1 | 1 | 1 | 53µs | 345µs | BEGIN@50 | RTP::Webmerge::Merge::
1 | 1 | 1 | 53µs | 319µs | BEGIN@36 | RTP::Webmerge::Merge::
1 | 1 | 1 | 37µs | 37µs | BEGIN@24 | RTP::Webmerge::Merge::
1 | 1 | 1 | 26µs | 26µs | BEGIN@21 | RTP::Webmerge::Merge::
1 | 1 | 1 | 24µs | 24µs | BEGIN@15 | RTP::Webmerge::Merge::
1 | 1 | 1 | 22µs | 22µs | BEGIN@18 | RTP::Webmerge::Merge::
2 | 2 | 1 | 9µs | 9µs | CORE:match (opcode) | RTP::Webmerge::Merge::
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::Merge; | ||||
6 | ################################################################################################### | ||||
7 | |||||
8 | 2 | 166µs | 2 | 640µ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 # spent 365µs making 1 call to RTP::Webmerge::Merge::BEGIN@8
# spent 275µs making 1 call to Exporter::import |
9 | 2 | 143µs | 2 | 229µ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 # spent 141µs making 1 call to RTP::Webmerge::Merge::BEGIN@9
# spent 88µs making 1 call to strict::import |
10 | 2 | 197µs | 2 | 120µ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 # 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 | ||||
15 | 1 | 148µs | 1 | 24µs | # spent 24µs within RTP::Webmerge::Merge::BEGIN@15 which was called:
# once (24µs+0s) by main::BEGIN@31 at line 15 # spent 24µs making 1 call to RTP::Webmerge::Merge::BEGIN@15 |
16 | |||||
17 | # load exporter and inherit from it | ||||
18 | 3 | 399µs | 2 | 82µs | 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 | ||||
21 | 1 | 282µs | 1 | 26µs | # spent 26µs within RTP::Webmerge::Merge::BEGIN@21 which was called:
# once (26µs+0s) by main::BEGIN@31 at line 21 # spent 26µs making 1 call to RTP::Webmerge::Merge::BEGIN@21 |
22 | |||||
23 | # define our functions to be exported | ||||
24 | 1 | 42µs | # spent 37µs within RTP::Webmerge::Merge::BEGIN@24 which was called:
# once (37µs+0s) by main::BEGIN@31 at line 27 | ||
25 | merge %reader %writer %importer %exporter | ||||
26 | %joiner %includer %prefixer %processor %suffixer | ||||
27 | 1 | 139µs | 1 | 37µs | ); } # spent 37µs making 1 call to RTP::Webmerge::Merge::BEGIN@24 |
28 | |||||
29 | ################################################################################################### | ||||
30 | |||||
31 | # load local modules | ||||
32 | 2 | 163µs | 2 | 796µ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 # 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 | ||||
35 | 2 | 149µs | 2 | 404µ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 # spent 230µs making 1 call to RTP::Webmerge::Merge::BEGIN@35
# spent 174µs making 1 call to Exporter::import |
36 | 2 | 148µs | 2 | 585µ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 # spent 319µs making 1 call to RTP::Webmerge::Merge::BEGIN@36
# spent 266µs making 1 call to Exporter::import |
37 | 2 | 689µs | 2 | 6.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 # 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 | ||||
44 | 2 | 601µs | 2 | 50.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 # 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 | ||||
47 | 2 | 194µs | 2 | 522µ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 # 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) | ||||
50 | 2 | 176µs | 2 | 636µ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 # 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 | ||||
53 | 2 | 194µs | 2 | 1.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 # 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 | ||||
58 | 2 | 318µs | 2 | 374µ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 # spent 214µs making 1 call to RTP::Webmerge::Merge::BEGIN@58
# spent 159µs making 1 call to Exporter::import |
59 | |||||
60 | ################################################################################################### | ||||
61 | |||||
62 | 18 | 4.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 | ||
63 | |||||
64 | ################################################################################################### | ||||
65 | |||||
66 | 2 | 594µs | 2 | 3.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 # spent 3.72ms making 1 call to RTP::Webmerge::Merge::BEGIN@66
# spent 266µs making 1 call to Exporter::import |
67 | 2 | 589µs | 2 | 7.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 # spent 7.20ms making 1 call to RTP::Webmerge::Merge::BEGIN@67
# spent 321µs making 1 call to Exporter::import |
68 | 2 | 615µs | 2 | 12.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 # spent 12.6ms making 1 call to RTP::Webmerge::Merge::BEGIN@68
# spent 114µs making 1 call to Exporter::import |
69 | 2 | 550µs | 2 | 10.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 # spent 10.0ms making 1 call to RTP::Webmerge::Merge::BEGIN@69
# spent 113µs making 1 call to Exporter::import |
70 | 2 | 177µs | 2 | 1.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 # spent 539µs making 1 call to RTP::Webmerge::Merge::BEGIN@70
# spent 476µs making 1 call to Exporter::import |
71 | 2 | 10.3ms | 2 | 1.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 # 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 | ||||
76 | 1 | 4µs | our (%reader, %writer, %importer, %exporter); | ||
77 | |||||
78 | # define joiner for mutliple block parts | ||||
79 | # processors for prepend, input and append | ||||
80 | 1 | 2µs | our (%joiner, %includer, %prefixer, %processor, %suffixer); | ||
81 | |||||
82 | ################################################################################################### | ||||
83 | |||||
84 | # write merged data to disk | ||||
85 | # also create checksums etc. | ||||
86 | # *********************************************************************************************** | ||||
87 | sub 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 | ||||
91 | 18 | 167µs | my ($type, $config, $output, $data, $collection) = @_; | ||
92 | |||||
93 | # get needed paths from object | ||||
94 | 18 | 154µs | my $output_path = $output->{'outputpath'}; | ||
95 | 18 | 81µs | my $checksum_path = $output->{'checksumpath'}; | ||
96 | |||||
97 | # call processors (will return if nothing is set) | ||||
98 | 18 | 418µs | 18 | 21.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 | ||||
101 | 18 | 30µs | die "no output path given to write merged file" unless $output_path; | ||
102 | 18 | 23µs | die "no crc output path given to write merged file" unless $checksum_path; | ||
103 | |||||
104 | # join all input crcs and list all crcs | ||||
105 | 36 | 169µs | my $crc_joined = ''; my $crc_listning = ''; | ||
106 | |||||
107 | # create md5sum for each item of each kind | ||||
108 | 18 | 918µs | 18 | 250µ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 | ||||
111 | 90 | 672µ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 | ||||
116 | 18 | 711µs | 36 | 47.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 | ||||
118 | 18 | 212µs | $crc_listning .= join(': ', $rel_path, $item->{'md5sum'}) . "\n"; | ||
119 | # concatenate md5sums of all items | ||||
120 | 18 | 176µs | $crc_joined .= $item->{'md5sum'}; | ||
121 | } | ||||
122 | } | ||||
123 | |||||
124 | # write the real output file ... | ||||
125 | 18 | 365µs | 18 | 26.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 | ||||
129 | 18 | 541µs | 36 | 3.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 | ||||
132 | 18 | 484µs | ${$data} .= "\n/* crc: " . $md5_joined . " */\n" if $config->{'crc-comment'}; | ||
133 | |||||
134 | # now calculate the output md5sum | ||||
135 | 18 | 350µs | 36 | 515ms | 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 | ||||
138 | 18 | 147µs | $crc .= "\n" . $md5_joined . "\n"; | ||
139 | |||||
140 | # add list of crcs of all sources | ||||
141 | 18 | 63µs | $crc .= $crc_listning; | ||
142 | |||||
143 | # write the real output file ... | ||||
144 | 18 | 422µs | 18 | 5.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 | ||||
148 | 18 | 119µs | return $rv unless $config->{'crc-file'}; | ||
149 | |||||
150 | # ... and then write the md5 checksum file | ||||
151 | 18 | 859µs | 18 | 50.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 | # *********************************************************************************************** | ||||
162 | sub 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 | ||||
166 | 2 | 10µs | my ($config, $merge, $type) = @_; | ||
167 | |||||
168 | # init data collection | ||||
169 | 2 | 41µ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 | ||||
179 | 2 | 91µs | 2 | 17µ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 | ||||
183 | 10 | 43µ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 | ||||
190 | 10 | 80µs | foreach my $item (@{$merge->{$kind} || []}) | ||
191 | { | ||||
192 | |||||
193 | # maybe get input from a script | ||||
194 | # the script output should be static | ||||
195 | 2 | 36µ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) | ||||
229 | 2 | 208µs | 4 | 1.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 | ||||
233 | 2 | 26µs | 2 | 4.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) | ||||
236 | 2 | 40µs | 2 | 6.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) | ||||
239 | 2 | 866µs | 4 | 2.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 | ||||
242 | 2 | 41µs | 2 | 1.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) | ||||
245 | 2 | 66µs | 2 | 54µ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 | ||||
249 | 2 | 86µ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 | ||||
310 | 2 | 59µ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 | # *********************************************************************************************** | ||||
325 | my $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 | ||||
329 | 2 | 11µs | my ($config, $type, $merge) = @_; | ||
330 | |||||
331 | # test if the merge has been disabled | ||||
332 | 2 | 18µs | return if exists $merge->{'disabled'} && | ||
333 | lc $merge->{'disabled'} eq 'true'; | ||||
334 | |||||
335 | # change directory (restore previous state after this block) | ||||
336 | 2 | 50µs | 2 | 369µ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 | ||||
339 | 2 | 26µs | 2 | 8.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 | ||||
342 | 2 | 14µs | if(ref $merge->{'output'} eq 'HASH') | ||
343 | { $merge->{'output'} = [$merge->{'output'}]; } | ||||
344 | |||||
345 | # process all files to be written for this merge | ||||
346 | 2 | 131µs | foreach my $output (@{$merge->{'output'} || []}) | ||
347 | { | ||||
348 | |||||
349 | # make webroot local to this block and reset if configured | ||||
350 | 18 | 107µs | local $webroot = check_path $output->{'webroot'} if $output->{'webroot'}; | ||
351 | |||||
352 | # create path to store this generated output | ||||
353 | 18 | 458µs | 18 | 19.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 | ||||
356 | 18 | 115µs | my $checksum_path = join('.', $output_path, 'md5'); | ||
357 | |||||
358 | # add these paths to our object | ||||
359 | 18 | 154µs | $output->{'outputpath'} = $output_path; | ||
360 | 18 | 84µs | $output->{'checksumpath'} = $checksum_path; | ||
361 | |||||
362 | # get path to be resolved | ||||
363 | 18 | 282µs | 18 | 115ms | 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 | ||||
366 | 18 | 130µ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 | ||||
376 | 36 | 397µ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 | } | ||||
383 | 180 | 4.99ms | @{$collection->{$_[0]} || []}; | ||
384 | 18 | 534µs | }; | ||
385 | |||||
386 | # get different joiner for js or css | ||||
387 | 18 | 124µs | my $joiner = $joiner{$type} || "\n"; | ||
388 | |||||
389 | # create a header for joined content (do that for all) | ||||
390 | 18 | 439µs | my @input = (sprintf($config->{'headtmpl'}, $target)); | ||
391 | 18 | 238µs | my @prefix = (sprintf($config->{'headtmpl'}, $target)); | ||
392 | |||||
393 | # add everything as data/text unaltered (just include data) | ||||
394 | 18 | 390µs | 18 | 382µ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 |
395 | 18 | 273µs | 18 | 235µ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 |
396 | 18 | 6.48ms | 36 | 4.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 |
397 | 18 | 636µs | 18 | 631µ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 |
398 | 18 | 276µs | 18 | 232µ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 | ||||
401 | 18 | 15.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 | ||||
405 | 18 | 1.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 | ||||
416 | 18 | 66µs | my (@process, @suffix); | ||
417 | |||||
418 | # should we pretty print the compiled code | ||||
419 | 18 | 87µs | $config->{'pretty'} = $output->{'pretty'}; | ||
420 | |||||
421 | # assertion that we have a output target of block | ||||
422 | 18 | 25µs | die "no target given for merge block" unless $target; | ||
423 | |||||
424 | # get processor variables for pre and post process | ||||
425 | 18 | 192µs | my $includer = $includer{$type}->{$target} if $includer{$type}; | ||
426 | 18 | 44µs | my $prefixer = $prefixer{$type}->{$target} if $prefixer{$type}; | ||
427 | 18 | 109µs | my $processor = $processor{$type}->{$target} if $processor{$type}; | ||
428 | 18 | 30µs | my $suffixer = $suffixer{$type}->{$target} if $suffixer{$type}; | ||
429 | |||||
430 | # assertion that we have a includer for the given type and target | ||||
431 | 18 | 17µ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 | ||||
435 | 18 | 1.22ms | if ($config->{$target}) | ||
436 | { | ||||
437 | |||||
438 | # print a message to the console about the current status | ||||
439 | 18 | 2.97ms | 18 | 2.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 | ||||
442 | 18 | 504µs | 18 | 627µ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 |
443 | 18 | 224µs | 18 | 263µ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 |
444 | 18 | 704µs | 36 | 4.70ms | push @process, map &{$includer}, $collect->('input'); # spent 1.92ms making 8 calls to RTP::Webmerge::Merge::CSS::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge/CSS.pm:65], avg 240µs/call
# spent 1.85ms making 8 calls to RTP::Webmerge::Merge::CSS::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge/CSS.pm:63], avg 231µs/call
# spent 645µs making 18 calls to RTP::Webmerge::Merge::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge.pm:384], avg 36µs/call
# spent 287µs making 2 calls to RTP::Webmerge::Merge::CSS::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge/CSS.pm:62], avg 143µs/call |
445 | 18 | 328µs | 18 | 388µ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 |
446 | 18 | 185µs | 18 | 207µ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 | ||||
449 | 18 | 287µs | my $prefix = join($joiner, grep { $_ } @prefix); | ||
450 | 18 | 82µs | my $suffix = join($joiner, grep { $_ } @suffix); | ||
451 | 18 | 5.69ms | my $process = join($joiner, grep { $_ } @process); | ||
452 | |||||
453 | # call processors (will return immediately if nothing is set) | ||||
454 | 18 | 838µs | 18 | 35.4ms | callProcessor($output->{'preprocess'}, \ $prefix, $config, $output); # spent 35.4ms making 18 calls to RTP::Webmerge::callProcessor, avg 1.96ms/call |
455 | 18 | 349µs | 18 | 326s | callProcessor($output->{'preprocess'}, \ $process, $config, $output); # spent 326s making 18 calls to RTP::Webmerge::callProcessor, avg 18.1s/call |
456 | 18 | 356µs | 18 | 16.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 | ||||
459 | 18 | 2.61ms | 8 | 31.3s | $process = $processor->($process, $config) if $processor; # spent 31.3s making 8 calls to RTP::Webmerge::Merge::CSS::__ANON__[webmerge/scripts/modules/RTP/Webmerge/Merge/CSS.pm:80], avg 3.91s/call |
460 | |||||
461 | # call target prefix/suffix processor if available | ||||
462 | 18 | 32µs | $prefix = $prefixer->(\ $prefix, $merge, $config) if $prefixer; | ||
463 | 18 | 22µs | $suffix = $suffixer->(\ $suffix, $merge, $config) if $suffixer; | ||
464 | |||||
465 | # create final joined code (prefix and suffix are unchanged) | ||||
466 | 18 | 11.8ms | my $code = join($joiner, grep { $_ } ($prefix, $process, $suffix)); | ||
467 | |||||
468 | # commit and write out the completely merged block | ||||
469 | 18 | 567µs | 18 | 53.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 | ||||
472 | 18 | 2.36ms | 18 | 1.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 | |||||
480 | 1 | 51µs | }; | ||
481 | # EO sub $merge | ||||
482 | |||||
483 | ################################################################################################### | ||||
484 | |||||
485 | # merge all blocks in config | ||||
486 | # *********************************************************************************************** | ||||
487 | sub 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 | ||||
491 | 1 | 4µs | my ($config, $block) = @_; | ||
492 | |||||
493 | # should we commit filesystem changes? | ||||
494 | 1 | 4µs | my $commit = $block->{'commit'} || 0; | ||
495 | |||||
496 | # change directory (restore previous state after this block) | ||||
497 | 1 | 31µs | 1 | 16µ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 | ||||
500 | 1 | 48µs | 1 | 6µ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 | ||||
503 | 1 | 14µ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 | ||||
509 | 2 | 24µs | foreach my $merge (@{$block->{$type} || []}) | ||
510 | { | ||||
511 | # call sub to merge a single block | ||||
512 | 2 | 91µs | 4 | 419s | $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 | ||||
518 | 1 | 62µs | 1 | 4µ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 | ################################################################################################### | ||||
525 | 1 | 22µs | 1; | ||
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:sort; # opcode |