| Filename | /usr/lib/perl5/XML/LibXML/SAX/Parser.pm |
| Statements | Executed 8336285 statements in 55.5s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 185299 | 1 | 1 | 31.9s | 87.1s | XML::LibXML::SAX::Parser::process_element (recurses: max depth 2, inclusive time 106s) |
| 555897 | 3 | 1 | 10.5s | 87.4s | XML::LibXML::SAX::Parser::process_node (recurses: max depth 4, inclusive time 215s) |
| 5000 | 1 | 1 | 599ms | 89.4s | XML::LibXML::SAX::Parser::generate |
| 5000 | 1 | 1 | 166ms | 91.6s | XML::LibXML::SAX::Parser::_parse_string |
| 1 | 1 | 1 | 14.7ms | 33.1ms | XML::LibXML::SAX::Parser::BEGIN@15 |
| 1 | 1 | 1 | 10.8ms | 10.8ms | XML::LibXML::SAX::Parser::BEGIN@18 |
| 1 | 1 | 1 | 9.79ms | 14.9ms | XML::LibXML::SAX::Parser::BEGIN@16 |
| 1 | 1 | 1 | 57µs | 72µs | XML::LibXML::SAX::Parser::BEGIN@12 |
| 1 | 1 | 1 | 26µs | 131µs | XML::LibXML::SAX::Parser::BEGIN@13 |
| 1 | 1 | 1 | 15µs | 15µs | XML::LibXML::SAX::Parser::BEGIN@17 |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::CLONE_SKIP |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::__ANON__[:77] |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::__ANON__[:78] |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::__ANON__[:79] |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::__ANON__[:80] |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::__ANON__[:81] |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::__ANON__[:82] |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::_parse_bytestream |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::_parse_characterstream |
| 0 | 0 | 0 | 0s | 0s | XML::LibXML::SAX::Parser::_parse_systemid |
| 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 | |||||
| 10 | package XML::LibXML::SAX::Parser; | ||||
| 11 | |||||
| 12 | 3 | 69µs | 2 | 87µs | # spent 72µs (57+15) within XML::LibXML::SAX::Parser::BEGIN@12 which was called:
# once (57µs+15µs) by XML::SAX::ParserFactory::BEGIN@1 at line 12 # spent 72µs making 1 call to XML::LibXML::SAX::Parser::BEGIN@12
# spent 15µs making 1 call to strict::import |
| 13 | 3 | 46µs | 2 | 236µs | # spent 131µs (26+105) within XML::LibXML::SAX::Parser::BEGIN@13 which was called:
# once (26µs+105µs) by XML::SAX::ParserFactory::BEGIN@1 at line 13 # spent 131µs making 1 call to XML::LibXML::SAX::Parser::BEGIN@13
# spent 105µs making 1 call to vars::import |
| 14 | |||||
| 15 | 3 | 211µs | 2 | 33.5ms | # spent 33.1ms (14.7+18.5) within XML::LibXML::SAX::Parser::BEGIN@15 which was called:
# once (14.7ms+18.5ms) by XML::SAX::ParserFactory::BEGIN@1 at line 15 # spent 33.1ms making 1 call to XML::LibXML::SAX::Parser::BEGIN@15
# spent 392µs making 1 call to XML::LibXML::import |
| 16 | 3 | 3.20ms | 2 | 15.9ms | # spent 14.9ms (9.79+5.09) within XML::LibXML::SAX::Parser::BEGIN@16 which was called:
# once (9.79ms+5.09ms) by XML::SAX::ParserFactory::BEGIN@1 at line 16 # spent 14.9ms making 1 call to XML::LibXML::SAX::Parser::BEGIN@16
# spent 1.02ms making 1 call to Exporter::import |
| 17 | 3 | 41µs | 1 | 15µs | # spent 15µs within XML::LibXML::SAX::Parser::BEGIN@17 which was called:
# once (15µs+0s) by XML::SAX::ParserFactory::BEGIN@1 at line 17 # spent 15µs making 1 call to XML::LibXML::SAX::Parser::BEGIN@17 |
| 18 | 3 | 11.7ms | 1 | 10.8ms | # spent 10.8ms (10.8+31µs) within XML::LibXML::SAX::Parser::BEGIN@18 which was called:
# once (10.8ms+31µs) by XML::SAX::ParserFactory::BEGIN@1 at line 18 # spent 10.8ms making 1 call to XML::LibXML::SAX::Parser::BEGIN@18 |
| 19 | |||||
| 20 | 1 | 2µs | $VERSION = "1.70"; # VERSION TEMPLATE: DO NOT CHANGE | ||
| 21 | 1 | 15µs | @ISA = ('XML::SAX::Base'); | ||
| 22 | |||||
| 23 | sub CLONE_SKIP { | ||||
| 24 | return $XML::LibXML::__threads_shared ? 0 : 1; | ||||
| 25 | } | ||||
| 26 | |||||
| 27 | sub _parse_characterstream { | ||||
| 28 | my ($self, $fh, $options) = @_; | ||||
| 29 | die "parsing a characterstream is not supported at this time"; | ||||
| 30 | } | ||||
| 31 | |||||
| 32 | sub _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 91.6s (166ms+91.5) within XML::LibXML::SAX::Parser::_parse_string which was called 5000 times, avg 18.3ms/call:
# 5000 times (166ms+91.5s) by XML::SAX::Base::parse at line 2602 of XML/SAX/Base.pm, avg 18.3ms/call | ||||
| 40 | 20000 | 319ms | my ($self, $str, $options) = @_; | ||
| 41 | 5000 | 73.7ms | my $parser = XML::LibXML->new(); # spent 73.7ms making 5000 calls to XML::LibXML::new, avg 15µs/call | ||
| 42 | 5000 | 1.87s | my $doc = exists($options->{Source}{SystemId}) ? $parser->parse_string($str, $options->{Source}{SystemId}) : $parser->parse_string($str); # spent 1.87s making 5000 calls to XML::LibXML::parse_string, avg 375µs/call | ||
| 43 | 10000 | 89.4s | $self->generate($doc); # spent 89.4s making 5000 calls to XML::LibXML::SAX::Parser::generate, avg 17.9ms/call
# spent 12.5ms making 5000 calls to XML::LibXML::Node::DESTROY, avg 3µs/call | ||
| 44 | } | ||||
| 45 | |||||
| 46 | sub _parse_systemid { | ||||
| 47 | my ($self, $sysid, $options) = @_; | ||||
| 48 | my $parser = XML::LibXML->new(); | ||||
| 49 | my $doc = $parser->parse_file($sysid); | ||||
| 50 | $self->generate($doc); | ||||
| 51 | } | ||||
| 52 | |||||
| 53 | # spent 89.4s (599ms+88.8) within XML::LibXML::SAX::Parser::generate which was called 5000 times, avg 17.9ms/call:
# 5000 times (599ms+88.8s) by XML::LibXML::SAX::Parser::_parse_string at line 43, avg 17.9ms/call | ||||
| 54 | 80000 | 738ms | my $self = shift; | ||
| 55 | my ($node) = @_; | ||||
| 56 | |||||
| 57 | 5000 | 26.5ms | my $doc = $node->ownerDocument(); # spent 26.5ms making 5000 calls to XML::LibXML::Node::ownerDocument, avg 5µs/call | ||
| 58 | { | ||||
| 59 | # precompute some DocumentLocator values | ||||
| 60 | my %locator = ( | ||||
| 61 | PublicId => undef, | ||||
| 62 | SystemId => undef, | ||||
| 63 | Encoding => undef, | ||||
| 64 | XMLVersion => undef, | ||||
| 65 | ); | ||||
| 66 | 5000 | 15.8ms | my $dtd = defined $doc ? $doc->externalSubset() : undef; # spent 15.8ms making 5000 calls to XML::LibXML::Document::externalSubset, avg 3µs/call | ||
| 67 | if (defined $dtd) { | ||||
| 68 | $locator{PublicId} = $dtd->publicId(); | ||||
| 69 | $locator{SystemId} = $dtd->systemId(); | ||||
| 70 | } | ||||
| 71 | if (defined $doc) { | ||||
| 72 | 5000 | 15.2ms | $locator{Encoding} = $doc->encoding(); # spent 15.2ms making 5000 calls to XML::LibXML::Document::encoding, avg 3µs/call | ||
| 73 | 5000 | 15.7ms | $locator{XMLVersion} = $doc->version(); # spent 15.7ms making 5000 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} }, | ||||
| 83 | 10000 | 430ms | ), # spent 273ms making 5000 calls to XML::SAX::Base::set_document_locator, avg 55µs/call
# spent 158ms making 5000 calls to XML::SAX::DocumentLocator::new, avg 32µs/call | ||
| 84 | ); | ||||
| 85 | } | ||||
| 86 | |||||
| 87 | 5000 | 16.4ms | if ( $node->nodeType() == XML_DOCUMENT_NODE # spent 16.4ms making 5000 calls to XML::LibXML::Node::nodeType, avg 3µs/call | ||
| 88 | || $node->nodeType == XML_HTML_DOCUMENT_NODE ) { | ||||
| 89 | 5000 | 253ms | $self->start_document({}); # spent 253ms making 5000 calls to XML::SAX::Base::start_document, avg 51µs/call | ||
| 90 | 15000 | 279ms | $self->xml_decl({Version => $node->getVersion, Encoding => $node->getEncoding}); # spent 251ms making 5000 calls to XML::SAX::Base::xml_decl, avg 50µs/call
# spent 15.9ms making 5000 calls to XML::LibXML::Document::getVersion, avg 3µs/call
# spent 12.3ms making 5000 calls to XML::LibXML::Document::getEncoding, avg 2µs/call | ||
| 91 | 5000 | 87.4s | $self->process_node($node); # spent 87.4s making 5000 calls to XML::LibXML::SAX::Parser::process_node, avg 17.5ms/call | ||
| 92 | 10000 | 286ms | $self->end_document({}); # spent 273ms making 5000 calls to XML::SAX::Base::end_document, avg 55µs/call
# spent 13.1ms making 5000 calls to XML::LibXML::Node::DESTROY, avg 3µs/call | ||
| 93 | } | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | # spent 87.4s (10.5+76.9) within XML::LibXML::SAX::Parser::process_node which was called 555897 times, avg 157µs/call:
# 545897 times (10.3s+-10.3s) by XML::LibXML::SAX::Parser::process_element at line 244, avg 0s/call
# 5000 times (135ms+87.3s) by XML::LibXML::SAX::Parser::generate at line 91, avg 17.5ms/call
# 5000 times (83.8ms+-83.8ms) by XML::LibXML::SAX::Parser::process_node at line 127, avg 0s/call | ||||
| 97 | 2228588 | 13.3s | my ($self, $node) = @_; | ||
| 98 | |||||
| 99 | local $self->{current_node} = $node; | ||||
| 100 | |||||
| 101 | 555897 | 1.50s | my $node_type = $node->nodeType(); # spent 1.50s making 555897 calls to XML::LibXML::Node::nodeType, avg 3µs/call | ||
| 102 | 921495 | 96.9s | if ($node_type == XML_COMMENT_NODE) { # spent 193s making 185299 calls to XML::LibXML::SAX::Parser::process_element, avg 1.04ms/call, recursion: max depth 2, sum of overlapping time 106s
# spent 8.44s making 365598 calls to XML::SAX::Base::characters, avg 23µs/call
# spent 1.30s making 365598 calls to XML::LibXML::Node::nodeValue, avg 4µs/call
# spent 79.3ms making 5000 calls to XML::LibXML::Node::childNodes, avg 16µ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) { | ||||
| 127 | 5000 | 0s | $self->process_node($kid); # spent 87.2s making 5000 calls to XML::LibXML::SAX::Parser::process_node, avg 17.4ms/call, recursion: max depth 1, sum of overlapping time 87.2s | ||
| 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 87.1s (31.9+55.2) within XML::LibXML::SAX::Parser::process_element which was called 185299 times, avg 470µs/call:
# 185299 times (31.9s+55.2s) by XML::LibXML::SAX::Parser::process_node at line 102, avg 470µs/call | ||||
| 152 | 6007676 | 41.1s | my ($self, $element) = @_; | ||
| 153 | |||||
| 154 | my $attribs = {}; | ||||
| 155 | 185299 | 420ms | my @ns_maps = $element->getNamespaces; # spent 420ms making 185299 calls to XML::LibXML::Node::getNamespaces, avg 2µs/call | ||
| 156 | |||||
| 157 | foreach my $ns (@ns_maps) { | ||||
| 158 | $self->start_prefix_mapping( | ||||
| 159 | { | ||||
| 160 | NamespaceURI => $ns->href, | ||||
| 161 | Prefix => ( defined $ns->localname ? $ns->localname : ''), | ||||
| 162 | } | ||||
| 163 | ); | ||||
| 164 | } | ||||
| 165 | |||||
| 166 | 185299 | 2.74s | foreach my $attr ($element->attributes) { # spent 2.74s making 185299 calls to XML::LibXML::Node::attributes, avg 15µs/call | ||
| 167 | my $key; | ||||
| 168 | # warn("Attr: $attr -> ", $attr->getName, " = ", $attr->getData, "\n"); | ||||
| 169 | # this isa dump thing... | ||||
| 170 | 294381 | 1.00s | if ($attr->isa('XML::LibXML::Namespace')) { # spent 1.00s making 294381 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. | ||||
| 173 | unless ( defined $attr->name ) { | ||||
| 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 { | ||||
| 185 | my $prefix = "xmlns"; | ||||
| 186 | my $localname = $attr->localname; | ||||
| 187 | my $key = "{http://www.w3.org/2000/xmlns/}"; | ||||
| 188 | my $name = "xmlns"; | ||||
| 189 | |||||
| 190 | if ( defined $localname ) { | ||||
| 191 | $key .= $localname; | ||||
| 192 | $name.= ":".$localname; | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | $attribs->{$key} = | ||||
| 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 { | ||||
| 206 | 294381 | 727ms | my $ns = $attr->namespaceURI; # spent 727ms making 294381 calls to XML::LibXML::Node::namespaceURI, avg 2µs/call | ||
| 207 | |||||
| 208 | $ns = '' unless defined $ns; | ||||
| 209 | 294381 | 820ms | $key = "{$ns}".$attr->localname; # spent 820ms making 294381 calls to XML::LibXML::Node::localname, avg 3µ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. | ||||
| 212 | 294381 | 758ms | my $name = $attr->name; # spent 758ms making 294381 calls to XML::LibXML::Attr::name, avg 3µs/call | ||
| 213 | $name = "" unless defined $name; | ||||
| 214 | |||||
| 215 | 294381 | 696ms | my $prefix = $attr->prefix; # spent 696ms making 294381 calls to XML::LibXML::Node::prefix, avg 2µs/call | ||
| 216 | $prefix = "" unless defined $prefix; | ||||
| 217 | $name = "$prefix:$name" | ||||
| 218 | if index( $name, ":" ) < 0 && length $prefix; | ||||
| 219 | |||||
| 220 | 588762 | 1.76s | $attribs->{$key} = # spent 1.01s making 294381 calls to XML::LibXML::Attr::value, avg 3µs/call
# spent 749ms making 294381 calls to XML::LibXML::Node::localname, avg 3µ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 | |||||
| 233 | 1035577 | 2.58s | my $node = { # spent 672ms making 294381 calls to XML::LibXML::Node::DESTROY, avg 2µs/call
# spent 621ms making 185299 calls to XML::LibXML::Node::nodeName, avg 3µs/call
# spent 465ms making 185299 calls to XML::LibXML::Node::localname, avg 3µs/call
# spent 416ms making 185299 calls to XML::LibXML::Node::namespaceURI, avg 2µs/call
# spent 403ms making 185299 calls to XML::LibXML::Node::prefix, avg 2µs/call | ||
| 234 | Name => $element->nodeName, | ||||
| 235 | Attributes => $attribs, | ||||
| 236 | NamespaceURI => $element->namespaceURI, | ||||
| 237 | Prefix => $element->prefix || "", | ||||
| 238 | LocalName => $element->localname, | ||||
| 239 | }; | ||||
| 240 | |||||
| 241 | 185299 | 5.36s | $self->start_element($node); # spent 5.36s making 185299 calls to XML::SAX::Base::start_element, avg 29µs/call | ||
| 242 | |||||
| 243 | 185299 | 3.15s | foreach my $child ($element->childNodes) { # spent 3.15s making 185299 calls to XML::LibXML::Node::childNodes, avg 17µs/call | ||
| 244 | 545897 | 0s | $self->process_node($child); # spent 128s making 545897 calls to XML::LibXML::SAX::Parser::process_node, avg 234µs/call, recursion: max depth 4, sum of overlapping time 128s | ||
| 245 | } | ||||
| 246 | |||||
| 247 | 545897 | 1.18s | my $end_node = { %$node }; # spent 1.18s making 545897 calls to XML::LibXML::Node::DESTROY, avg 2µs/call | ||
| 248 | |||||
| 249 | delete $end_node->{Attributes}; | ||||
| 250 | |||||
| 251 | 185299 | 12.5s | $self->end_element($end_node); # spent 12.5s making 185299 calls to XML::SAX::Base::end_element, avg 67µs/call | ||
| 252 | |||||
| 253 | foreach my $ns (@ns_maps) { | ||||
| 254 | $self->end_prefix_mapping( | ||||
| 255 | { | ||||
| 256 | NamespaceURI => $ns->href, | ||||
| 257 | Prefix => ( defined $ns->localname ? $ns->localname : ''), | ||||
| 258 | } | ||||
| 259 | ); | ||||
| 260 | } | ||||
| 261 | } | ||||
| 262 | |||||
| 263 | 1 | 6µs | 1; | ||
| 264 | |||||
| 265 | __END__ |