Filename | /var/www/foswikidev/core/lib/Foswiki/Serialise.pm |
Statements | Executed 105338 statements in 327ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
26327 | 1 | 1 | 256ms | 64.5s | deserialise | Foswiki::Serialise::
26328 | 2 | 1 | 44.5ms | 44.7ms | _getSerialiser | Foswiki::Serialise::
1 | 1 | 1 | 12µs | 388µs | serialise | Foswiki::Serialise::
1 | 1 | 1 | 12µs | 25µs | BEGIN@4 | Foswiki::Serialise::
1 | 1 | 1 | 12µs | 50µs | BEGIN@92 | Foswiki::Serialise::
1 | 1 | 1 | 9µs | 13µs | BEGIN@5 | Foswiki::Serialise::
1 | 1 | 1 | 8µs | 32µs | BEGIN@7 | Foswiki::Serialise::
0 | 0 | 0 | 0s | 0s | convertMeta | Foswiki::Serialise::
0 | 0 | 0 | 0s | 0s | finish | Foswiki::Serialise::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Serialise; | ||||
3 | |||||
4 | 2 | 25µs | 2 | 38µ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 # spent 25µs making 1 call to Foswiki::Serialise::BEGIN@4
# spent 13µs making 1 call to strict::import |
5 | 2 | 23µs | 2 | 17µ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 # spent 13µs making 1 call to Foswiki::Serialise::BEGIN@5
# spent 4µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 242µs | 2 | 55µ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 # 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 | |||||
13 | API to allow structures to be serialised and de-serialized. This API will only return | ||||
14 | basic types like hashes and arrarys | ||||
15 | |||||
16 | =cut | ||||
17 | |||||
18 | #lets only load the serialiser once per execution | ||||
19 | 1 | 800ns | my %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 | ||||
35 | 1 | 2µs | my ( $value, $style ) = @_; | ||
36 | |||||
37 | 1 | 7µs | 2 | 376µ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 | ||||
52 | 26327 | 20.1ms | my ( $text, $style, $into ) = @_; | ||
53 | |||||
54 | 26327 | 166ms | 52654 | 64.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 | sub _getSerialiser { | ||||
59 | 26328 | 9.10ms | my $style = shift || 'Simplified'; | ||
60 | |||||
61 | 26328 | 132ms | return $serialisers{$style} | ||
62 | if ( defined( $serialisers{$style} ) ); | ||||
63 | |||||
64 | 2 | 2µs | $style = 'Simplified' if ( $style eq 'Default' ); | ||
65 | 2 | 2µs | my $module = "Foswiki::Serialise::$style"; | ||
66 | |||||
67 | 2 | 50µ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 | |||||
72 | 2 | 800ns | my $cereal; | ||
73 | 2 | 1µ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 | ||||
78 | 2 | 11µs | 2 | 18µ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 |
79 | 2 | 3µs | $serialisers{$style} = $cereal; | ||
80 | 2 | 7µ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 | ||||
84 | sub 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) ) { | ||||
92 | 2 | 162µs | 2 | 88µ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 # 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 | |||||
123 | Finishes all instantiated serialisers. There should only be at most one of each | ||||
124 | serialiser instantiated at any given time, so you normally wouldn't want to call | ||||
125 | this, except perhaps from the unit test framework; see Item11349. | ||||
126 | |||||
127 | =cut | ||||
128 | |||||
129 | sub 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 | |||||
142 | 1 | 3µs | 1; | ||
143 | __END__ |