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

Filename/var/www/foswikidev/core/lib/Foswiki/Serialise.pm
StatementsExecuted 105338 statements in 327ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2632711256ms64.5sFoswiki::Serialise::::deserialiseFoswiki::Serialise::deserialise
263282144.5ms44.7msFoswiki::Serialise::::_getSerialiserFoswiki::Serialise::_getSerialiser
11112µs388µsFoswiki::Serialise::::serialiseFoswiki::Serialise::serialise
11112µs25µsFoswiki::Serialise::::BEGIN@4Foswiki::Serialise::BEGIN@4
11112µs50µsFoswiki::Serialise::::BEGIN@92Foswiki::Serialise::BEGIN@92
1119µs13µsFoswiki::Serialise::::BEGIN@5Foswiki::Serialise::BEGIN@5
1118µs32µsFoswiki::Serialise::::BEGIN@7Foswiki::Serialise::BEGIN@7
0000s0sFoswiki::Serialise::::convertMetaFoswiki::Serialise::convertMeta
0000s0sFoswiki::Serialise::::finishFoswiki::Serialise::finish
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
2package Foswiki::Serialise;
3
4225µs238µs
# spent 25µs (12+13) within Foswiki::Serialise::BEGIN@4 which was called: # once (12µs+13µs) by Foswiki::Meta::BEGIN@116 at line 4
use strict;
# spent 25µs making 1 call to Foswiki::Serialise::BEGIN@4 # spent 13µs making 1 call to strict::import
5223µs217µs
# spent 13µs (9+4) within Foswiki::Serialise::BEGIN@5 which was called: # once (9µs+4µs) by Foswiki::Meta::BEGIN@116 at line 5
use warnings;
# spent 13µs making 1 call to Foswiki::Serialise::BEGIN@5 # spent 4µs making 1 call to warnings::import
6
72242µs255µs
# spent 32µs (8+23) within Foswiki::Serialise::BEGIN@7 which was called: # once (8µs+23µs) by Foswiki::Meta::BEGIN@116 at line 7
use Assert;
# spent 32µs making 1 call to Foswiki::Serialise::BEGIN@7 # spent 23µs making 1 call to Exporter::import
8
9=begin TML
10
11---+ package Foswiki::Serialise
12
13API to allow structures to be serialised and de-serialized. This API will only return
14basic types like hashes and arrarys
15
16=cut
17
18#lets only load the serialiser once per execution
191800nsmy %serialisers = ();
20
21#should this really be a register/request?
22
23=begin TML
24
25---++ StaticMethod serialise( $value, $style ) -> $cereal
26 * =$value= the perl object we're serializing (typically a ref/obj)
27 * =$style= serialization format
28
29#TODO: do we need to use Foswiki, or can we throw a Simple exception instead?
30#I think to be reusable we catually have to throw..
31
32=cut
33
34
# spent 388µs (12+376) within Foswiki::Serialise::serialise which was called: # once (12µs+376µs) by Foswiki::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Macros/QUERY.pm:68] at line 67 of /var/www/foswikidev/core/lib/Foswiki/Macros/QUERY.pm
sub serialise {
3512µs my ( $value, $style ) = @_;
36
3717µs2376µs return _getSerialiser($style)->write($value);
# spent 373µs making 1 call to Foswiki::Serialise::_getSerialiser # spent 3µs making 1 call to Foswiki::Serialise::Simplified::write
38}
39
40=begin TML
41
42---++ StaticMethod deserialise( $text, $style, $into ) -> $data
43 * =$text= the data we are deserialising
44 * =$style= serialization format
45 TODO: please work out how to add _some_ autodetection of format
46 * =$into= the perl object we're deserializing into. The serialiser
47 is matched to this object type.
48
49=cut
50
51
# spent 64.5s (256ms+64.3) within Foswiki::Serialise::deserialise which was called 26327 times, avg 2.45ms/call: # 26327 times (256ms+64.3s) by Foswiki::Store::Rcs::Store::readTopic at line 118 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Store.pm, avg 2.45ms/call
sub deserialise {
522632720.1ms my ( $text, $style, $into ) = @_;
53
5426327166ms5265464.3s return _getSerialiser($style)->read( $text, $into );
# spent 64.2s making 26327 calls to Foswiki::Serialise::Embedded::read, avg 2.44ms/call # spent 44.3ms making 26327 calls to Foswiki::Serialise::_getSerialiser, avg 2µs/call
55}
56
57#in the event of trouble, return 'Simplified'
58
# spent 44.7ms (44.5+161µs) within Foswiki::Serialise::_getSerialiser which was called 26328 times, avg 2µs/call: # 26327 times (44.2ms+100µs) by Foswiki::Serialise::deserialise at line 54, avg 2µs/call # once (312µs+61µs) by Foswiki::Serialise::serialise at line 37
sub _getSerialiser {
59263289.10ms my $style = shift || 'Simplified';
60
6126328132ms return $serialisers{$style}
62 if ( defined( $serialisers{$style} ) );
63
6422µs $style = 'Simplified' if ( $style eq 'Default' );
6522µs my $module = "Foswiki::Serialise::$style";
66
67250µs eval "require $module";
# spent 77µs executing statements in string eval # spent 64µs executing statements in string eval
68
69 # Assertion breaks unit test Fn_QUERY::test_InvalidStyle
70 #ASSERT( !$@, $@ ) if DEBUG;
71
722800ns my $cereal;
7321µs $cereal = _getSerialiser('Simplified') if $@;
74
75 # Devel::Leak::Object implies we're leaking Eg. Foswiki::Serialise::Embedded
76 # objects here, but they're just singletons we let hang around for minor
77 # perf reasons. See Item11349
78211µs218µs $cereal = $module->new() if ( not defined($cereal) );
# spent 10µs making 1 call to Foswiki::Serialise::Embedded::new # spent 9µs making 1 call to Foswiki::Serialise::Simplified::new
7923µs $serialisers{$style} = $cereal;
8027µs return $cereal;
81}
82
83#filter out parts of a meta object that don't make sense serialise (for example, json doesn't really like being sent a blessed object
84sub convertMeta {
85 my $savedMeta = shift;
86
87 my $meta = {};
88 $meta->{_web} = $savedMeta->web() if ( defined( $savedMeta->web() ) );
89 $meta->{_topic} = $savedMeta->topic() if ( defined( $savedMeta->topic() ) );
90
91 foreach my $key ( keys(%$savedMeta) ) {
922162µs288µs
# spent 50µs (12+38) within Foswiki::Serialise::BEGIN@92 which was called: # once (12µs+38µs) by Foswiki::Meta::BEGIN@116 at line 92
use Scalar::Util qw(blessed reftype);
# spent 50µs making 1 call to Foswiki::Serialise::BEGIN@92 # spent 38µs making 1 call to Exporter::import
93 if ( blessed( $savedMeta->{$key} ) ) {
94
95 #print STDERR "WARNING: skipping $key, its a blessed object\n";
96 next;
97 }
98 else {
99
100#print STDERR "WARNING: using $key - itsa ".(blessed($savedMeta->{$key})||reftype($savedMeta->{$key})||ref($savedMeta->{$key}||'notaref'))."\n";
101 }
102
103 #TODO: next if ( $key is one of the array types... and has no elements..
104
105 $meta->{$key} = $savedMeta->{$key};
106 }
107 if ( defined( $meta->{_topic} ) ) {
108
109 #TODO: exclude attachment meta too..
110 my $raw = serialise( $savedMeta, 'Embedded' );
111 if ( defined($raw) ) {
112 $meta->{_raw_text} = $raw;
113 }
114 }
115
116 return $meta;
117}
118
119=begin TML
120
121---++ StaticMethod finish
122
123Finishes all instantiated serialisers. There should only be at most one of each
124serialiser instantiated at any given time, so you normally wouldn't want to call
125this, except perhaps from the unit test framework; see Item11349.
126
127=cut
128
129sub finish {
130 my ($this) = @_;
131
132 while ( my ( $name, $cereal ) = each %serialisers ) {
133 if ( $cereal->can('finish') ) {
134 $cereal->finish();
135 }
136 delete $serialisers{$name};
137 }
138
139 return;
140}
141
14213µs1;
143__END__