← 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:16 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Serialise/Embedded.pm
StatementsExecuted 1001 statements in 6.19ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
6211.78ms3.83msFoswiki::Serialise::Embedded::::_writeTypesFoswiki::Serialise::Embedded::_writeTypes
66211.01ms1.80msFoswiki::Serialise::Embedded::::_writeKeyValueFoswiki::Serialise::Embedded::_writeKeyValue
6611663µs792µsFoswiki::Serialise::Embedded::::dataEncodeFoswiki::Serialise::Embedded::dataEncode
211180µs4.06msFoswiki::Serialise::Embedded::::getEmbeddedStoreFormFoswiki::Serialise::Embedded::getEmbeddedStoreForm
2211137µs137µsFoswiki::Serialise::Embedded::::CORE:sortFoswiki::Serialise::Embedded::CORE:sort (opcode)
6611130µs130µsFoswiki::Serialise::Embedded::::CORE:substFoswiki::Serialise::Embedded::CORE:subst (opcode)
4831111µs111µsFoswiki::Serialise::Embedded::::CORE:matchFoswiki::Serialise::Embedded::CORE:match (opcode)
11160µs79µsFoswiki::Serialise::Embedded::::BEGIN@15Foswiki::Serialise::Embedded::BEGIN@15
21158µs4.12msFoswiki::Serialise::Embedded::::writeFoswiki::Serialise::Embedded::write
11137µs133µsFoswiki::Serialise::Embedded::::BEGIN@19Foswiki::Serialise::Embedded::BEGIN@19
11136µs81µsFoswiki::Serialise::Embedded::::BEGIN@16Foswiki::Serialise::Embedded::BEGIN@16
11126µs26µsFoswiki::Serialise::Embedded::::newFoswiki::Serialise::Embedded::new
11118µs18µsFoswiki::Serialise::Embedded::::BEGIN@17Foswiki::Serialise::Embedded::BEGIN@17
11116µs16µsFoswiki::Serialise::Embedded::::BEGIN@18Foswiki::Serialise::Embedded::BEGIN@18
0000s0sFoswiki::Serialise::Embedded::::readFoswiki::Serialise::Embedded::read
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=begin TML
4
5---+ package Foswiki::Serialise::Embedded
6
7This is __the__ on disk format serialiser and deserialise for TWiki and Foswiki topics legacy .txt format.
8
9__WARNING__ this is only for Foswiki::Meta objects.
10
11=cut
12
13package Foswiki::Serialise::Embedded;
14
15296µs298µs
# spent 79µs (60+19) within Foswiki::Serialise::Embedded::BEGIN@15 which was called: # once (60µs+19µs) by Foswiki::Serialise::getSerialiser at line 15
use strict;
# spent 79µs making 1 call to Foswiki::Serialise::Embedded::BEGIN@15 # spent 19µs making 1 call to strict::import
16287µs2127µs
# spent 81µs (36+45) within Foswiki::Serialise::Embedded::BEGIN@16 which was called: # once (36µs+45µs) by Foswiki::Serialise::getSerialiser at line 16
use warnings;
# spent 81µs making 1 call to Foswiki::Serialise::Embedded::BEGIN@16 # spent 45µs making 1 call to warnings::import
17260µs118µs
# spent 18µs within Foswiki::Serialise::Embedded::BEGIN@17 which was called: # once (18µs+0s) by Foswiki::Serialise::getSerialiser at line 17
use Foswiki ();
# spent 18µs making 1 call to Foswiki::Serialise::Embedded::BEGIN@17
18257µs116µs
# spent 16µs within Foswiki::Serialise::Embedded::BEGIN@18 which was called: # once (16µs+0s) by Foswiki::Serialise::getSerialiser at line 18
use Foswiki::Meta ();
# spent 16µs making 1 call to Foswiki::Serialise::Embedded::BEGIN@18
1921.81ms2229µs
# spent 133µs (37+96) within Foswiki::Serialise::Embedded::BEGIN@19 which was called: # once (37µs+96µs) by Foswiki::Serialise::getSerialiser at line 19
use Assert;
# spent 133µs making 1 call to Foswiki::Serialise::Embedded::BEGIN@19 # spent 96µs making 1 call to Assert::import
20
21=begin TML
22
23---++ ClassMethod new( $class, ) -> $cereal
24
25=cut
26
27
# spent 26µs within Foswiki::Serialise::Embedded::new which was called: # once (26µs+0s) by Foswiki::Serialise::getSerialiser at line 81 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Serialise.pm
sub new {
2812µs my $class = shift;
29117µs my $this = bless( {}, $class );
30114µs return $this;
31}
32
33
# spent 4.12ms (58µs+4.06) within Foswiki::Serialise::Embedded::write which was called 2 times, avg 2.06ms/call: # 2 times (58µs+4.06ms) by Foswiki::Serialise::serialise at line 39 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Serialise.pm, avg 2.06ms/call
sub write {
3424µs my $module = shift;
3524µs my ( $session, $result ) = @_;
36
37210µs28µs ASSERT( $result->isa('Foswiki::Meta') ) if DEBUG;
# spent 8µs making 2 calls to Assert::ASSERTS_OFF, avg 4µs/call
38224µs24.06ms return getEmbeddedStoreForm($result);
# spent 4.06ms making 2 calls to Foswiki::Serialise::Embedded::getEmbeddedStoreForm, avg 2.03ms/call
39}
40
41#really awkward - setEmbeddedStoreForm interleaves reading from text and calling Meta calls to update cache information
42#need to separate these out in a performant way.
43sub read {
44 die 'not implemented';
45 my $module = shift;
46 my ( $session, $result ) = @_;
47
48 ASSERT( $result->isa('Foswiki::Meta') ) if DEBUG;
49 return setEmbeddedStoreForm($result);
50}
51
52=begin TML
53
54---++ ObjectMethod getEmbeddedStoreForm() -> $text
55
56Generate the embedded store form of the topic. The embedded store
57form has meta-data values embedded using %META: lines. The text
58stored in the meta is taken as the topic text.
59
60TODO: Soooo.... if we wanted to make a meta->setPreference('VARIABLE', 'Values...'); we would have to change this to
61 1 see if that preference is set in the {_text} using the * Set syntax, in which case, replace that
62 2 or let the META::PREF.. work as it does now..
63
64yay :/
65
66TODO: can we move this code into Foswiki::Serialise ?
67
68=cut
69
70
# spent 4.06ms (180µs+3.88) within Foswiki::Serialise::Embedded::getEmbeddedStoreForm which was called 2 times, avg 2.03ms/call: # 2 times (180µs+3.88ms) by Foswiki::Serialise::Embedded::write at line 38, avg 2.03ms/call
sub getEmbeddedStoreForm {
7123µs my $this = shift;
72
7329µs26µs ASSERT( $this->{_web} && $this->{_topic}, 'this is not a topic object' )
# spent 6µs making 2 calls to Assert::ASSERTS_OFF, avg 3µs/call
74 if DEBUG;
7526µs $this->{_text} ||= '';
76
7725µs require Foswiki::Store; # for encoding
78
79212µs242µs my $ti = $this->get('TOPICINFO');
# spent 42µs making 2 calls to Foswiki::Meta::get, avg 21µs/call
8025µs delete $ti->{rev} if $ti; # don't want this written
81
82215µs2544µs my $text = _writeTypes( $this, 'TOPICINFO', 'TOPICPARENT' );
# spent 544µs making 2 calls to Foswiki::Serialise::Embedded::_writeTypes, avg 272µs/call
83214µs $text .= $this->{_text};
84231µs43.28ms my $end =
# spent 3.28ms making 4 calls to Foswiki::Serialise::Embedded::_writeTypes, avg 821µs/call
85 _writeTypes( $this, 'FORM', 'FIELD', 'FILEATTACHMENT', 'TOPICMOVED' )
86 . _writeTypes( $this, 'not', 'TOPICINFO', 'TOPICPARENT', 'FORM', 'FIELD',
87 'FILEATTACHMENT', 'TOPICMOVED' );
8824µs $text .= "\n" if $end;
89
9024µs $ti->{rev} = $ti->{version} if $ti;
91
92252µs return $text . $end;
93}
94
95# PRIVATE STATIC Write a meta-data key=value pair
96# The encoding is reversed in _readKeyValues
97
# spent 1.80ms (1.01+792µs) within Foswiki::Serialise::Embedded::_writeKeyValue which was called 66 times, avg 27µs/call: # 45 times (695µs+543µs) by Foswiki::Serialise::Embedded::_writeTypes at line 149, avg 28µs/call # 21 times (316µs+249µs) by Foswiki::Serialise::Embedded::_writeTypes at line 141, avg 27µs/call
sub _writeKeyValue {
9866125µs my ( $key, $value ) = @_;
99
10066174µs if ( defined($value) ) {
10166310µs66792µs $value = dataEncode($value);
# spent 792µs making 66 calls to Foswiki::Serialise::Embedded::dataEncode, avg 12µs/call
102 }
103 else {
104 $value = '';
105 }
106
10766370µs return $key . '="' . $value . '"';
108}
109
110# PRIVATE STATIC: Write all the key=value pairs for the types listed
111
# spent 3.83ms (1.78+2.05) within Foswiki::Serialise::Embedded::_writeTypes which was called 6 times, avg 638µs/call: # 4 times (1.50ms+1.78ms) by Foswiki::Serialise::Embedded::getEmbeddedStoreForm at line 84, avg 821µs/call # 2 times (275µs+269µs) by Foswiki::Serialise::Embedded::getEmbeddedStoreForm at line 82, avg 272µs/call
sub _writeTypes {
112623µs my ( $this, @types ) = @_;
113
114612µs my $text = '';
115
116616µs if ( $types[0] eq 'not' ) {
117
118 # write all types that are not in the list
11923µs my %seen;
120234µs @seen{@types} = ();
12125µs @types = (); # empty "not in list"
122220µs foreach my $key ( keys %$this ) {
12318144µs1437µs push( @types, $key )
# spent 37µs making 14 calls to Foswiki::Serialise::Embedded::CORE:match, avg 3µs/call
124 unless ( exists $seen{$key} || $key =~ /^_/ );
125 }
126 }
127
128635µs foreach my $type (@types) {
1291291µs1223µs next if ( $type =~ /^_/ );
# spent 23µs making 12 calls to Foswiki::Serialise::Embedded::CORE:match, avg 2µs/call
1301222µs my $data = $this->{$type};
1311220µs next if !defined $data;
132423µs foreach my $item (@$data) {
13322151µs2251µs next if ( $item =~ /^_/ );
# spent 51µs making 22 calls to Foswiki::Serialise::Embedded::CORE:match, avg 2µs/call
1342234µs my $sep = '';
1352239µs $text .= '%META:' . $type . '{';
1362240µs my $name = $item->{name};
1372255µs if ($name) {
138
139 # If there's a name field, put first to make regexp
140 # based searching easier
14121112µs21565µs $text .= _writeKeyValue( 'name', $item->{name} );
# spent 565µs making 21 calls to Foswiki::Serialise::Embedded::_writeKeyValue, avg 27µs/call
1422130µs $sep = ' ';
143 }
14422332µs22137µs foreach my $key ( sort keys %$item ) {
# spent 137µs making 22 calls to Foswiki::Serialise::Embedded::CORE:sort, avg 6µs/call
145
146 #next if ($key =~ /^_/ );
14766247µs if ( $key ne 'name' ) {
1484560µs $text .= $sep;
14945252µs451.24ms $text .= _writeKeyValue( $key, $item->{$key} );
# spent 1.24ms making 45 calls to Foswiki::Serialise::Embedded::_writeKeyValue, avg 28µs/call
1504563µs $sep = ' ';
151 }
152 }
1532265µs $text .= '}%' . "\n";
154 }
155 }
156
157648µs return $text;
158}
159
160=begin TML
161
162---++ StaticMethod dataEncode( $uncoded ) -> $coded
163
164Encode meta-data field values, escaping out selected characters.
165The encoding is chosen to avoid problems with parsing the attribute
166values in embedded meta-data, while minimising the number of
167characters encoded so searches can still work (fairly) sensibly.
168
169The encoding has to be exported because Foswiki (and plugins) use
170encoded field data in other places e.g. RDiff, mainly as a shorthand
171for the properly parsed meta object. Some day we may be able to
172eliminate that....
173
174=cut
175
176
# spent 792µs (663+130) within Foswiki::Serialise::Embedded::dataEncode which was called 66 times, avg 12µs/call: # 66 times (663µs+130µs) by Foswiki::Serialise::Embedded::_writeKeyValue at line 101, avg 12µs/call
sub dataEncode {
1776693µs my $datum = shift;
178
17966445µs66130µs $datum =~ s/([%"\r\n{}])/'%'.sprintf('%02x',ord($1))/ge;
# spent 130µs making 66 calls to Foswiki::Serialise::Embedded::CORE:subst, avg 2µs/call
18066347µs return $datum;
181}
182
18316µs1;
184__END__
 
# spent 111µs within Foswiki::Serialise::Embedded::CORE:match which was called 48 times, avg 2µs/call: # 22 times (51µs+0s) by Foswiki::Serialise::Embedded::_writeTypes at line 133, avg 2µs/call # 14 times (37µs+0s) by Foswiki::Serialise::Embedded::_writeTypes at line 123, avg 3µs/call # 12 times (23µs+0s) by Foswiki::Serialise::Embedded::_writeTypes at line 129, avg 2µs/call
sub Foswiki::Serialise::Embedded::CORE:match; # opcode
# spent 137µs within Foswiki::Serialise::Embedded::CORE:sort which was called 22 times, avg 6µs/call: # 22 times (137µs+0s) by Foswiki::Serialise::Embedded::_writeTypes at line 144, avg 6µs/call
sub Foswiki::Serialise::Embedded::CORE:sort; # opcode
# spent 130µs within Foswiki::Serialise::Embedded::CORE:subst which was called 66 times, avg 2µs/call: # 66 times (130µs+0s) by Foswiki::Serialise::Embedded::dataEncode at line 179, avg 2µs/call
sub Foswiki::Serialise::Embedded::CORE:subst; # opcode