| Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Process/CSS/Spritesets.pm |
| Statements | Executed 338 statements in 16.5ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 24 | 1 | 1 | 8.46ms | 326s | RTP::Webmerge::Process::CSS::Spritesets::spritesets |
| 12 | 1 | 1 | 5.35ms | 23.2ms | RTP::Webmerge::Process::CSS::Spritesets::__ANON__[:98] |
| 1 | 1 | 1 | 91µs | 355µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@8 |
| 1 | 1 | 1 | 80µs | 570µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@140 |
| 1 | 1 | 1 | 60µs | 296µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@29 |
| 1 | 1 | 1 | 56µs | 86µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@10 |
| 1 | 1 | 1 | 56µs | 56µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@18.30 |
| 1 | 1 | 1 | 56µs | 239µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@35 |
| 1 | 1 | 1 | 55µs | 231µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@26 |
| 1 | 1 | 1 | 53µs | 139µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@9 |
| 1 | 1 | 1 | 43µs | 43µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@32 |
| 1 | 1 | 1 | 29µs | 29µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@21 |
| 1 | 1 | 1 | 27µs | 27µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@15 |
| 1 | 1 | 1 | 23µs | 23µs | RTP::Webmerge::Process::CSS::Spritesets::BEGIN@18 |
| 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::Process::CSS::Spritesets; | ||||
| 6 | ################################################################################################### | ||||
| 7 | |||||
| 8 | 2 | 162µs | 2 | 619µs | # spent 355µs (91+264) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@8 which was called:
# once (91µs+264µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 8 # spent 355µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@8
# spent 264µs making 1 call to Exporter::import |
| 9 | 2 | 141µs | 2 | 225µs | # spent 139µs (53+86) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@9 which was called:
# once (53µs+86µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 9 # spent 139µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@9
# spent 86µs making 1 call to strict::import |
| 10 | 2 | 213µs | 2 | 116µs | # spent 86µs (56+30) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@10 which was called:
# once (56µs+30µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 10 # spent 86µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@10
# spent 30µs making 1 call to warnings::import |
| 11 | |||||
| 12 | ################################################################################################### | ||||
| 13 | |||||
| 14 | # define our version string | ||||
| 15 | 1 | 149µs | 1 | 27µs | # spent 27µs within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@15 which was called:
# once (27µs+0s) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 15 # spent 27µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@15 |
| 16 | |||||
| 17 | # load exporter and inherit from it | ||||
| 18 | 3 | 416µs | 2 | 79µs | # spent 23µs within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@18 which was called:
# once (23µs+0s) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 18
# spent 56µs within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@18.30 which was called:
# once (56µs+0s) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 18 # spent 56µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@18.30
# spent 23µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@18 |
| 19 | |||||
| 20 | # define our functions to be exported | ||||
| 21 | 1 | 152µs | 1 | 29µs | # spent 29µs within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@21 which was called:
# once (29µs+0s) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 21 # spent 29µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@21 |
| 22 | |||||
| 23 | ################################################################################################### | ||||
| 24 | |||||
| 25 | # load some constants | ||||
| 26 | 2 | 185µs | 2 | 406µs | # spent 231µs (55+175) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@26 which was called:
# once (55µs+175µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 26 # spent 231µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@26
# spent 176µs making 1 call to Exporter::import |
| 27 | |||||
| 28 | # import program runner function | ||||
| 29 | 2 | 176µs | 2 | 533µs | # spent 296µs (60+236) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@29 which was called:
# once (60µs+236µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 29 # spent 296µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@29
# spent 236µs making 1 call to Exporter::import |
| 30 | |||||
| 31 | # load image spriteset class | ||||
| 32 | 2 | 163µs | 1 | 43µs | # spent 43µs within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@32 which was called:
# once (43µs+0s) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 32 # spent 43µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@32 |
| 33 | |||||
| 34 | # import webmerge IO file reader and writer | ||||
| 35 | 2 | 2.27ms | 2 | 422µs | # spent 239µs (56+183) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@35 which was called:
# once (56µs+183µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 35 # spent 239µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@35
# spent 183µs making 1 call to Exporter::import |
| 36 | |||||
| 37 | ################################################################################################### | ||||
| 38 | |||||
| 39 | # process spritesets with additional modules | ||||
| 40 | # try to keep them as standalone as possible | ||||
| 41 | # *************************************************************************************** | ||||
| 42 | sub spritesets | ||||
| 43 | # spent 326s (8.46ms+326) within RTP::Webmerge::Process::CSS::Spritesets::spritesets which was called 24 times, avg 13.6s/call:
# 24 times (8.46ms+326s) by RTP::Webmerge::callProcessor at line 555 of webmerge/scripts/modules/RTP/Webmerge.pm, avg 13.6s/call | ||||
| 44 | |||||
| 45 | # get input variables | ||||
| 46 | 24 | 112µs | my ($data, $config, $output) = @_; | ||
| 47 | |||||
| 48 | # create a new ocbnet spriteset css parser object | ||||
| 49 | 24 | 806µs | 24 | 1.38ms | my $css = OCBNET::Spritesets::CSS::Parser->new($config); # spent 1.38ms making 24 calls to OCBNET::Spritesets::CSS::Parser::new, avg 57µs/call |
| 50 | |||||
| 51 | # declare writer sub | ||||
| 52 | my $writer = sub | ||||
| 53 | # spent 23.2ms (5.35+17.9) within RTP::Webmerge::Process::CSS::Spritesets::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Process/CSS/Spritesets.pm:98] which was called 12 times, avg 1.94ms/call:
# 12 times (5.35ms+17.9ms) by OCBNET::Spritesets::CSS::Parser::write at line 419 of webmerge/scripts/modules/OCBNET/Spritesets/CSS/Parser.pm, avg 1.94ms/call | ||||
| 54 | |||||
| 55 | # get input varibles | ||||
| 56 | 12 | 1.85ms | my ($file, $blob, $written) = @_; | ||
| 57 | |||||
| 58 | # get data for atomic file handling | ||||
| 59 | 12 | 101µs | my $atomic = $config->{'atomic'}; | ||
| 60 | |||||
| 61 | # check if file is known | ||||
| 62 | 12 | 646µs | if ($atomic->{$file}) | ||
| 63 | { | ||||
| 64 | |||||
| 65 | # content has changed between writes | ||||
| 66 | # what should we do in this situation? | ||||
| 67 | 9 | 1.38ms | if (${$atomic->{$file}->[0]} ne $blob) | ||
| 68 | { | ||||
| 69 | # this seems that it can happen with spritesets | ||||
| 70 | # the differences are very subtile, but no idea why | ||||
| 71 | # so far we haven't had an issue with it in a long time | ||||
| 72 | warn "\nERROR: Writing to same file more than once (different content):\n"; | ||||
| 73 | warn substr($file, - 65), "\n"; | ||||
| 74 | die "PLEASE REVIEW YOUR CONFIGURATION!\n"; | ||||
| 75 | } | ||||
| 76 | else | ||||
| 77 | { | ||||
| 78 | # this is really just a warning, nothing more | ||||
| 79 | # remove this once we add a proper implementation | ||||
| 80 | 9 | 966µs | warn "\nWARNING: Writing to the same file more than once (same content):\n"; | ||
| 81 | 9 | 535µs | warn substr($file, - 65), "\n"; | ||
| 82 | } | ||||
| 83 | } | ||||
| 84 | # first write on file | ||||
| 85 | else | ||||
| 86 | { | ||||
| 87 | # write out the file and get the file handle | ||||
| 88 | 3 | 65µs | 3 | 17.9ms | my $handle = writefile($file, \$blob, $atomic, 1); # spent 17.9ms making 3 calls to RTP::Webmerge::IO::writefile, avg 5.97ms/call |
| 89 | # assertion for any write errors | ||||
| 90 | 3 | 4µs | die "error write $file" unless $handle; | ||
| 91 | # create data structure to remember ... | ||||
| 92 | 3 | 34µs | unless (exists $written->{'png'}) | ||
| 93 | { $written->{'png'} = []; } | ||||
| 94 | # ... which files have been written | ||||
| 95 | 3 | 29µs | push(@{$written->{'png'}}, $handle); | ||
| 96 | } | ||||
| 97 | |||||
| 98 | 24 | 702µs | }; | ||
| 99 | # EO sub $writer | ||||
| 100 | |||||
| 101 | # read stylesheet and process spritesets | ||||
| 102 | 24 | 1.03ms | 72 | 133s | $css->read($data)->rehash->load; # spent 87.4s making 24 calls to OCBNET::Spritesets::CSS::Parser::read, avg 3.64s/call
# spent 37.8s making 24 calls to OCBNET::Spritesets::CSS::Parser::load, avg 1.58s/call
# spent 7.45s making 24 calls to OCBNET::Spritesets::CSS::Parser::rehash, avg 310ms/call |
| 103 | 24 | 969µs | 72 | 55.6s | $css->optimize->distribute->finalize; # spent 30.4s making 24 calls to OCBNET::Spritesets::CSS::Parser::distribute, avg 1.26s/call
# spent 23.2s making 24 calls to OCBNET::Spritesets::CSS::Parser::optimize, avg 966ms/call
# spent 2.02s making 24 calls to OCBNET::Spritesets::CSS::Parser::finalize, avg 84.0ms/call |
| 104 | 24 | 400µs | 24 | 116s | my $written = $css->write($writer); # spent 116s making 24 calls to OCBNET::Spritesets::CSS::Parser::write, avg 4.85s/call |
| 105 | 24 | 967µs | 48 | 21.1s | ${$data} = $css->process->render; # spent 19.6s making 24 calls to OCBNET::Spritesets::CSS::Parser::process, avg 815ms/call
# spent 1.55s making 24 calls to OCBNET::Spritesets::CSS::Block::render, avg 64.4ms/call |
| 106 | |||||
| 107 | # print debug messages if wished | ||||
| 108 | 24 | 89µs | $css->debug if $config->{'debug'}; | ||
| 109 | |||||
| 110 | # optimize spriteset images | ||||
| 111 | 24 | 81µs | if ($config->{'optimize'}) | ||
| 112 | { | ||||
| 113 | # call all possible optimizers | ||||
| 114 | foreach my $program (keys %{$written}) | ||||
| 115 | { | ||||
| 116 | # check if this program should run or not | ||||
| 117 | next unless $config->{'optimize-' . $program}; | ||||
| 118 | # close file finehandle now to flush out changes | ||||
| 119 | CORE::close($_) foreach (@{$written->{$program}}); | ||||
| 120 | # fetch all temporary file paths to be optimized by next step | ||||
| 121 | my @files = map { ${*$_}{'io_atomicfile_temp'} } @{$written->{$program}}; | ||||
| 122 | # call the external optimizer program on all temporary files | ||||
| 123 | runProgram($config, $program . 'opt', \@files, $program . ' sprites'); | ||||
| 124 | # re-open the file handles after the optimizers have done their work | ||||
| 125 | sysopen($_, ${*$_}{'io_atomicfile_temp'}, O_RDWR) foreach (@{$written->{$program}}); | ||||
| 126 | } | ||||
| 127 | # EO each program | ||||
| 128 | } | ||||
| 129 | # EO if optimize | ||||
| 130 | |||||
| 131 | # return success | ||||
| 132 | 24 | 1.49ms | return 1; | ||
| 133 | |||||
| 134 | } | ||||
| 135 | # EO sub dejquery | ||||
| 136 | |||||
| 137 | ################################################################################################### | ||||
| 138 | |||||
| 139 | # import registered processors | ||||
| 140 | 2 | 232µs | 2 | 1.06ms | # spent 570µs (80+490) within RTP::Webmerge::Process::CSS::Spritesets::BEGIN@140 which was called:
# once (80µs+490µs) by RTP::Webmerge::Process::CSS::BEGIN@21 at line 140 # spent 570µs making 1 call to RTP::Webmerge::Process::CSS::Spritesets::BEGIN@140
# spent 490µs making 1 call to Exporter::import |
| 141 | |||||
| 142 | # register the processor function | ||||
| 143 | 1 | 7µs | $processors{'spritesets'} = \& spritesets; | ||
| 144 | |||||
| 145 | ################################################################################################### | ||||
| 146 | ################################################################################################### | ||||
| 147 | 1 | 16µs | 1; |