← Index
NYTProf Performance Profile   « block view • line view • sub view »
For conv.pl
  Run on Sun Nov 14 21:27:43 2010
Reported on Sun Nov 14 21:29:12 2010

Filename/usr/share/perl5/XML/SAX.pm
StatementsExecuted 303 statements in 4.04ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.54ms2.77msXML::SAX::::BEGIN@16XML::SAX::BEGIN@16
1111.89ms3.78msXML::SAX::::BEGIN@15XML::SAX::BEGIN@15
111956µs3.85msXML::SAX::::BEGIN@18XML::SAX::BEGIN@18
111926µs1.54msXML::SAX::::_parse_ini_fileXML::SAX::_parse_ini_file
111858µs987µsXML::SAX::::BEGIN@17XML::SAX::BEGIN@17
9331313µs313µsXML::SAX::::CORE:substXML::SAX::CORE:subst (opcode)
6821219µs219µsXML::SAX::::CORE:matchXML::SAX::CORE:match (opcode)
321182µs82µsXML::SAX::::CORE:readlineXML::SAX::CORE:readline (opcode)
11162µs1.95msXML::SAX::::load_parsersXML::SAX::load_parsers
11157µs57µsXML::SAX::::CORE:openXML::SAX::CORE:open (opcode)
11119µs25µsXML::SAX::::BEGIN@5XML::SAX::BEGIN@5
11116µs88µsXML::SAX::::BEGIN@20XML::SAX::BEGIN@20
11115µs1.97msXML::SAX::::parsersXML::SAX::parsers
11114µs82µsXML::SAX::::BEGIN@22XML::SAX::BEGIN@22
11113µs75µsXML::SAX::::BEGIN@23XML::SAX::BEGIN@23
11113µs107µsXML::SAX::::BEGIN@6XML::SAX::BEGIN@6
1118µs8µsXML::SAX::::BEGIN@10XML::SAX::BEGIN@10
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
0000s0sXML::SAX::::save_parsers_debianXML::SAX::save_parsers_debian
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# $Id: SAX.pm,v 1.29 2007/06/27 09:09:12 grant Exp $
2
3package XML::SAX;
4
5341µs231µs
# spent 25µs (19+6) within XML::SAX::BEGIN@5 which was called: # once (19µs+6µs) by MARC::File::SAX::BEGIN@10 at line 5
use strict;
# spent 25µs making 1 call to XML::SAX::BEGIN@5 # spent 6µs making 1 call to strict::import
6347µs2201µs
# spent 107µs (13+94) within XML::SAX::BEGIN@6 which was called: # once (13µs+94µs) by MARC::File::SAX::BEGIN@10 at line 6
use vars qw($VERSION @ISA @EXPORT_OK);
# spent 107µs making 1 call to XML::SAX::BEGIN@6 # spent 94µs making 1 call to vars::import
7
812µs$VERSION = '0.16';
9
10362µs18µs
# spent 8µs within XML::SAX::BEGIN@10 which was called: # once (8µs+0s) by MARC::File::SAX::BEGIN@10 at line 10
use Exporter ();
# spent 8µs making 1 call to XML::SAX::BEGIN@10
11110µs@ISA = ('Exporter');
12
1312µs@EXPORT_OK = qw(Namespaces Validation);
14
153229µs23.87ms
# spent 3.78ms (1.89+1.89) within XML::SAX::BEGIN@15 which was called: # once (1.89ms+1.89ms) by MARC::File::SAX::BEGIN@10 at line 15
use File::Basename qw(dirname);
# spent 3.78ms making 1 call to XML::SAX::BEGIN@15 # spent 90µs making 1 call to Exporter::import
163145µs12.77ms
# spent 2.77ms (2.54+229µs) within XML::SAX::BEGIN@16 which was called: # once (2.54ms+229µs) by MARC::File::SAX::BEGIN@10 at line 16
use File::Spec ();
# spent 2.77ms making 1 call to XML::SAX::BEGIN@16
173159µs21.08ms
# spent 987µs (858+129) within XML::SAX::BEGIN@17 which was called: # once (858µs+129µs) by MARC::File::SAX::BEGIN@10 at line 17
use Symbol qw(gensym);
# spent 987µs making 1 call to XML::SAX::BEGIN@17 # spent 98µs making 1 call to Exporter::import
183171µs13.85ms
# spent 3.85ms (956µs+2.89) within XML::SAX::BEGIN@18 which was called: # once (956µs+2.89ms) by MARC::File::SAX::BEGIN@10 at line 18
use XML::SAX::ParserFactory (); # loaded for simplicity
# spent 3.85ms making 1 call to XML::SAX::BEGIN@18
19
20345µs2160µs
# spent 88µs (16+72) within XML::SAX::BEGIN@20 which was called: # once (16µs+72µs) by MARC::File::SAX::BEGIN@10 at line 20
use constant PARSER_DETAILS => "ParserDetails.ini";
# spent 88µs making 1 call to XML::SAX::BEGIN@20 # spent 72µs making 1 call to constant::import
21
22343µs2150µs
# spent 82µs (14+68) within XML::SAX::BEGIN@22 which was called: # once (14µs+68µs) by MARC::File::SAX::BEGIN@10 at line 22
use constant Namespaces => "http://xml.org/sax/features/namespaces";
# spent 82µs making 1 call to XML::SAX::BEGIN@22 # spent 68µs making 1 call to constant::import
2331.39ms2137µs
# spent 75µs (13+62) within XML::SAX::BEGIN@23 which was called: # once (13µs+62µs) by MARC::File::SAX::BEGIN@10 at line 23
use constant Validation => "http://xml.org/sax/features/validation";
# spent 75µs making 1 call to XML::SAX::BEGIN@23 # spent 62µs making 1 call to constant::import
24
2511µsmy $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
- -
47
# spent 1.95ms (62µs+1.89) within XML::SAX::load_parsers which was called: # once (62µs+1.89ms) by XML::SAX::parsers at line 114
sub load_parsers {
4812µs my $class = shift;
4912µs my $dir = shift;
50
51 # reset parsers
5211µs $known_parsers = [];
53
54 # get directory from wherever XML::SAX is installed
5512µs if (!$dir) {
5612µs $dir = $INC{'XML/SAX.pm'};
5716µs1137µs $dir = dirname($dir);
# spent 137µs making 1 call to File::Basename::dirname
58 }
59
6016µs117µs my $fh = gensym();
# spent 17µs making 1 call to Symbol::gensym
61175µs2195µs if (!open($fh, File::Spec->catfile($dir, "SAX", PARSER_DETAILS))) {
# spent 138µs making 1 call to File::Spec::Unix::catfile # spent 57µs making 1 call to XML::SAX::CORE:open
62 XML::SAX->do_warn("could not find " . PARSER_DETAILS . " in $dir/SAX\n");
63 return $class;
64 }
65
6618µs11.54ms $known_parsers = $class->_parse_ini_file($fh);
# spent 1.54ms making 1 call to XML::SAX::_parse_ini_file
67
68112µs return $class;
69}
70
71
# spent 1.54ms (926µs+614µs) within XML::SAX::_parse_ini_file which was called: # once (926µs+614µs) by XML::SAX::load_parsers at line 66
sub _parse_ini_file {
7212µs my $class = shift;
7311µs my ($fh) = @_;
74
7512µs my @config;
76
7711µs my $lineno = 0;
781237µs3282µs while (defined(my $line = <$fh>)) {
# spent 82µs making 32 calls to XML::SAX::CORE:readline, avg 3µs/call
793128µs $lineno++;
803140µs my $original = $line;
81 # strip whitespace
8231344µs31222µs $line =~ s/\s*$//m;
# spent 222µs making 31 calls to XML::SAX::CORE:subst, avg 7µs/call
8331153µs3147µs $line =~ s/^\s*//m;
# spent 47µs making 31 calls to XML::SAX::CORE:subst, avg 2µs/call
84 # strip comments
8531143µs3144µs $line =~ s/[#;].*$//m;
# spent 44µs making 31 calls to XML::SAX::CORE:subst, avg 1µs/call
86 # ignore blanks
8731159µs3149µs next if $line =~ /^$/m;
# spent 49µs making 31 calls to XML::SAX::CORE:match, avg 2µs/call
88
89 # heading
9021301µs37170µs if ($line =~ /^\[\s*(.*)\s*\]$/m) {
# spent 170µs making 37 calls to XML::SAX::CORE:match, avg 5µs/call
91517µs push @config, { Name => $1 };
9259µs next;
93 }
94
95 # instruction
96 elsif ($line =~ /^(.*?)\s*?=\s*(.*)$/) {
971619µs unless(@config) {
98 push @config, { Name => '' };
99 }
1001673µ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
109114µs return \@config;
110}
111
112
# spent 1.97ms (15µs+1.95) within XML::SAX::parsers which was called: # once (15µs+1.95ms) by XML::SAX::ParserFactory::new at line 18 of XML/SAX/ParserFactory.pm
sub parsers {
11312µs my $class = shift;
11416µs11.95ms if (!$known_parsers) {
# spent 1.95ms making 1 call to XML::SAX::load_parsers
115 $class->load_parsers();
116 }
117111µ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 save_parsers_debian {
219 my $class = shift;
220 my ($parser_module,$directory, $priority) = @_;
221
222 # add parser
223 $known_parsers = [];
224 $class->add_parser($parser_module);
225
226 # get parser's ParserDetails file
227 my $file = $parser_module;
228 $file = "${priority}-$file" if $priority != 0;
229 $file = File::Spec->catfile($directory, $file);
230 chmod 0644, $file;
231 unlink($file);
232
233 my $fh = gensym();
234 open($fh, ">$file") ||
235 die "Cannot write to $file: $!";
236
237 foreach my $p (@$known_parsers) {
238 print $fh "[$p->{Name}]\n";
239 foreach my $key (keys %{$p->{Features}}) {
240 print $fh "$key = $p->{Features}{$key}\n";
241 }
242 print $fh "\n";
243 }
244
245 print $fh "\n";
246
247 close $fh;
248
249 return $class;
250}
251
252sub do_warn {
253 my $class = shift;
254 # Don't output warnings if running under Test::Harness
255 warn(@_) unless $ENV{HARNESS_ACTIVE};
256}
257
25818µs1;
259__END__
 
# spent 219µs within XML::SAX::CORE:match which was called 68 times, avg 3µs/call: # 37 times (170µs+0s) by XML::SAX::_parse_ini_file at line 90, avg 5µs/call # 31 times (49µs+0s) by XML::SAX::_parse_ini_file at line 87, avg 2µs/call
sub XML::SAX::CORE:match; # opcode
# spent 57µs within XML::SAX::CORE:open which was called: # once (57µs+0s) by XML::SAX::load_parsers at line 61
sub XML::SAX::CORE:open; # opcode
# spent 82µs within XML::SAX::CORE:readline which was called 32 times, avg 3µs/call: # 32 times (82µs+0s) by XML::SAX::_parse_ini_file at line 78, avg 3µs/call
sub XML::SAX::CORE:readline; # opcode
# spent 313µs within XML::SAX::CORE:subst which was called 93 times, avg 3µs/call: # 31 times (222µs+0s) by XML::SAX::_parse_ini_file at line 82, avg 7µs/call # 31 times (47µs+0s) by XML::SAX::_parse_ini_file at line 83, avg 2µs/call # 31 times (44µs+0s) by XML::SAX::_parse_ini_file at line 85, avg 1µs/call
sub XML::SAX::CORE:subst; # opcode