← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:47 2015

Filename/usr/share/perl5/XML/SAX.pm
StatementsExecuted 185 statements in 6.03ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.17ms4.29msXML::SAX::::_parse_ini_fileXML::SAX::_parse_ini_file
1111.20ms2.45msXML::SAX::::BEGIN@18XML::SAX::BEGIN@18
543159µs59µsXML::SAX::::CORE:substXML::SAX::CORE:subst (opcode)
342138µs38µsXML::SAX::::CORE:matchXML::SAX::CORE:match (opcode)
11131µs4.41msXML::SAX::::load_parsersXML::SAX::load_parsers
191120µs20µsXML::SAX::::CORE:readlineXML::SAX::CORE:readline (opcode)
11118µs18µsXML::SAX::::CORE:openXML::SAX::CORE:open (opcode)
11111µs23µsXML::SAX::::BEGIN@5XML::SAX::BEGIN@5
1119µs40µsXML::SAX::::BEGIN@15XML::SAX::BEGIN@15
1118µs35µsXML::SAX::::BEGIN@17XML::SAX::BEGIN@17
2118µs4.42msXML::SAX::::parsersXML::SAX::parsers
1116µs32µsXML::SAX::::BEGIN@20XML::SAX::BEGIN@20
1116µs39µsXML::SAX::::BEGIN@6XML::SAX::BEGIN@6
1116µs24µsXML::SAX::::BEGIN@23XML::SAX::BEGIN@23
1115µs25µsXML::SAX::::BEGIN@22XML::SAX::BEGIN@22
1113µs3µsXML::SAX::::BEGIN@10XML::SAX::BEGIN@10
1113µs3µsXML::SAX::::BEGIN@16XML::SAX::BEGIN@16
0000s0sXML::SAX::::_is_vendor_suppliedXML::SAX::_is_vendor_supplied
0000s0sXML::SAX::::add_parserXML::SAX::add_parser
0000s0sXML::SAX::::do_warnXML::SAX::do_warn
0000s0sXML::SAX::::remove_parserXML::SAX::remove_parser
0000s0sXML::SAX::::save_parsersXML::SAX::save_parsers
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# $Id$
2
3package XML::SAX;
4
5229µs234µs
# spent 23µs (11+11) within XML::SAX::BEGIN@5 which was called: # once (11µs+11µs) by XML::Simple::build_tree at line 5
use strict;
# spent 23µs making 1 call to XML::SAX::BEGIN@5 # spent 11µs making 1 call to strict::import
6227µs272µs
# spent 39µs (6+33) within XML::SAX::BEGIN@6 which was called: # once (6µs+33µs) by XML::Simple::build_tree at line 6
use vars qw($VERSION @ISA @EXPORT_OK);
# spent 39µs making 1 call to XML::SAX::BEGIN@6 # spent 33µs making 1 call to vars::import
7
81300ns$VERSION = '0.99';
9
10234µs13µs
# spent 3µs within XML::SAX::BEGIN@10 which was called: # once (3µs+0s) by XML::Simple::build_tree at line 10
use Exporter ();
# spent 3µs making 1 call to XML::SAX::BEGIN@10
1116µs@ISA = ('Exporter');
12
131600ns@EXPORT_OK = qw(Namespaces Validation);
14
15223µs272µs
# spent 40µs (9+31) within XML::SAX::BEGIN@15 which was called: # once (9µs+31µs) by XML::Simple::build_tree at line 15
use File::Basename qw(dirname);
# spent 40µs making 1 call to XML::SAX::BEGIN@15 # spent 31µs making 1 call to Exporter::import
16219µs13µs
# spent 3µs within XML::SAX::BEGIN@16 which was called: # once (3µs+0s) by XML::Simple::build_tree at line 16
use File::Spec ();
# spent 3µs making 1 call to XML::SAX::BEGIN@16
17226µs263µs
# spent 35µs (8+27) within XML::SAX::BEGIN@17 which was called: # once (8µs+27µs) by XML::Simple::build_tree at line 17
use Symbol qw(gensym);
# spent 35µs making 1 call to XML::SAX::BEGIN@17 # spent 28µs making 1 call to Exporter::import
182744µs12.45ms
# spent 2.45ms (1.20+1.25) within XML::SAX::BEGIN@18 which was called: # once (1.20ms+1.25ms) by XML::Simple::build_tree at line 18
use XML::SAX::ParserFactory (); # loaded for simplicity
# spent 2.45ms making 1 call to XML::SAX::BEGIN@18
19
20224µs258µs
# spent 32µs (6+26) within XML::SAX::BEGIN@20 which was called: # once (6µs+26µs) by XML::Simple::build_tree at line 20
use constant PARSER_DETAILS => "ParserDetails.ini";
# spent 32µs making 1 call to XML::SAX::BEGIN@20 # spent 26µs making 1 call to constant::import
21
22222µs245µs
# spent 25µs (5+20) within XML::SAX::BEGIN@22 which was called: # once (5µs+20µs) by XML::Simple::build_tree at line 22
use constant Namespaces => "http://xml.org/sax/features/namespaces";
# spent 25µs making 1 call to XML::SAX::BEGIN@22 # spent 20µs making 1 call to constant::import
232695µs243µs
# spent 24µs (6+18) within XML::SAX::BEGIN@23 which was called: # once (6µs+18µs) by XML::Simple::build_tree at line 23
use constant Validation => "http://xml.org/sax/features/validation";
# spent 24µs making 1 call to XML::SAX::BEGIN@23 # spent 18µs making 1 call to constant::import
24
251200nsmy $known_parsers = undef;
26
27# load_parsers takes the ParserDetails.ini file out of the same directory
28# that XML::SAX is in, and looks at it. Format in POD below
29
30=begin EXAMPLE
31
32[XML::SAX::PurePerl]
33http://xml.org/sax/features/namespaces = 1
34http://xml.org/sax/features/validation = 0
35# a comment
36
37# blank lines ignored
38
39[XML::SAX::AnotherParser]
40http://xml.org/sax/features/namespaces = 0
41http://xml.org/sax/features/validation = 1
42
43=end EXAMPLE
44
45=cut
46
47
# spent 4.41ms (31µs+4.38) within XML::SAX::load_parsers which was called: # once (31µs+4.38ms) by XML::SAX::parsers at line 114
sub load_parsers {
481100ns my $class = shift;
491100ns my $dir = shift;
50
51 # reset parsers
521400ns $known_parsers = [];
53
54 # get directory from wherever XML::SAX is installed
551400ns if (!$dir) {
561400ns $dir = $INC{'XML/SAX.pm'};
5711µs137µs $dir = dirname($dir);
# spent 37µs making 1 call to File::Basename::dirname
58 }
59
6012µs17µs my $fh = gensym();
# spent 7µs making 1 call to Symbol::gensym
61158µs561µs if (!open($fh, File::Spec->catfile($dir, "SAX", PARSER_DETAILS))) {
# spent 30µs making 1 call to File::Spec::Unix::catfile # spent 18µs making 1 call to XML::SAX::CORE:open # spent 7µs making 2 calls to File::Spec::Unix::canonpath, avg 3µs/call # spent 7µs making 1 call to File::Spec::Unix::catdir
62 XML::SAX->do_warn("could not find " . PARSER_DETAILS . " in $dir/SAX\n");
63 return $class;
64 }
65
6613µs14.29ms $known_parsers = $class->_parse_ini_file($fh);
# spent 4.29ms making 1 call to XML::SAX::_parse_ini_file
67
68113µs return $class;
69}
70
71
# spent 4.29ms (4.17+117µs) within XML::SAX::_parse_ini_file which was called: # once (4.17ms+117µs) by XML::SAX::load_parsers at line 66
sub _parse_ini_file {
721400ns my $class = shift;
731300ns my ($fh) = @_;
74
751100ns my @config;
76
771200ns my $lineno = 0;
78142µs1920µs while (defined(my $line = <$fh>)) {
# spent 20µs making 19 calls to XML::SAX::CORE:readline, avg 1µs/call
79181µs $lineno++;
80184µs my $original = $line;
81 # strip whitespace
821863µs1841µs $line =~ s/\s*$//m;
# spent 41µs making 18 calls to XML::SAX::CORE:subst, avg 2µs/call
831831µs1814µs $line =~ s/^\s*//m;
# spent 14µs making 18 calls to XML::SAX::CORE:subst, avg 800ns/call
84 # strip comments
851817µs184µs $line =~ s/[#;].*$//m;
# spent 4µs making 18 calls to XML::SAX::CORE:subst, avg 217ns/call
86 # ignore blanks
87184.06ms186µs next if $line =~ /^$/m;
# spent 6µs making 18 calls to XML::SAX::CORE:match, avg 356ns/call
88
89 # heading
901050µs1631µs if ($line =~ /^\[\s*(.*)\s*\]$/m) {
# spent 31µs making 16 calls to XML::SAX::CORE:match, avg 2µs/call
9146µs push @config, { Name => $1 };
9242µs next;
93 }
94
95 # instruction
96 elsif ($line =~ /^(.*?)\s*?=\s*(.*)$/) {
9762µs unless(@config) {
98 push @config, { Name => '' };
99 }
100611µs $config[-1]{Features}{$1} = $2;
101 }
102
103 # not whitespace, comment, or instruction
104 else {
105 die "Invalid line in ini: $lineno\n>>> $original\n";
106 }
107 }
108
10914µs return \@config;
110}
111
112
# spent 4.42ms (8µs+4.41) within XML::SAX::parsers which was called 2 times, avg 2.21ms/call: # 2 times (8µs+4.41ms) by XML::SAX::ParserFactory::new at line 18 of XML/SAX/ParserFactory.pm, avg 2.21ms/call
sub parsers {
1132400ns my $class = shift;
11421µs14.41ms if (!$known_parsers) {
# spent 4.41ms making 1 call to XML::SAX::load_parsers
115 $class->load_parsers();
116 }
11725µs return $known_parsers;
118}
119
120sub remove_parser {
121 my $class = shift;
122 my ($parser_module) = @_;
123
124 if (!$known_parsers) {
125 $class->load_parsers();
126 }
127
128 @$known_parsers = grep { $_->{Name} ne $parser_module } @$known_parsers;
129
130 return $class;
131}
132
133sub add_parser {
134 my $class = shift;
135 my ($parser_module) = @_;
136
137 if (!$known_parsers) {
138 $class->load_parsers();
139 }
140
141 # first load module, then query features, then push onto known_parsers,
142
143 my $parser_file = $parser_module;
144 $parser_file =~ s/::/\//g;
145 $parser_file .= ".pm";
146
147 require $parser_file;
148
149 my @features = $parser_module->supported_features();
150
151 my $new = { Name => $parser_module };
152 foreach my $feature (@features) {
153 $new->{Features}{$feature} = 1;
154 }
155
156 # If exists in list already, move to end.
157 my $done = 0;
158 my $pos = undef;
159 for (my $i = 0; $i < @$known_parsers; $i++) {
160 my $p = $known_parsers->[$i];
161 if ($p->{Name} eq $parser_module) {
162 $pos = $i;
163 }
164 }
165 if (defined $pos) {
166 splice(@$known_parsers, $pos, 1);
167 push @$known_parsers, $new;
168 $done++;
169 }
170
171 # Otherwise (not in list), add at end of list.
172 if (!$done) {
173 push @$known_parsers, $new;
174 }
175
176 return $class;
177}
178
179sub save_parsers {
180 my $class = shift;
181
182 ### DEBIAN MODIFICATION
183 print "\n";
184 print "Please use 'update-perl-sax-parsers(8) to register this parser.'\n";
185 print "See /usr/share/doc/libxml-sax-perl/README.Debian.gz for more info.\n";
186 print "\n";
187
188 return $class; # rest of the function is disabled on Debian.
189 ### END DEBIAN MODIFICATION
190
191 # get directory from wherever XML::SAX is installed
192 my $dir = $INC{'XML/SAX.pm'};
193 $dir = dirname($dir);
194
195 my $file = File::Spec->catfile($dir, "SAX", PARSER_DETAILS);
196 chmod 0644, $file;
197 unlink($file);
198
199 my $fh = gensym();
200 open($fh, ">$file") ||
201 die "Cannot write to $file: $!";
202
203 foreach my $p (@$known_parsers) {
204 print $fh "[$p->{Name}]\n";
205 foreach my $key (keys %{$p->{Features}}) {
206 print $fh "$key = $p->{Features}{$key}\n";
207 }
208 print $fh "\n";
209 }
210
211 print $fh "\n";
212
213 close $fh;
214
215 return $class;
216}
217
218sub do_warn {
219 my $class = shift;
220 # Don't output warnings if running under Test::Harness
221 warn(@_) unless $ENV{HARNESS_ACTIVE};
222}
223
224sub _is_vendor_supplied {
225 1;
226}
227
22813µs1;
229__END__
 
# spent 38µs within XML::SAX::CORE:match which was called 34 times, avg 1µs/call: # 18 times (6µs+0s) by XML::SAX::_parse_ini_file at line 87, avg 356ns/call # 16 times (31µs+0s) by XML::SAX::_parse_ini_file at line 90, avg 2µs/call
sub XML::SAX::CORE:match; # opcode
# spent 18µs within XML::SAX::CORE:open which was called: # once (18µs+0s) by XML::SAX::load_parsers at line 61
sub XML::SAX::CORE:open; # opcode
# spent 20µs within XML::SAX::CORE:readline which was called 19 times, avg 1µs/call: # 19 times (20µs+0s) by XML::SAX::_parse_ini_file at line 78, avg 1µs/call
sub XML::SAX::CORE:readline; # opcode
# spent 59µs within XML::SAX::CORE:subst which was called 54 times, avg 1µs/call: # 18 times (41µs+0s) by XML::SAX::_parse_ini_file at line 82, avg 2µs/call # 18 times (14µs+0s) by XML::SAX::_parse_ini_file at line 83, avg 800ns/call # 18 times (4µs+0s) by XML::SAX::_parse_ini_file at line 85, avg 217ns/call
sub XML::SAX::CORE:subst; # opcode