← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:14 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Plugins/SmiliesPlugin.pm
StatementsExecuted 4275 statements in 8.81ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5114.59ms6.07msFoswiki::Plugins::SmiliesPlugin::::preRenderingHandlerFoswiki::Plugins::SmiliesPlugin::preRenderingHandler
1111.77ms14.9msFoswiki::Plugins::SmiliesPlugin::::_loadSmiliesFoswiki::Plugins::SmiliesPlugin::_loadSmilies
896111.44ms1.44msFoswiki::Plugins::SmiliesPlugin::::_renderSmilyFoswiki::Plugins::SmiliesPlugin::_renderSmily
11121µs15.0msFoswiki::Plugins::SmiliesPlugin::::initPluginFoswiki::Plugins::SmiliesPlugin::initPlugin
11114µs27µsFoswiki::Plugins::SmiliesPlugin::::BEGIN@7Foswiki::Plugins::SmiliesPlugin::BEGIN@7
51113µs36µsFoswiki::Plugins::SmiliesPlugin::::_addToZoneFoswiki::Plugins::SmiliesPlugin::_addToZone
1119µs13µsFoswiki::Plugins::SmiliesPlugin::::BEGIN@8Foswiki::Plugins::SmiliesPlugin::BEGIN@8
1114µs4µsFoswiki::Plugins::SmiliesPlugin::::BEGIN@10Foswiki::Plugins::SmiliesPlugin::BEGIN@10
0000s0sFoswiki::Plugins::SmiliesPlugin::::_formatSmilyFoswiki::Plugins::SmiliesPlugin::_formatSmily
0000s0sFoswiki::Plugins::SmiliesPlugin::::_renderSmiliesFoswiki::Plugins::SmiliesPlugin::_renderSmilies
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2#
3# This plugin replaces smilies with small smilies bitmaps
4
5package Foswiki::Plugins::SmiliesPlugin;
6
7228µs241µs
# spent 27µs (14+13) within Foswiki::Plugins::SmiliesPlugin::BEGIN@7 which was called: # once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.35 at line 7
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::SmiliesPlugin::BEGIN@7 # spent 13µs making 1 call to strict::import
8228µs217µs
# spent 13µs (9+4) within Foswiki::Plugins::SmiliesPlugin::BEGIN@8 which was called: # once (9µs+4µs) by Foswiki::Plugin::BEGIN@2.35 at line 8
use warnings;
# spent 13µs making 1 call to Foswiki::Plugins::SmiliesPlugin::BEGIN@8 # spent 4µs making 1 call to warnings::import
9
102939µs14µs
# spent 4µs within Foswiki::Plugins::SmiliesPlugin::BEGIN@10 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.35 at line 10
use Foswiki::Func ();
# spent 4µs making 1 call to Foswiki::Plugins::SmiliesPlugin::BEGIN@10
11
1211µsour %cache = ();
1310sour $current;
14
151500nsour $VERSION = '2.02';
161200nsour $RELEASE = '25 Jun 2015';
171100nsour $NO_PREFS_IN_TOPIC = 1;
181200nsour $SHORTDESCRIPTION = 'Render smilies like :-) as icons';
191100nsour $doneHeader = 0;
20
21
# spent 15.0ms (21µs+14.9) within Foswiki::Plugins::SmiliesPlugin::initPlugin which was called: # once (21µs+14.9ms) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm
sub initPlugin {
22
2312µs115µs Foswiki::Func::registerTagHandler( 'SMILIES', \&_renderSmilies );
# spent 15µs making 1 call to Foswiki::Func::registerTagHandler
24
2512µs my $web = $Foswiki::cfg{SystemWebName};
2612µs123µs my $topic = Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_TOPIC')
# spent 23µs making 1 call to Foswiki::Func::getPreferencesValue
27 || "SmiliesPlugin";
28
291700ns $doneHeader = 0;
30
3113µs114.9ms _loadSmilies( $web, $topic );
# spent 14.9ms making 1 call to Foswiki::Plugins::SmiliesPlugin::_loadSmilies
32
3314µs return 1;
34}
35
36
# spent 6.07ms (4.59+1.48) within Foswiki::Plugins::SmiliesPlugin::preRenderingHandler which was called 5 times, avg 1.21ms/call: # 5 times (4.59ms+1.48ms) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 1.21ms/call
sub preRenderingHandler {
37
389013.60ms9011.48ms if ( $_[0] =~
# spent 1.44ms making 896 calls to Foswiki::Plugins::SmiliesPlugin::_renderSmily, avg 2µs/call # spent 36µs making 5 calls to Foswiki::Plugins::SmiliesPlugin::_addToZone, avg 7µs/call
39 s/(\s|^)$cache{$current}{pattern}(?=\s|$)/_renderSmily($1,$2)/ge )
40 {
41 _addToZone();
42 }
43}
44
45
# spent 36µs (13+23) within Foswiki::Plugins::SmiliesPlugin::_addToZone which was called 5 times, avg 7µs/call: # 5 times (13µs+23µs) by Foswiki::Plugins::SmiliesPlugin::preRenderingHandler at line 38, avg 7µs/call
sub _addToZone {
46512µs return if $doneHeader;
471400ns $doneHeader = 1;
4815µs123µs Foswiki::Func::addToZone( "head", "SMILIESPLUGIN",
# spent 23µs making 1 call to Foswiki::Func::addToZone
49"<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/SmiliesPlugin/smilies.css' type='text/css' media='all' />"
50 );
51}
52
53
# spent 14.9ms (1.77+13.1) within Foswiki::Plugins::SmiliesPlugin::_loadSmilies which was called: # once (1.77ms+13.1ms) by Foswiki::Plugins::SmiliesPlugin::initPlugin at line 31
sub _loadSmilies {
5411µs my ( $web, $topic, $force ) = @_;
55
5612µs110µs ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic );
# spent 10µs making 1 call to Foswiki::Func::normalizeWebTopicName
57
5812µs $current = "$web.$topic";
591800ns return if !$force && defined $cache{$current};
60
6111µs $cache{$current} = ();
62
6313µs120µs $cache{$current}{format} =
# spent 20µs making 1 call to Foswiki::Func::getPreferencesValue
64 Foswiki::Func::getPreferencesValue('SMILIESPLUGIN_FORMAT')
65 || '<img class=\'smily\' src=\'$url\' alt=\'$tooltip\' title=\'$tooltip\' />';
66
6711µs $cache{$current}{pattern} = "(";
681300ns my $state = 0;
6912µs113.1ms my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
# spent 13.1ms making 1 call to Foswiki::Func::readTopic
70174µs foreach my $line ( split( /\n/, $text || '' ) ) {
71
72 # | smily | image | description |
73104521µs if ( $line =~ m/^\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*$/ ) {
74
759144µs my $alternatives = $1;
769124µs my $image = $2;
779122µs my $desc = $3;
78
799137µs if ( $alternatives =~ m/^\*/ ) {
801400ns $state = 1;
811500ns next;
82 }
83
849032µs $image =~ s/%ATTACHURL(PATH)?%//g;
859020µs $desc =~ s/"//g;
86
87909µs next unless $alternatives && $image;
88
8990130µs foreach my $key ( split( /\s+/, $alternatives ) ) {
90140241µs $key =~ s/<nop>|\&nbsp;//g;
91140131µs $cache{$current}{pattern} .= "\Q$key\E|";
92140147µs $cache{$current}{image}{$key} = $image;
9314092µs $cache{$current}{desc}{$key} = $desc;
94140154µs $cache{$current}{alts}{$key} = $alternatives;
95 }
96 }
97 else {
98139µs last if $state == 1;
99 }
100 }
101
102 #$cache{$current}{pattern} =~ s/\|$//;
10311µs $cache{$current}{pattern} .= ")";
104160µs121µs $cache{$current}{pubUrl} = Foswiki::Func::getPubUrlPath() . "/$web/$topic";
# spent 21µs making 1 call to Foswiki::Func::getPubUrlPath
105
106}
107
108
# spent 1.44ms within Foswiki::Plugins::SmiliesPlugin::_renderSmily which was called 896 times, avg 2µs/call: # 896 times (1.44ms+0s) by Foswiki::Plugins::SmiliesPlugin::preRenderingHandler at line 38, avg 2µs/call
sub _renderSmily {
109896625µs my ( $pre, $smily ) = @_;
110
1118961.79ms return $pre unless $smily;
112 return $pre . _formatSmily( $cache{$current}{format}, $smily );
113}
114
115sub _formatSmily {
116 my ( $format, $smily ) = @_;
117
118 my $text = $format;
119
120 $text =~ s/\$key/<nop>$smily/g;
121 $text =~ s/\$alternatives/$cache{$current}{alts}{$smily}/g;
122 $text =~ s/\$emoticon/$smily/g;
123 $text =~ s/\$tooltip/$cache{$current}{desc}{$smily}/g;
124 $text =~
125 s/\$url/$cache{$current}{pubUrl}\/$cache{$current}{image}{$smily}/g;
126
127 return $text;
128}
129
130sub _renderSmilies {
131 my ( $session, $params ) = @_;
132
133 my $smily = $params->{_DEFAULT};
134 my $header = $params->{header};
135 my $format = $params->{format};
136 my $footer = $params->{footer} || '';
137 my $separator = $params->{separator} || '$n';
138
139 $header =
140'| *%MAKETEXT{"Notation"}%* | *%MAKETEXT{"Image"}%* | *%MAKETEXT{"Description"}%* |$n'
141 unless defined $header;
142
143 $format = '| $alternatives | $emoticon | $tooltip |' unless defined $format;
144
145 my @smilies = ();
146 if ( defined $smily ) {
147 push @smilies, $smily;
148 }
149 else {
150 @smilies =
151 sort {
152 lc( $cache{$current}{image}{$a} ) cmp
153 lc( $cache{$current}{image}{$b} )
154 }
155 keys %{ $cache{$current}{alts} };
156 }
157
158 my @result = ();
159 my %seen = ();
160 foreach my $smily (@smilies) {
161 next if $seen{ $cache{$current}{alts}{$smily} };
162 push @result, _formatSmily( $format, $smily );
163 $seen{ $cache{$current}{alts}{$smily} } = 1;
164 }
165
166 return '' unless @result;
167
168 _addToZone();
169
170 return Foswiki::Func::decodeFormatTokens(
171 $header . join( $separator, @result ) . $footer );
172}
173
17414µs1;
175__END__