← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 11:58:52 2013
Reported on Tue Oct 15 12:01:53 2013

Filename/usr/lib/perl5/XML/LibXML/SAX/Parser.pm
StatementsExecuted 73176 statements in 335ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
161911189ms529msXML::LibXML::SAX::Parser::::process_elementXML::LibXML::SAX::Parser::process_element (recurses: max depth 7, inclusive time 818ms)
48333162.0ms531msXML::LibXML::SAX::Parser::::process_nodeXML::LibXML::SAX::Parser::process_node (recurses: max depth 8, inclusive time 1.48s)
11117.7ms17.8msXML::LibXML::SAX::Parser::::BEGIN@17XML::LibXML::SAX::Parser::BEGIN@17
11111.9ms29.0msXML::LibXML::SAX::Parser::::BEGIN@15XML::LibXML::SAX::Parser::BEGIN@15
28213.67ms542msXML::LibXML::SAX::Parser::::generateXML::LibXML::SAX::Parser::generate
1112.13ms5.38msXML::LibXML::SAX::Parser::::BEGIN@16XML::LibXML::SAX::Parser::BEGIN@16
25111.08ms467msXML::LibXML::SAX::Parser::::_parse_stringXML::LibXML::SAX::Parser::_parse_string
111754µs785µsXML::LibXML::SAX::Parser::::BEGIN@18XML::LibXML::SAX::Parser::BEGIN@18
311112µs91.8msXML::LibXML::SAX::Parser::::_parse_systemidXML::LibXML::SAX::Parser::_parse_systemid
11121µs28µsXML::LibXML::SAX::Parser::::BEGIN@12XML::LibXML::SAX::Parser::BEGIN@12
11112µs66µsXML::LibXML::SAX::Parser::::BEGIN@13XML::LibXML::SAX::Parser::BEGIN@13
0000s0sXML::LibXML::SAX::Parser::::CLONE_SKIPXML::LibXML::SAX::Parser::CLONE_SKIP
0000s0sXML::LibXML::SAX::Parser::::__ANON__[:77]XML::LibXML::SAX::Parser::__ANON__[:77]
0000s0sXML::LibXML::SAX::Parser::::__ANON__[:78]XML::LibXML::SAX::Parser::__ANON__[:78]
0000s0sXML::LibXML::SAX::Parser::::__ANON__[:79]XML::LibXML::SAX::Parser::__ANON__[:79]
0000s0sXML::LibXML::SAX::Parser::::__ANON__[:80]XML::LibXML::SAX::Parser::__ANON__[:80]
0000s0sXML::LibXML::SAX::Parser::::__ANON__[:81]XML::LibXML::SAX::Parser::__ANON__[:81]
0000s0sXML::LibXML::SAX::Parser::::__ANON__[:82]XML::LibXML::SAX::Parser::__ANON__[:82]
0000s0sXML::LibXML::SAX::Parser::::_parse_bytestreamXML::LibXML::SAX::Parser::_parse_bytestream
0000s0sXML::LibXML::SAX::Parser::::_parse_characterstreamXML::LibXML::SAX::Parser::_parse_characterstream
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# $Id: Parser.pm 785 2009-07-16 14:17:46Z pajas $
2#
3# This is free software, you may use it and distribute it under the same terms as
4# Perl itself.
5#
6# Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
7#
8#
9
10package XML::LibXML::SAX::Parser;
11
12337µs235µs
# spent 28µs (21+7) within XML::LibXML::SAX::Parser::BEGIN@12 which was called: # once (21µs+7µs) by XML::SAX::ParserFactory::parser at line 12
use strict;
# spent 28µs making 1 call to XML::LibXML::SAX::Parser::BEGIN@12 # spent 7µs making 1 call to strict::import
13340µs2120µs
# spent 66µs (12+54) within XML::LibXML::SAX::Parser::BEGIN@13 which was called: # once (12µs+54µs) by XML::SAX::ParserFactory::parser at line 13
use vars qw($VERSION @ISA);
# spent 66µs making 1 call to XML::LibXML::SAX::Parser::BEGIN@13 # spent 54µs making 1 call to vars::import
14
153185µs229.3ms
# spent 29.0ms (11.9+17.1) within XML::LibXML::SAX::Parser::BEGIN@15 which was called: # once (11.9ms+17.1ms) by XML::SAX::ParserFactory::parser at line 15
use XML::LibXML;
# spent 29.0ms making 1 call to XML::LibXML::SAX::Parser::BEGIN@15 # spent 335µs making 1 call to XML::LibXML::import
163225µs26.05ms
# spent 5.38ms (2.13+3.25) within XML::LibXML::SAX::Parser::BEGIN@16 which was called: # once (2.13ms+3.25ms) by XML::SAX::ParserFactory::parser at line 16
use XML::LibXML::Common qw(:libxml);
# spent 5.38ms making 1 call to XML::LibXML::SAX::Parser::BEGIN@16 # spent 675µs making 1 call to Exporter::import
173267µs117.8ms
# spent 17.8ms (17.7+92µs) within XML::LibXML::SAX::Parser::BEGIN@17 which was called: # once (17.7ms+92µs) by XML::SAX::ParserFactory::parser at line 17
use XML::SAX::Base;
# spent 17.8ms making 1 call to XML::LibXML::SAX::Parser::BEGIN@17
1831.61ms1785µs
# spent 785µs (754+30) within XML::LibXML::SAX::Parser::BEGIN@18 which was called: # once (754µs+30µs) by XML::SAX::ParserFactory::parser at line 18
use XML::SAX::DocumentLocator;
# spent 785µs making 1 call to XML::LibXML::SAX::Parser::BEGIN@18
19
2012µs$VERSION = "1.70"; # VERSION TEMPLATE: DO NOT CHANGE
21116µs@ISA = ('XML::SAX::Base');
22
23sub CLONE_SKIP {
24 return $XML::LibXML::__threads_shared ? 0 : 1;
25}
26
27sub _parse_characterstream {
28 my ($self, $fh, $options) = @_;
29 die "parsing a characterstream is not supported at this time";
30}
31
32sub _parse_bytestream {
33 my ($self, $fh, $options) = @_;
34 my $parser = XML::LibXML->new();
35 my $doc = exists($options->{Source}{SystemId}) ? $parser->parse_fh($fh, $options->{Source}{SystemId}) : $parser->parse_fh($fh);
36 $self->generate($doc);
37}
38
39
# spent 467ms (1.08+466) within XML::LibXML::SAX::Parser::_parse_string which was called 25 times, avg 18.7ms/call: # 25 times (1.08ms+466ms) by XML::SAX::Base::parse at line 2602 of XML/SAX/Base.pm, avg 18.7ms/call
sub _parse_string {
402594µs my ($self, $str, $options) = @_;
4125159µs25310µs my $parser = XML::LibXML->new();
# spent 310µs making 25 calls to XML::LibXML::new, avg 12µs/call
4225213µs2510.9ms my $doc = exists($options->{Source}{SystemId}) ? $parser->parse_string($str, $options->{Source}{SystemId}) : $parser->parse_string($str);
# spent 10.9ms making 25 calls to XML::LibXML::parse_string, avg 436µs/call
43251.91ms50453ms $self->generate($doc);
# spent 453ms making 25 calls to XML::LibXML::SAX::Parser::generate, avg 18.1ms/call # spent 50µs making 25 calls to XML::LibXML::Node::DESTROY, avg 2µs/call
44}
45
46
# spent 91.8ms (112µs+91.7) within XML::LibXML::SAX::Parser::_parse_systemid which was called 3 times, avg 30.6ms/call: # 3 times (112µs+91.7ms) by XML::SAX::Base::parse at line 2602 of XML/SAX/Base.pm, avg 30.6ms/call
sub _parse_systemid {
4735µs my ($self, $sysid, $options) = @_;
48320µs368µs my $parser = XML::LibXML->new();
# spent 68µs making 3 calls to XML::LibXML::new, avg 23µs/call
49317µs32.13ms my $doc = $parser->parse_file($sysid);
# spent 2.13ms making 3 calls to XML::LibXML::parse_file, avg 711µs/call
503262µs689.3ms $self->generate($doc);
# spent 89.3ms making 3 calls to XML::LibXML::SAX::Parser::generate, avg 29.8ms/call # spent 6µs making 3 calls to XML::LibXML::Node::DESTROY, avg 2µs/call
51}
52
53
# spent 542ms (3.67+539) within XML::LibXML::SAX::Parser::generate which was called 28 times, avg 19.4ms/call: # 25 times (3.21ms+450ms) by XML::LibXML::SAX::Parser::_parse_string at line 43, avg 18.1ms/call # 3 times (460µs+88.8ms) by XML::LibXML::SAX::Parser::_parse_systemid at line 50, avg 29.8ms/call
sub generate {
542824µs my $self = shift;
552829µs my ($node) = @_;
56
5728461µs28246µs my $doc = $node->ownerDocument();
# spent 246µs making 28 calls to XML::LibXML::Node::ownerDocument, avg 9µs/call
58 {
59 # precompute some DocumentLocator values
6056582µs my %locator = (
61 PublicId => undef,
62 SystemId => undef,
63 Encoding => undef,
64 XMLVersion => undef,
65 );
6628287µs2886µs my $dtd = defined $doc ? $doc->externalSubset() : undef;
# spent 86µs making 28 calls to XML::LibXML::Document::externalSubset, avg 3µs/call
672814µs if (defined $dtd) {
68 $locator{PublicId} = $dtd->publicId();
69 $locator{SystemId} = $dtd->systemId();
70 }
712826µs if (defined $doc) {
7228216µs2880µs $locator{Encoding} = $doc->encoding();
# spent 80µs making 28 calls to XML::LibXML::Document::encoding, avg 3µs/call
7328194µs2870µs $locator{XMLVersion} = $doc->version();
# spent 70µs making 28 calls to XML::LibXML::Document::version, avg 3µs/call
74 }
75 $self->set_document_locator(
76 XML::SAX::DocumentLocator->new(
77 sub { $locator{PublicId} },
78 sub { $locator{SystemId} },
79 sub { defined($self->{current_node}) ? $self->{current_node}->line_number() : undef },
80 sub { 1 },
81 sub { $locator{Encoding} },
82 sub { $locator{XMLVersion} },
8328897µs562.75ms ),
# spent 1.46ms making 28 calls to XML::SAX::Base::set_document_locator, avg 52µs/call # spent 1.30ms making 28 calls to XML::SAX::DocumentLocator::new, avg 46µs/call
84 );
85 }
86
8728712µs28124µs if ( $node->nodeType() == XML_DOCUMENT_NODE
# spent 124µs making 28 calls to XML::LibXML::Node::nodeType, avg 4µs/call
88 || $node->nodeType == XML_HTML_DOCUMENT_NODE ) {
8928172µs281.36ms $self->start_document({});
# spent 1.36ms making 28 calls to XML::SAX::Base::start_document, avg 48µs/call
9028564µs841.37ms $self->xml_decl({Version => $node->getVersion, Encoding => $node->getEncoding});
# spent 1.24ms making 28 calls to XML::SAX::Base::xml_decl, avg 44µs/call # spent 86µs making 28 calls to XML::LibXML::Document::getVersion, avg 3µs/call # spent 51µs making 28 calls to XML::LibXML::Document::getEncoding, avg 2µs/call
9128285µs28531ms $self->process_node($node);
# spent 531ms making 28 calls to XML::LibXML::SAX::Parser::process_node, avg 19.0ms/call
9228200µs561.69ms $self->end_document({});
# spent 1.64ms making 28 calls to XML::SAX::Base::end_document, avg 59µs/call # spent 54µs making 28 calls to XML::LibXML::Node::DESTROY, avg 2µs/call
93 }
94}
95
96
# spent 531ms (62.0+469) within XML::LibXML::SAX::Parser::process_node which was called 4833 times, avg 110µs/call: # 4777 times (60.8ms+-60.8ms) by XML::LibXML::SAX::Parser::process_element at line 244, avg 0s/call # 28 times (849µs+530ms) by XML::LibXML::SAX::Parser::generate at line 91, avg 19.0ms/call # 28 times (387µs+-387µs) by XML::LibXML::SAX::Parser::process_node at line 127, avg 0s/call
sub process_node {
9748333.62ms my ($self, $node) = @_;
98
9948336.26ms local $self->{current_node} = $node;
100
101483325.6ms483310.6ms my $node_type = $node->nodeType();
# spent 10.6ms making 4833 calls to XML::LibXML::Node::nodeType, avg 2µs/call
102483345.3ms8044589ms if ($node_type == XML_COMMENT_NODE) {
# spent 1.35s making 1619 calls to XML::LibXML::SAX::Parser::process_element, avg 832µs/call, recursion: max depth 7, sum of overlapping time 818ms # spent 49.8ms making 3147 calls to XML::SAX::Base::characters, avg 16µs/call # spent 8.75ms making 3147 calls to XML::LibXML::Node::nodeValue, avg 3µs/call # spent 502µs making 28 calls to XML::LibXML::Node::childNodes, avg 18µs/call # spent 493µs making 39 calls to XML::SAX::Base::comment, avg 13µs/call # spent 206µs making 39 calls to XML::LibXML::Node::getData, avg 5µs/call # spent 68µs making 25 calls to XML::LibXML::Namespace::DESTROY, avg 3µs/call
103 $self->comment( { Data => $node->getData } );
104 }
105 elsif ($node_type == XML_TEXT_NODE
106 || $node_type == XML_CDATA_SECTION_NODE) {
107 # warn($node->getData . "\n");
108 $self->characters( { Data => $node->nodeValue } );
109 }
110 elsif ($node_type == XML_ELEMENT_NODE) {
111 # warn("<" . $node->getName . ">\n");
112 $self->process_element($node);
113 # warn("</" . $node->getName . ">\n");
114 }
115 elsif ($node_type == XML_ENTITY_REF_NODE) {
116 foreach my $kid ($node->childNodes) {
117 # warn("child of entity ref: " . $kid->getType() . " called: " . $kid->getName . "\n");
118 $self->process_node($kid);
119 }
120 }
121 elsif ($node_type == XML_DOCUMENT_NODE
122 || $node_type == XML_HTML_DOCUMENT_NODE
123 || $node_type == XML_DOCUMENT_FRAG_NODE) {
124 # some times it is just usefull to generate SAX events from
125 # a document fragment (very good with filters).
126 foreach my $kid ($node->childNodes) {
12728277µs5334µs $self->process_node($kid);
# spent 34µs making 25 calls to XML::LibXML::Namespace::DESTROY, avg 1µs/call # spent 529ms making 28 calls to XML::LibXML::SAX::Parser::process_node, avg 18.9ms/call, recursion: max depth 1, sum of overlapping time 529ms
128 }
129 }
130 elsif ($node_type == XML_PI_NODE) {
131 $self->processing_instruction( { Target => $node->getName, Data => $node->getData } );
132 }
133 elsif ($node_type == XML_COMMENT_NODE) {
134 $self->comment( { Data => $node->getData } );
135 }
136 elsif ( $node_type == XML_XINCLUDE_START
137 || $node_type == XML_XINCLUDE_END ) {
138 # ignore!
139 # i may want to handle this one day, dunno yet
140 }
141 elsif ($node_type == XML_DTD_NODE ) {
142 # ignore!
143 # i will support DTDs, but had no time yet.
144 }
145 else {
146 # warn("unsupported node type: $node_type");
147 }
148
149}
150
151
# spent 529ms (189+340) within XML::LibXML::SAX::Parser::process_element which was called 1619 times, avg 327µs/call: # 1619 times (189ms+340ms) by XML::LibXML::SAX::Parser::process_node at line 102, avg 327µs/call
sub process_element {
1521619987µs my ($self, $element) = @_;
153
15416191.23ms my $attribs = {};
15516198.01ms16192.80ms my @ns_maps = $element->getNamespaces;
# spent 2.80ms making 1619 calls to XML::LibXML::Node::getNamespaces, avg 2µs/call
156
15716192.02ms foreach my $ns (@ns_maps) {
158531.16ms1872.24ms $self->start_prefix_mapping(
# spent 1.99ms making 53 calls to XML::SAX::Base::start_prefix_mapping, avg 38µs/call # spent 139µs making 53 calls to XML::LibXML::Namespace::href, avg 3µs/call # spent 115µs making 81 calls to XML::LibXML::Namespace::localname, avg 1µs/call
159 {
160 NamespaceURI => $ns->href,
161 Prefix => ( defined $ns->localname ? $ns->localname : ''),
162 }
163 );
164 }
165
166161918.1ms161918.3ms foreach my $attr ($element->attributes) {
# spent 18.3ms making 1619 calls to XML::LibXML::Node::attributes, avg 11µs/call
1672634655µs my $key;
168 # warn("Attr: $attr -> ", $attr->getName, " = ", $attr->getData, "\n");
169 # this isa dump thing...
170263417.9ms26346.71ms if ($attr->isa('XML::LibXML::Namespace')) {
# spent 6.71ms making 2634 calls to UNIVERSAL::isa, avg 3µs/call
171 # TODO This needs fixing modulo agreeing on what
172 # is the right thing to do here.
17353205µs53206µs unless ( defined $attr->name ) {
# spent 206µs making 53 calls to XML::LibXML::Namespace::name, avg 4µs/call
174 ## It's an atter like "xmlns='foo'"
175 $attribs->{"{}xmlns"} =
176 {
177 Name => "xmlns",
178 LocalName => "xmlns",
179 Prefix => "",
180 Value => $attr->href,
181 NamespaceURI => "",
182 };
183 }
184 else {
1855349µs my $prefix = "xmlns";
18653282µs5384µs my $localname = $attr->localname;
# spent 84µs making 53 calls to XML::LibXML::Namespace::localname, avg 2µs/call
1875389µs my $key = "{http://www.w3.org/2000/xmlns/}";
1885326µs my $name = "xmlns";
189
1905337µs if ( defined $localname ) {
1912820µs $key .= $localname;
1922827µs $name.= ":".$localname;
193 }
194
19553603µs5399µs $attribs->{$key} =
# spent 99µs making 53 calls to XML::LibXML::Namespace::href, avg 2µs/call
196 {
197 Name => $name,
198 Value => $attr->href,
199 NamespaceURI => "http://www.w3.org/2000/xmlns/",
200 Prefix => $prefix,
201 LocalName => $localname,
202 };
203 }
204 }
205 else {
206258111.4ms25814.42ms my $ns = $attr->namespaceURI;
# spent 4.42ms making 2581 calls to XML::LibXML::Node::namespaceURI, avg 2µs/call
207
20825811.49ms $ns = '' unless defined $ns;
209258113.5ms25814.94ms $key = "{$ns}".$attr->localname;
# spent 4.94ms making 2581 calls to XML::LibXML::Node::localname, avg 2µs/call
210 ## Not sure why, but $attr->name is coming through stripped
211 ## of its prefix, so we need to hand-assemble a real name.
212258110.8ms25813.74ms my $name = $attr->name;
# spent 3.74ms making 2581 calls to XML::LibXML::Attr::name, avg 1µs/call
2132581842µs $name = "" unless defined $name;
214
215258110.1ms25813.66ms my $prefix = $attr->prefix;
# spent 3.66ms making 2581 calls to XML::LibXML::Node::prefix, avg 1µs/call
21625811.17ms $prefix = "" unless defined $prefix;
21725813.97ms $name = "$prefix:$name"
218 if index( $name, ":" ) < 0 && length $prefix;
219
220258133.1ms516210.2ms $attribs->{$key} =
# spent 6.47ms making 2581 calls to XML::LibXML::Attr::value, avg 3µs/call # spent 3.75ms making 2581 calls to XML::LibXML::Node::localname, avg 1µs/call
221 {
222 Name => $name,
223 Value => $attr->value,
224 NamespaceURI => $ns,
225 Prefix => $prefix,
226 LocalName => $attr->localname,
227 };
228 }
229 # use Data::Dumper;
230 # warn("Attr made: ", Dumper($attribs->{$key}), "\n");
231 }
232
233161930.3ms911015.5ms my $node = {
# spent 3.92ms making 1619 calls to XML::LibXML::Node::nodeName, avg 2µs/call # spent 3.60ms making 2581 calls to XML::LibXML::Node::DESTROY, avg 1µs/call # spent 3.06ms making 1619 calls to XML::LibXML::Node::namespaceURI, avg 2µs/call # spent 2.40ms making 1619 calls to XML::LibXML::Node::localname, avg 1µs/call # spent 2.18ms making 1619 calls to XML::LibXML::Node::prefix, avg 1µs/call # spent 302µs making 53 calls to XML::LibXML::Namespace::DESTROY, avg 6µs/call
234 Name => $element->nodeName,
235 Attributes => $attribs,
236 NamespaceURI => $element->namespaceURI,
237 Prefix => $element->prefix || "",
238 LocalName => $element->localname,
239 };
240
24116194.25ms161935.0ms $self->start_element($node);
# spent 35.0ms making 1619 calls to XML::SAX::Base::start_element, avg 22µs/call
242
243161926.0ms161922.9ms foreach my $child ($element->childNodes) {
# spent 22.9ms making 1619 calls to XML::LibXML::Node::childNodes, avg 14µs/call
244477718.5ms47807µs $self->process_node($child);
# spent 7µs making 3 calls to XML::LibXML::Namespace::DESTROY, avg 2µs/call # spent 949ms making 4777 calls to XML::LibXML::SAX::Parser::process_node, avg 199µs/call, recursion: max depth 8, sum of overlapping time 949ms
245 }
246
24716197.82ms47776.28ms my $end_node = { %$node };
# spent 6.28ms making 4777 calls to XML::LibXML::Node::DESTROY, avg 1µs/call
248
24916191.47ms delete $end_node->{Attributes};
250
25116193.99ms161968.8ms $self->end_element($end_node);
# spent 68.8ms making 1619 calls to XML::SAX::Base::end_element, avg 42µs/call
252
253161912.7ms foreach my $ns (@ns_maps) {
254531.25ms1872.51ms $self->end_prefix_mapping(
# spent 2.24ms making 53 calls to XML::SAX::Base::end_prefix_mapping, avg 42µs/call # spent 161µs making 53 calls to XML::LibXML::Namespace::href, avg 3µs/call # spent 107µs making 81 calls to XML::LibXML::Namespace::localname, avg 1µs/call
255 {
256 NamespaceURI => $ns->href,
257 Prefix => ( defined $ns->localname ? $ns->localname : ''),
258 }
259 );
260 }
261}
262
26316µs1;
264
265__END__