← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:27:14 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TablePlugin.pm
StatementsExecuted 5791 statements in 33.8ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11311120.4ms32.8msFoswiki::Plugins::TablePlugin::::afterCommonTagsHandlerFoswiki::Plugins::TablePlugin::afterCommonTagsHandler
1155827.30ms7.30msFoswiki::Plugins::TablePlugin::::debugFoswiki::Plugins::TablePlugin::debug
1131115.25ms5.25msFoswiki::Plugins::TablePlugin::::_writeStyleToHeadFoswiki::Plugins::TablePlugin::_writeStyleToHead
511878µs49.3msFoswiki::Plugins::TablePlugin::::preRenderingHandlerFoswiki::Plugins::TablePlugin::preRenderingHandler
111116µs195µsFoswiki::Plugins::TablePlugin::::initPluginFoswiki::Plugins::TablePlugin::initPlugin
111114µs3.74msFoswiki::Plugins::TablePlugin::::_readPluginSettingsFoswiki::Plugins::TablePlugin::_readPluginSettings
61141µs41µsFoswiki::Plugins::TablePlugin::::debugDataFoswiki::Plugins::TablePlugin::debugData
51135µs35µsFoswiki::Plugins::TablePlugin::::CORE:matchFoswiki::Plugins::TablePlugin::CORE:match (opcode)
11124µs32µsFoswiki::Plugins::TablePlugin::::BEGIN@8Foswiki::Plugins::TablePlugin::BEGIN@8
11117µs35µsFoswiki::Plugins::TablePlugin::::BEGIN@9Foswiki::Plugins::TablePlugin::BEGIN@9
0000s0sFoswiki::Plugins::TablePlugin::::addHeadStylesFoswiki::Plugins::TablePlugin::addHeadStyles
0000s0sFoswiki::Plugins::TablePlugin::::initialiseWhenRenderFoswiki::Plugins::TablePlugin::initialiseWhenRender
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# Allow sorting of tables, plus setting of background colour for
4# headings and data cells. See %SYSTEMWEB%.TablePlugin for details of use
5
6package Foswiki::Plugins::TablePlugin;
7
8246µs239µs
# spent 32µs (24+7) within Foswiki::Plugins::TablePlugin::BEGIN@8 which was called: # once (24µs+7µs) by Foswiki::Plugin::BEGIN@2.17 at line 8
use strict;
# spent 32µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@8 # spent 7µs making 1 call to strict::import
921.61ms254µs
# spent 35µs (17+19) within Foswiki::Plugins::TablePlugin::BEGIN@9 which was called: # once (17µs+19µs) by Foswiki::Plugin::BEGIN@2.17 at line 9
use warnings;
# spent 35µs making 1 call to Foswiki::Plugins::TablePlugin::BEGIN@9 # spent 19µs making 1 call to warnings::import
10
1112µsour $VERSION = '$Rev$';
1211µsour $RELEASE = '1.135';
1312µsour $SHORTDESCRIPTION =
14 'Control attributes of tables and sorting of table columns';
1511µsour $NO_PREFS_IN_TOPIC = 1;
1611µsour %pluginAttributes;
17
1811µsour $DEBUG_FROM_UNIT_TEST = 0;
1911µsour $topic;
201800nsour $web;
211800nsour $user;
221800nsour $installWeb;
231700nsour $initialised;
2412µsmy $DEFAULT_TABLE_SETTINGS =
25'tableborder="1" valign="top" headercolor="#000000" headerbg="#d6d3cf" headerbgsorted="#c4c1ba" databg="#ffffff,#edf4f9" databgsorted="#f1f7fc,#ddebf6" tablerules="rows" headerrules="cols"';
2612µsmy $styles = {}; # hash to keep track of web->topic
2711µsour $writtenToHead = 0;
28
29
# spent 195µs (116+79) within Foswiki::Plugins::TablePlugin::initPlugin which was called: # once (116µs+79µs) by Foswiki::Plugin::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm:235] at line 228 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm
sub initPlugin {
3019µs ( $topic, $web, $user, $installWeb ) = @_;
31
32116µs119µs debug( 'TablePlugin', "initPlugin:$web.$topic" );
# spent 19µs making 1 call to Foswiki::Plugins::TablePlugin::debug
33
34 # check for Plugins.pm versions
3515µs if ( $Foswiki::Plugins::VERSION < 1.026 ) {
36 Foswiki::Func::writeWarning(
37 'Version mismatch between TablePlugin and Plugins.pm');
38 return 0;
39 }
40
41110µs149µs my $cgi = Foswiki::Func::getCgiQuery();
# spent 49µs making 1 call to Foswiki::Func::getCgiQuery
4212µs return 0 unless $cgi;
43
4412µs $initialised = 0;
4512µs $writtenToHead = 0;
4617µs %pluginAttributes = ();
47
4818µs110µs debug( 'TablePlugin', "inited" );
# spent 10µs making 1 call to Foswiki::Plugins::TablePlugin::debug
49
50120µs return 1;
51}
52
53
# spent 49.3ms (878µs+48.4) within Foswiki::Plugins::TablePlugin::preRenderingHandler which was called 5 times, avg 9.86ms/call: # 5 times (878µs+48.4ms) by Foswiki::Plugin::invoke at line 287 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm, avg 9.86ms/call
sub preRenderingHandler {
54 ### my ( $text, $removed ) = @_;
55527µs537µs debug( 'TablePlugin', 'preRenderingHandler' );
# spent 37µs making 5 calls to Foswiki::Plugins::TablePlugin::debug, avg 7µs/call
56568µs5526µs my $sort = Foswiki::Func::getPreferencesValue('TABLEPLUGIN_SORT')
# spent 526µs making 5 calls to Foswiki::Func::getPreferencesValue, avg 105µs/call
57 || 'all';
58 return
59573µs535µs unless ( $sort && $sort =~ /^(all|attachments)$/ )
# spent 35µs making 5 calls to Foswiki::Plugins::TablePlugin::CORE:match, avg 7µs/call
60 || $_[0] =~ /%TABLE{.*?}%/;
61
62535µs13.74ms _readPluginSettings() if !%pluginAttributes;
63
64 # on-demand inclusion
655559µs eval "use Foswiki::Plugins::TablePlugin::Core ()";
# spent 294µs executing statements in 5 string evals (merged)
# includes 14.6ms spent executing 5 calls to 5 subs defined therein.
6658µs die $@ if $@;
67590µs526.7ms Foswiki::Plugins::TablePlugin::Core::handler(@_);
# spent 26.7ms making 5 calls to Foswiki::Plugins::TablePlugin::Core::handler, avg 5.33ms/call
68}
69
70=begin TML
71---++ StaticMethod initialiseWhenRender() -> 1
72
73Official API call for TablePlugin. Other plugins can reinitialise the plugin
74which will reset all table counters etc next time the preRenderingHandler
75is run. The preRenderingHandler is called again when a plugin uses the
76Foswiki::Func::renderText method.
77A plugin like !CompareRevisionsAddOn uses initialiseWhenRender between the
78rendering of two revisions of the same topic to avoid table numbers to
79continue counting up when rendering the topic the second time.
80
81Example of use in a plugin taking care to check for TablePlugin being
82installed and being of a version that contains this method.
83Otherwise using a "mother of hacks" to get to the same result.
84
85 if ( defined &Foswiki::Plugins::TablePlugin::initPlugin ) {
86 if ( defined &Foswiki::Plugins::TablePlugin::initialiseWhenRender ) {
87 Foswiki::Plugins::TablePlugin::initialiseWhenRender();
88 }
89 else {
90 # If TablePlugin does not have the reinitialise API
91 # we use try a shameless hack instead
92 if ( defined $Foswiki::Plugins::TablePlugin::initialised ) {
93 $Foswiki::Plugins::TablePlugin::initialised = 0;
94 }
95 }
96 }
97
98=cut
99
100sub initialiseWhenRender {
101
102 $initialised = 0;
103
104 return 1;
105}
106
107=pod
108
109Read in plugin settings from TABLEPLUGIN_TABLEATTRIBUTES
110TABLEATTRIBUTES are no longer supported (NO_PREFS_IN_TOPIC).
111If no settings are found, use the default settings from configure.
112And if these cannot be read, use the default values defined here in this plugin.
113
114Settings are applied by the principle of 'filling in the gaps'
115=cut
116
117
# spent 3.74ms (114µs+3.62) within Foswiki::Plugins::TablePlugin::_readPluginSettings which was called: # once (114µs+3.62ms) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 62
sub _readPluginSettings {
11815µs16µs debug( 'TablePlugin', '_readPluginSettings' );
# spent 6µs making 1 call to Foswiki::Plugins::TablePlugin::debug
11913µs my $configureAttrStr =
120 $Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes};
12116µs1154µs my $pluginAttrStr =
# spent 154µs making 1 call to Foswiki::Func::getPreferencesValue
122 Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES');
123
12417µs17µs debug( 'TablePlugin', "\t configureAttrStr=$configureAttrStr" )
# spent 7µs making 1 call to Foswiki::Plugins::TablePlugin::debug
125 if $configureAttrStr;
12616µs16µs debug( 'TablePlugin', "\t pluginAttrStr=$pluginAttrStr" ) if $pluginAttrStr;
# spent 6µs making 1 call to Foswiki::Plugins::TablePlugin::debug
12712µs debug( 'TablePlugin',
128 "\t no settings from configure could be read; using default values" )
129 if !$configureAttrStr;
13011µs $configureAttrStr ||= $DEFAULT_TABLE_SETTINGS;
131
13218µs11.43ms $configureAttrStr = Foswiki::Func::expandCommonVariables( $configureAttrStr,
# spent 1.43ms making 1 call to Foswiki::Func::expandCommonVariables
133 $topic, $web, undef )
134 if $configureAttrStr;
13516µs11.26ms $pluginAttrStr = Foswiki::Func::expandCommonVariables( $pluginAttrStr,
# spent 1.26ms making 1 call to Foswiki::Func::expandCommonVariables
136 $topic, $web, undef )
137 if $pluginAttrStr;
138
139118µs1410µs my %configureParams = Foswiki::Func::extractParameters($configureAttrStr);
# spent 410µs making 1 call to Foswiki::Func::extractParameters
14019µs1351µs my %pluginParams = Foswiki::Func::extractParameters($pluginAttrStr);
# spent 351µs making 1 call to Foswiki::Func::extractParameters
141
142125µs %pluginAttributes = ( %configureParams, %pluginParams );
143}
144
145
# spent 32.8ms (20.4+12.4) within Foswiki::Plugins::TablePlugin::afterCommonTagsHandler which was called 1131 times, avg 29µs/call: # 1131 times (20.4ms+12.4ms) by Foswiki::Plugin::invoke at line 287 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugin.pm, avg 29µs/call
sub afterCommonTagsHandler {
146
14711315.14ms11317.11ms debug( '', 'afterCommonTagsHandler' );
# spent 7.11ms making 1131 calls to Foswiki::Plugins::TablePlugin::debug, avg 6µs/call
14811319.48ms11315.25ms _writeStyleToHead();
# spent 5.25ms making 1131 calls to Foswiki::Plugins::TablePlugin::_writeStyleToHead, avg 5µs/call
149}
150
151=pod
152
153addHeadStyles( $id, \@styles )
154
155Store list of CSS lines to be written.
156
157=cut
158
159sub addHeadStyles {
160 my ( $inId, $inStyles ) = @_;
161
162 $styles->{$web}->{$topic}->{$inId} = $inStyles;
163}
164
165
# spent 5.25ms within Foswiki::Plugins::TablePlugin::_writeStyleToHead which was called 1131 times, avg 5µs/call: # 1131 times (5.25ms+0s) by Foswiki::Plugins::TablePlugin::afterCommonTagsHandler at line 148, avg 5µs/call
sub _writeStyleToHead {
166
16711316.52ms return if !$styles->{$web}->{$topic};
168
169 my @allStyles = ();
170 foreach my $id ( sort keys %{ $styles->{$web}->{$topic} } ) {
171 push @allStyles, @{ $styles->{$web}->{$topic}->{$id} };
172 }
173 my $styleText = join( "\n", @allStyles );
174 debug( 'TablePlugin', "_writeStyleToHead; styleText=$styleText" );
175
176 my $header = <<EOS;
177<style type="text/css" media="all">
178$styleText
179</style>
180EOS
181 Foswiki::Func::addToHEAD( "TABLEPLUGIN_${web}_${topic}", $header );
182}
183
184=pod
185
186Shorthand debugging call.
187
188=cut
189
190
# spent 7.30ms within Foswiki::Plugins::TablePlugin::debug which was called 1155 times, avg 6µs/call: # 1131 times (7.11ms+0s) by Foswiki::Plugins::TablePlugin::afterCommonTagsHandler at line 147, avg 6µs/call # 14 times (100µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debug at line 1967 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 7µs/call # 5 times (37µs+0s) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 55, avg 7µs/call # once (19µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 32 # once (10µs+0s) by Foswiki::Plugins::TablePlugin::initPlugin at line 48 # once (7µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 124 # once (6µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 118 # once (6µs+0s) by Foswiki::Plugins::TablePlugin::_readPluginSettings at line 126
sub debug {
19111552.03ms my ( $origin, $text ) = @_;
19211557.88ms return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug};
193 return if !$text;
194
195 $origin ||= 'TablePlugin';
196 $text = "$origin: $text";
197
198 print STDERR $text . "\n" if $DEBUG_FROM_UNIT_TEST;
199 Foswiki::Func::writeDebug("$text");
200}
201
202
# spent 41µs within Foswiki::Plugins::TablePlugin::debugData which was called 6 times, avg 7µs/call: # 6 times (41µs+0s) by Foswiki::Plugins::TablePlugin::Core::_debugData at line 1971 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/TablePlugin/Core.pm, avg 7µs/call
sub debugData {
203615µs my ( $origin, $text, $data ) = @_;
204
205644µs return if !$Foswiki::cfg{Plugins}{TablePlugin}{Debug};
206 $origin ||= 'TablePlugin';
207 Foswiki::Func::writeDebug("$origin: $text:");
208 print STDERR "$origin: $text:" . "\n" if $DEBUG_FROM_UNIT_TEST;
209 if ($data) {
210 eval
211'use Data::Dumper; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 1; Foswiki::Func::writeDebug(Dumper($data));';
212 print STDERR Dumper($data) . "\n" if $DEBUG_FROM_UNIT_TEST;
213 }
214}
215
216110µs1;
217__END__
 
# spent 35µs within Foswiki::Plugins::TablePlugin::CORE:match which was called 5 times, avg 7µs/call: # 5 times (35µs+0s) by Foswiki::Plugins::TablePlugin::preRenderingHandler at line 59, avg 7µs/call
sub Foswiki::Plugins::TablePlugin::CORE:match; # opcode