Filename | /usr/share/perl/5.36/diagnostics.pm |
Statements | Executed 64227 statements in 161ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
20563 | 15 | 1 | 25.8ms | 25.8ms | CORE:subst (opcode) | diagnostics::
955 | 1 | 1 | 18.2ms | 19.9ms | bold | diagnostics::
14119 | 6 | 1 | 6.59ms | 6.59ms | CORE:substcont (opcode) | diagnostics::
2499 | 2 | 1 | 3.64ms | 3.64ms | CORE:readline (opcode) | diagnostics::
423 | 2 | 1 | 3.22ms | 4.18ms | italic | diagnostics::
1 | 1 | 1 | 3.22ms | 3.80ms | BEGIN@186 | diagnostics::
2498 | 1 | 1 | 1.96ms | 2.31ms | unescape | diagnostics::
1 | 1 | 1 | 1.29ms | 1.29ms | CORE:sort (opcode) | diagnostics::
4557 | 7 | 1 | 1.04ms | 1.04ms | CORE:match (opcode) | diagnostics::
280 | 1 | 1 | 426µs | 742µs | _split_pod_link | diagnostics::
1 | 1 | 1 | 420µs | 464µs | BEGIN@196 | diagnostics::
1 | 1 | 1 | 372µs | 422µs | BEGIN@197 | diagnostics::
3 | 3 | 3 | 24µs | 28µs | import | diagnostics::
3 | 1 | 1 | 20µs | 20µs | death_trap | diagnostics::
1 | 1 | 1 | 12µs | 12µs | CORE:open (opcode) | diagnostics::
3 | 2 | 1 | 10µs | 10µs | CORE:ftis (opcode) | diagnostics::
1 | 1 | 1 | 8µs | 8µs | CORE:eof (opcode) | diagnostics::
1 | 1 | 1 | 8µs | 9µs | BEGIN@184 | diagnostics::
1 | 1 | 1 | 6µs | 6µs | CORE:close (opcode) | diagnostics::
1 | 1 | 1 | 5µs | 5µs | BEGIN@185 | diagnostics::
0 | 0 | 0 | 0s | 0s | autodescribe | diagnostics::
0 | 0 | 0 | 0s | 0s | disable | diagnostics::
0 | 0 | 0 | 0s | 0s | enable | diagnostics::
0 | 0 | 0 | 0s | 0s | noop | diagnostics::
0 | 0 | 0 | 0s | 0s | shorten | diagnostics::
0 | 0 | 0 | 0s | 0s | splainthis | diagnostics::
0 | 0 | 0 | 0s | 0s | warn_trap | diagnostics::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package diagnostics; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
5 | diagnostics, splain - produce verbose warning diagnostics | ||||
6 | |||||
7 | =head1 SYNOPSIS | ||||
8 | |||||
9 | Using the C<diagnostics> pragma: | ||||
10 | |||||
11 | use diagnostics; | ||||
12 | use diagnostics -verbose; | ||||
13 | |||||
14 | enable diagnostics; | ||||
15 | disable diagnostics; | ||||
16 | |||||
17 | Using the C<splain> standalone filter program: | ||||
18 | |||||
19 | perl program 2>diag.out | ||||
20 | splain [-v] [-p] diag.out | ||||
21 | |||||
22 | Using diagnostics to get stack traces from a misbehaving script: | ||||
23 | |||||
24 | perl -Mdiagnostics=-traceonly my_script.pl | ||||
25 | |||||
26 | =head1 DESCRIPTION | ||||
27 | |||||
28 | =head2 The C<diagnostics> Pragma | ||||
29 | |||||
30 | This module extends the terse diagnostics normally emitted by both the | ||||
31 | perl compiler and the perl interpreter (from running perl with a -w | ||||
32 | switch or C<use warnings>), augmenting them with the more | ||||
33 | explicative and endearing descriptions found in L<perldiag>. Like the | ||||
34 | other pragmata, it affects the compilation phase of your program rather | ||||
35 | than merely the execution phase. | ||||
36 | |||||
37 | To use in your program as a pragma, merely invoke | ||||
38 | |||||
39 | use diagnostics; | ||||
40 | |||||
41 | at the start (or near the start) of your program. (Note | ||||
42 | that this I<does> enable perl's B<-w> flag.) Your whole | ||||
43 | compilation will then be subject(ed :-) to the enhanced diagnostics. | ||||
44 | These still go out B<STDERR>. | ||||
45 | |||||
46 | Due to the interaction between runtime and compiletime issues, | ||||
47 | and because it's probably not a very good idea anyway, | ||||
48 | you may not use C<no diagnostics> to turn them off at compiletime. | ||||
49 | However, you may control their behaviour at runtime using the | ||||
50 | disable() and enable() methods to turn them off and on respectively. | ||||
51 | |||||
52 | The B<-verbose> flag first prints out the L<perldiag> introduction before | ||||
53 | any other diagnostics. The $diagnostics::PRETTY variable can generate nicer | ||||
54 | escape sequences for pagers. | ||||
55 | |||||
56 | Warnings dispatched from perl itself (or more accurately, those that match | ||||
57 | descriptions found in L<perldiag>) are only displayed once (no duplicate | ||||
58 | descriptions). User code generated warnings a la warn() are unaffected, | ||||
59 | allowing duplicate user messages to be displayed. | ||||
60 | |||||
61 | This module also adds a stack trace to the error message when perl dies. | ||||
62 | This is useful for pinpointing what | ||||
63 | caused the death. The B<-traceonly> (or | ||||
64 | just B<-t>) flag turns off the explanations of warning messages leaving just | ||||
65 | the stack traces. So if your script is dieing, run it again with | ||||
66 | |||||
67 | perl -Mdiagnostics=-traceonly my_bad_script | ||||
68 | |||||
69 | to see the call stack at the time of death. By supplying the B<-warntrace> | ||||
70 | (or just B<-w>) flag, any warnings emitted will also come with a stack | ||||
71 | trace. | ||||
72 | |||||
73 | =head2 The I<splain> Program | ||||
74 | |||||
75 | Another program, I<splain> is actually nothing | ||||
76 | more than a link to the (executable) F<diagnostics.pm> module, as well as | ||||
77 | a link to the F<diagnostics.pod> documentation. The B<-v> flag is like | ||||
78 | the C<use diagnostics -verbose> directive. | ||||
79 | The B<-p> flag is like the | ||||
80 | $diagnostics::PRETTY variable. Since you're post-processing with | ||||
81 | I<splain>, there's no sense in being able to enable() or disable() processing. | ||||
82 | |||||
83 | Output from I<splain> is directed to B<STDOUT>, unlike the pragma. | ||||
84 | |||||
85 | =head1 EXAMPLES | ||||
86 | |||||
87 | The following file is certain to trigger a few errors at both | ||||
88 | runtime and compiletime: | ||||
89 | |||||
90 | use diagnostics; | ||||
91 | print NOWHERE "nothing\n"; | ||||
92 | print STDERR "\n\tThis message should be unadorned.\n"; | ||||
93 | warn "\tThis is a user warning"; | ||||
94 | print "\nDIAGNOSTIC TESTER: Please enter a <CR> here: "; | ||||
95 | my $a, $b = scalar <STDIN>; | ||||
96 | print "\n"; | ||||
97 | print $x/$y; | ||||
98 | |||||
99 | If you prefer to run your program first and look at its problem | ||||
100 | afterwards, do this: | ||||
101 | |||||
102 | perl -w test.pl 2>test.out | ||||
103 | ./splain < test.out | ||||
104 | |||||
105 | Note that this is not in general possible in shells of more dubious heritage, | ||||
106 | as the theoretical | ||||
107 | |||||
108 | (perl -w test.pl >/dev/tty) >& test.out | ||||
109 | ./splain < test.out | ||||
110 | |||||
111 | Because you just moved the existing B<stdout> to somewhere else. | ||||
112 | |||||
113 | If you don't want to modify your source code, but still have on-the-fly | ||||
114 | warnings, do this: | ||||
115 | |||||
116 | exec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&- | ||||
117 | |||||
118 | Nifty, eh? | ||||
119 | |||||
120 | If you want to control warnings on the fly, do something like this. | ||||
121 | Make sure you do the C<use> first, or you won't be able to get | ||||
122 | at the enable() or disable() methods. | ||||
123 | |||||
124 | use diagnostics; # checks entire compilation phase | ||||
125 | print "\ntime for 1st bogus diags: SQUAWKINGS\n"; | ||||
126 | print BOGUS1 'nada'; | ||||
127 | print "done with 1st bogus\n"; | ||||
128 | |||||
129 | disable diagnostics; # only turns off runtime warnings | ||||
130 | print "\ntime for 2nd bogus: (squelched)\n"; | ||||
131 | print BOGUS2 'nada'; | ||||
132 | print "done with 2nd bogus\n"; | ||||
133 | |||||
134 | enable diagnostics; # turns back on runtime warnings | ||||
135 | print "\ntime for 3rd bogus: SQUAWKINGS\n"; | ||||
136 | print BOGUS3 'nada'; | ||||
137 | print "done with 3rd bogus\n"; | ||||
138 | |||||
139 | disable diagnostics; | ||||
140 | print "\ntime for 4th bogus: (squelched)\n"; | ||||
141 | print BOGUS4 'nada'; | ||||
142 | print "done with 4th bogus\n"; | ||||
143 | |||||
144 | =head1 INTERNALS | ||||
145 | |||||
146 | Diagnostic messages derive from the F<perldiag.pod> file when available at | ||||
147 | runtime. Otherwise, they may be embedded in the file itself when the | ||||
148 | splain package is built. See the F<Makefile> for details. | ||||
149 | |||||
150 | If an extant $SIG{__WARN__} handler is discovered, it will continue | ||||
151 | to be honored, but only after the diagnostics::splainthis() function | ||||
152 | (the module's $SIG{__WARN__} interceptor) has had its way with your | ||||
153 | warnings. | ||||
154 | |||||
155 | There is a $diagnostics::DEBUG variable you may set if you're desperately | ||||
156 | curious what sorts of things are being intercepted. | ||||
157 | |||||
158 | BEGIN { $diagnostics::DEBUG = 1 } | ||||
159 | |||||
160 | |||||
161 | =head1 BUGS | ||||
162 | |||||
163 | Not being able to say "no diagnostics" is annoying, but may not be | ||||
164 | insurmountable. | ||||
165 | |||||
166 | The C<-pretty> directive is called too late to affect matters. | ||||
167 | You have to do this instead, and I<before> you load the module. | ||||
168 | |||||
169 | BEGIN { $diagnostics::PRETTY = 1 } | ||||
170 | |||||
171 | I could start up faster by delaying compilation until it should be | ||||
172 | needed, but this gets a "panic: top_level" when using the pragma form | ||||
173 | in Perl 5.001e. | ||||
174 | |||||
175 | While it's true that this documentation is somewhat subserious, if you use | ||||
176 | a program named I<splain>, you should expect a bit of whimsy. | ||||
177 | |||||
178 | =head1 AUTHOR | ||||
179 | |||||
180 | Tom Christiansen <F<tchrist@mox.perl.com>>, 25 June 1995. | ||||
181 | |||||
182 | =cut | ||||
183 | |||||
184 | 2 | 17µs | 2 | 11µs | # spent 9µs (8+1) within diagnostics::BEGIN@184 which was called:
# once (8µs+1µs) by main::BEGIN@8 at line 184 # spent 9µs making 1 call to diagnostics::BEGIN@184
# spent 2µs making 1 call to strict::import |
185 | 2 | 24µs | 1 | 5µs | # spent 5µs within diagnostics::BEGIN@185 which was called:
# once (5µs+0s) by main::BEGIN@8 at line 185 # spent 5µs making 1 call to diagnostics::BEGIN@185 |
186 | 2 | 127µs | 2 | 3.83ms | # spent 3.80ms (3.22+583µs) within diagnostics::BEGIN@186 which was called:
# once (3.22ms+583µs) by main::BEGIN@8 at line 186 # spent 3.80ms making 1 call to diagnostics::BEGIN@186
# spent 26µs making 1 call to Exporter::import |
187 | 1 | 800ns | $Carp::Internal{__PACKAGE__.""}++; | ||
188 | |||||
189 | 1 | 200ns | our $VERSION = '1.39'; | ||
190 | our $DEBUG; | ||||
191 | our $VERBOSE; | ||||
192 | our $PRETTY; | ||||
193 | 1 | 100ns | our $TRACEONLY = 0; | ||
194 | 1 | 100ns | our $WARNTRACE = 0; | ||
195 | |||||
196 | 2 | 85µs | 2 | 471µs | # spent 464µs (420+44) within diagnostics::BEGIN@196 which was called:
# once (420µs+44µs) by main::BEGIN@8 at line 196 # spent 464µs making 1 call to diagnostics::BEGIN@196
# spent 6µs making 1 call to Config::import |
197 | 2 | 2.16ms | 2 | 447µs | # spent 422µs (372+50) within diagnostics::BEGIN@197 which was called:
# once (372µs+50µs) by main::BEGIN@8 at line 197 # spent 422µs making 1 call to diagnostics::BEGIN@197
# spent 25µs making 1 call to Exporter::import |
198 | 1 | 6µs | 1 | 3µs | my $privlib = $Config{privlibexp}; # spent 3µs making 1 call to Config::FETCH |
199 | 1 | 800ns | if ($^O eq 'VMS') { | ||
200 | require VMS::Filespec; | ||||
201 | $privlib = VMS::Filespec::unixify($privlib); | ||||
202 | } | ||||
203 | 1 | 900ns | my @trypod = ( | ||
204 | "$privlib/pod/perldiag.pod", | ||||
205 | "$privlib/pods/perldiag.pod", | ||||
206 | ); | ||||
207 | # handy for development testing of new warnings etc | ||||
208 | 1 | 6µs | 1 | 4µs | unshift @trypod, "./pod/perldiag.pod" if -e "pod/perldiag.pod"; # spent 4µs making 1 call to diagnostics::CORE:ftis |
209 | 1 | 9µs | 2 | 6µs | (my $PODFILE) = ((grep { -e } @trypod), $trypod[$#trypod])[0]; # spent 6µs making 2 calls to diagnostics::CORE:ftis, avg 3µs/call |
210 | |||||
211 | 1 | 300ns | $DEBUG ||= 0; | ||
212 | |||||
213 | 1 | 2µs | local $| = 1; | ||
214 | 1 | 100ns | local $_; | ||
215 | 1 | 1µs | local $.; | ||
216 | |||||
217 | 1 | 100ns | my $standalone; | ||
218 | 1 | 100ns | my(%HTML_2_Troff, %HTML_2_Latin_1, %HTML_2_ASCII_7); | ||
219 | |||||
220 | CONFIG: { | ||||
221 | 2 | 400ns | our $opt_p = our $opt_d = our $opt_v = our $opt_f = ''; | ||
222 | |||||
223 | 1 | 400ns | unless (caller) { | ||
224 | $standalone++; | ||||
225 | require Getopt::Std; | ||||
226 | Getopt::Std::getopts('pdvf:') | ||||
227 | or die "Usage: $0 [-v] [-p] [-f splainpod]"; | ||||
228 | $PODFILE = $opt_f if $opt_f; | ||||
229 | $DEBUG = 2 if $opt_d; | ||||
230 | $VERBOSE = $opt_v; | ||||
231 | $PRETTY = $opt_p; | ||||
232 | } | ||||
233 | |||||
234 | 1 | 14µs | 1 | 12µs | if (open(POD_DIAG, '<', $PODFILE)) { # spent 12µs making 1 call to diagnostics::CORE:open |
235 | 1 | 100ns | warn "Happy happy podfile from real $PODFILE\n" if $DEBUG; | ||
236 | 1 | 700ns | last CONFIG; | ||
237 | } | ||||
238 | |||||
239 | if (caller) { | ||||
240 | INCPATH: { | ||||
241 | for my $file ( (map { "$_/".__PACKAGE__.".pm" } @INC), $0) { | ||||
242 | warn "Checking $file\n" if $DEBUG; | ||||
243 | if (open(POD_DIAG, '<', $file)) { | ||||
244 | while (<POD_DIAG>) { | ||||
245 | next unless | ||||
246 | /^__END__\s*# wish diag dbase were more accessible/; | ||||
247 | print STDERR "podfile is $file\n" if $DEBUG; | ||||
248 | last INCPATH; | ||||
249 | } | ||||
250 | } | ||||
251 | } | ||||
252 | } | ||||
253 | } else { | ||||
254 | print STDERR "podfile is <DATA>\n" if $DEBUG; | ||||
255 | *POD_DIAG = *main::DATA; | ||||
256 | } | ||||
257 | } | ||||
258 | 1 | 10µs | 1 | 8µs | if (eof(POD_DIAG)) { # spent 8µs making 1 call to diagnostics::CORE:eof |
259 | die "couldn't find diagnostic data in $PODFILE @INC $0"; | ||||
260 | } | ||||
261 | |||||
262 | |||||
263 | %HTML_2_Troff = ( | ||||
264 | 1 | 2µs | 'amp' => '&', # ampersand | ||
265 | 'lt' => '<', # left chevron, less-than | ||||
266 | 'gt' => '>', # right chevron, greater-than | ||||
267 | 'quot' => '"', # double quote | ||||
268 | 'sol' => '/', # forward slash / solidus | ||||
269 | 'verbar' => '|', # vertical bar | ||||
270 | |||||
271 | "Aacute" => "A\\*'", # capital A, acute accent | ||||
272 | # etc | ||||
273 | |||||
274 | ); | ||||
275 | |||||
276 | 1 | 1µs | %HTML_2_Latin_1 = ( | ||
277 | 'amp' => '&', # ampersand | ||||
278 | 'lt' => '<', # left chevron, less-than | ||||
279 | 'gt' => '>', # right chevron, greater-than | ||||
280 | 'quot' => '"', # double quote | ||||
281 | 'sol' => '/', # Forward slash / solidus | ||||
282 | 'verbar' => '|', # vertical bar | ||||
283 | |||||
284 | # # capital A, acute accent | ||||
285 | "Aacute" => chr utf8::unicode_to_native(0xC1) | ||||
286 | |||||
287 | # etc | ||||
288 | ); | ||||
289 | |||||
290 | 1 | 1µs | %HTML_2_ASCII_7 = ( | ||
291 | 'amp' => '&', # ampersand | ||||
292 | 'lt' => '<', # left chevron, less-than | ||||
293 | 'gt' => '>', # right chevron, greater-than | ||||
294 | 'quot' => '"', # double quote | ||||
295 | 'sol' => '/', # Forward slash / solidus | ||||
296 | 'verbar' => '|', # vertical bar | ||||
297 | |||||
298 | "Aacute" => "A" # capital A, acute accent | ||||
299 | # etc | ||||
300 | ); | ||||
301 | |||||
302 | our %HTML_Escapes; | ||||
303 | 1 | 800ns | *HTML_Escapes = do { | ||
304 | if ($standalone) { | ||||
305 | $PRETTY ? \%HTML_2_Latin_1 : \%HTML_2_ASCII_7; | ||||
306 | } else { | ||||
307 | 1 | 300ns | \%HTML_2_Latin_1; | ||
308 | } | ||||
309 | }; | ||||
310 | |||||
311 | 1 | 800ns | *THITHER = $standalone ? *STDOUT : *STDERR; | ||
312 | |||||
313 | 1 | 200ns | my %transfmt = (); | ||
314 | 1 | 200ns | my $transmo = <<EOFUNC; | ||
315 | sub transmo { | ||||
316 | #local \$^W = 0; # recursive warnings we do NOT need! | ||||
317 | EOFUNC | ||||
318 | |||||
319 | 1 | 100ns | my %msg; | ||
320 | 1 | 100ns | my $over_level = 0; # We look only at =item lines at the first =over level | ||
321 | { | ||||
322 | 2 | 200ns | print STDERR "FINISHING COMPILATION for $_\n" if $DEBUG; | ||
323 | 1 | 1µs | local $/ = ''; | ||
324 | 1 | 100ns | local $_; | ||
325 | 1 | 100ns | my $header; | ||
326 | my @headers; | ||||
327 | my $for_item; | ||||
328 | my $seen_body; | ||||
329 | 1 | 1.92ms | 1461 | 975µs | while (<POD_DIAG>) { # spent 975µs making 1461 calls to diagnostics::CORE:readline, avg 667ns/call |
330 | |||||
331 | # spent 742µs (426+316) within diagnostics::_split_pod_link which was called 280 times, avg 3µs/call:
# 280 times (426µs+316µs) by main::BEGIN@8 at line 344, avg 3µs/call | ||||
332 | 280 | 494µs | 280 | 316µs | $_[0] =~ m'(?:([^|]*)\|)?([^/]*)(?:/("?)(.*)\3)?'s; # spent 316µs making 280 calls to diagnostics::CORE:match, avg 1µs/call |
333 | 280 | 2.69ms | ($1,$2,$4); | ||
334 | } | ||||
335 | |||||
336 | 2498 | 894µs | 2498 | 2.31ms | unescape(); # spent 2.31ms making 2498 calls to diagnostics::unescape, avg 924ns/call |
337 | 2498 | 370µs | if ($PRETTY) { | ||
338 | sub noop { return $_[0] } # spensive for a noop | ||||
339 | 2865 | 20.2ms | 8734 | 1.73ms | # spent 19.9ms (18.2+1.73) within diagnostics::bold which was called 955 times, avg 21µs/call:
# 955 times (18.2ms+1.73ms) by main::BEGIN@8 at line 341, avg 21µs/call # spent 1.49ms making 7779 calls to diagnostics::CORE:substcont, avg 191ns/call
# spent 248µs making 955 calls to diagnostics::CORE:subst, avg 259ns/call |
340 | 1269 | 4.31ms | 4705 | 957µs | sub italic { my $str = $_[0]; $str =~ s/(.)/_\b$1/g; return $str; } # spent 827µs making 4282 calls to diagnostics::CORE:substcont, avg 193ns/call
# spent 130µs making 423 calls to diagnostics::CORE:subst, avg 308ns/call |
341 | 3453 | 19.0ms | 4880 | 36.3ms | s/C<<< (.*?) >>>|C<< (.*?) >>|[BC]<(.*?)>/bold($+)/ges; # spent 19.9ms making 955 calls to diagnostics::bold, avg 21µs/call
# spent 12.4ms making 2498 calls to diagnostics::CORE:subst, avg 5µs/call
# spent 4.07ms making 1427 calls to diagnostics::CORE:substcont, avg 3µs/call |
342 | 2535 | 1.77ms | 2604 | 825µs | s/[IF]<(.*?)>/italic($1)/ges; # spent 444µs making 2498 calls to diagnostics::CORE:subst, avg 178ns/call
# spent 354µs making 37 calls to diagnostics::italic, avg 10µs/call
# spent 26µs making 69 calls to diagnostics::CORE:substcont, avg 383ns/call |
343 | 2498 | 4.44ms | 3038 | 576µs | s/L<(.*?)>/ # spent 408µs making 2498 calls to diagnostics::CORE:subst, avg 163ns/call
# spent 169µs making 540 calls to diagnostics::CORE:substcont, avg 313ns/call |
344 | 280 | 215µs | 280 | 742µs | my($text,$page,$sect) = _split_pod_link($1); # spent 742µs making 280 calls to diagnostics::_split_pod_link, avg 3µs/call |
345 | 280 | 264µs | 386 | 3.82ms | defined $text # spent 3.82ms making 386 calls to diagnostics::italic, avg 10µs/call |
346 | ? $text | ||||
347 | : defined $sect | ||||
348 | ? italic($sect) . ' in ' . italic($page) | ||||
349 | : italic($page) | ||||
350 | /ges; | ||||
351 | 2498 | 4.26ms | 2498 | 442µs | s/S<(.*?)>/ # spent 442µs making 2498 calls to diagnostics::CORE:subst, avg 177ns/call |
352 | $1 | ||||
353 | /ges; | ||||
354 | } else { | ||||
355 | s/C<<< (.*?) >>>|C<< (.*?) >>|[BC]<(.*?)>/$+/gs; | ||||
356 | s/[IF]<(.*?)>/$1/gs; | ||||
357 | s/L<(.*?)>/ | ||||
358 | my($text,$page,$sect) = _split_pod_link($1); | ||||
359 | defined $text | ||||
360 | ? $text | ||||
361 | : defined $sect | ||||
362 | ? qq '"$sect" in $page' | ||||
363 | : $page | ||||
364 | /ges; | ||||
365 | s/S<(.*?)>/ | ||||
366 | $1 | ||||
367 | /ges; | ||||
368 | } | ||||
369 | 2498 | 7.51ms | 2498 | 283µs | unless (/^=/) { # spent 283µs making 2498 calls to diagnostics::CORE:match, avg 113ns/call |
370 | 1435 | 204µs | if (defined $header) { | ||
371 | 1433 | 180µs | 15 | 4µs | if ( $header eq 'DESCRIPTION' && # spent 4µs making 15 calls to diagnostics::CORE:match, avg 287ns/call |
372 | ( /Optional warnings are enabled/ | ||||
373 | || /Some of these messages are generic./ | ||||
374 | ) ) | ||||
375 | { | ||||
376 | 2 | 700ns | next; | ||
377 | } | ||||
378 | 1431 | 769µs | 1431 | 51.9ms | $_ = expand $_; # spent 51.9ms making 1431 calls to Text::Tabs::expand, avg 36µs/call |
379 | 1431 | 5.79ms | 1431 | 2.50ms | s/^/ /gm; # spent 2.50ms making 1431 calls to diagnostics::CORE:subst, avg 2µs/call |
380 | 1431 | 735µs | $msg{$header} .= $_; | ||
381 | 1474 | 293µs | for my $h(@headers) { $msg{$h} .= $_ } | ||
382 | 1431 | 119µs | ++$seen_body; | ||
383 | 1431 | 177µs | undef $for_item; | ||
384 | } | ||||
385 | 1433 | 271µs | next; | ||
386 | } | ||||
387 | |||||
388 | # If we have not come across the body of the description yet, then | ||||
389 | # the previous header needs to share the same description. | ||||
390 | 1063 | 199µs | if ($seen_body) { | ||
391 | @headers = (); | ||||
392 | } | ||||
393 | else { | ||||
394 | 30 | 9µs | push @headers, $header if defined $header; | ||
395 | } | ||||
396 | |||||
397 | 1063 | 5.45ms | 1063 | 2.35ms | if ( ! s/=item (.*?)\s*\z//s || $over_level != 1) { # spent 2.35ms making 1063 calls to diagnostics::CORE:subst, avg 2µs/call |
398 | |||||
399 | 25 | 58µs | 93 | 11µs | if ( s/=head1\sDESCRIPTION//) { # spent 6µs making 44 calls to diagnostics::CORE:match, avg 143ns/call
# spent 5µs making 49 calls to diagnostics::CORE:subst, avg 98ns/call |
400 | 1 | 700ns | $msg{$header = 'DESCRIPTION'} = ''; | ||
401 | 1 | 200ns | undef $for_item; | ||
402 | } | ||||
403 | elsif( s/^=for\s+diagnostics\s*\n(.*?)\s*\z// ) { | ||||
404 | $for_item = $1; | ||||
405 | } | ||||
406 | elsif( /^=over\b/ ) { | ||||
407 | $over_level++; | ||||
408 | } | ||||
409 | elsif( /^=back\b/ ) { # Stop processing body here | ||||
410 | 4 | 300ns | $over_level--; | ||
411 | 4 | 800ns | if ($over_level == 0) { | ||
412 | 1 | 100ns | undef $header; | ||
413 | 1 | 0s | undef $for_item; | ||
414 | 1 | 100ns | $seen_body = 0; | ||
415 | 1 | 500ns | next; | ||
416 | } | ||||
417 | } | ||||
418 | 24 | 7µs | next; | ||
419 | } | ||||
420 | |||||
421 | 1038 | 148µs | if( $for_item ) { $header = $for_item; undef $for_item } | ||
422 | else { | ||||
423 | 1038 | 328µs | $header = $1; | ||
424 | |||||
425 | 1038 | 6.03ms | 1038 | 143µs | $header =~ s/\n/ /gs; # Allow multi-line headers # spent 143µs making 1038 calls to diagnostics::CORE:subst, avg 137ns/call |
426 | } | ||||
427 | |||||
428 | # strip formatting directives from =item line | ||||
429 | 1038 | 591µs | 1038 | 108µs | $header =~ s/[A-Z]<(.*?)>/$1/g; # spent 108µs making 1038 calls to diagnostics::CORE:subst, avg 104ns/call |
430 | |||||
431 | # Since we strip "(\.\s*)\n" when we search a warning, strip it here as well | ||||
432 | 1038 | 4.34ms | 1038 | 3.79ms | $header =~ s/(\.\s*)?$//; # spent 3.79ms making 1038 calls to diagnostics::CORE:subst, avg 4µs/call |
433 | |||||
434 | 1038 | 1.14ms | my @toks = split( /(%l?[dxX]|%[ucp]|%(?:\.\d+)?[fs])/, $header ); | ||
435 | 1038 | 223µs | if (@toks > 1) { | ||
436 | 648 | 73µs | my $conlen = 0; | ||
437 | 648 | 310µs | for my $i (0..$#toks){ | ||
438 | 2274 | 739µs | if( $i % 2 ){ | ||
439 | 916 | 3.99ms | 1718 | 428µs | if( $toks[$i] eq '%c' ){ # spent 428µs making 1718 calls to diagnostics::CORE:match, avg 249ns/call |
440 | $toks[$i] = '.'; | ||||
441 | } elsif( $toks[$i] =~ /^%(?:d|u)$/ ){ | ||||
442 | $toks[$i] = '\d+'; | ||||
443 | } elsif( $toks[$i] =~ '^%(?:s|.*f)$' ){ | ||||
444 | $toks[$i] = $i == $#toks ? '.*' : '.*?'; | ||||
445 | } elsif( $toks[$i] =~ '%.(\d+)s' ){ | ||||
446 | $toks[$i] = ".{$1}"; | ||||
447 | } elsif( $toks[$i] =~ '^%l*([pxX])$' ){ | ||||
448 | $toks[$i] = $1 eq 'X' ? '[\dA-F]+' : '[\da-f]+'; | ||||
449 | } | ||||
450 | } elsif( length( $toks[$i] ) ){ | ||||
451 | 1324 | 422µs | $toks[$i] = quotemeta $toks[$i]; | ||
452 | 1324 | 155µs | $conlen += length( $toks[$i] ); | ||
453 | } | ||||
454 | } | ||||
455 | 648 | 274µs | my $lhs = join( '', @toks ); | ||
456 | 648 | 2.11ms | 648 | 1.74ms | $lhs =~ s/(\\\s)+/\\s+/g; # Replace lit space with multi-space match # spent 1.74ms making 648 calls to diagnostics::CORE:subst, avg 3µs/call |
457 | $transfmt{$header}{pat} = | ||||
458 | 648 | 747µs | " s^\\s*$lhs\\s*\Q$header\Es\n\t&& return 1;\n"; | ||
459 | 648 | 201µs | $transfmt{$header}{len} = $conlen; | ||
460 | } else { | ||||
461 | 390 | 157µs | my $lhs = "\Q$header\E"; | ||
462 | 390 | 979µs | 390 | 755µs | $lhs =~ s/(\\\s)+/\\s+/g; # Replace lit space with multi-space match # spent 755µs making 390 calls to diagnostics::CORE:subst, avg 2µs/call |
463 | $transfmt{$header}{pat} = | ||||
464 | 390 | 389µs | " s^\\s*$lhs\\s*\Q$header\E\n\t && return 1;\n"; | ||
465 | 390 | 122µs | $transfmt{$header}{len} = length( $header ); | ||
466 | } | ||||
467 | |||||
468 | print STDERR __PACKAGE__.": Duplicate entry: \"$header\"\n" | ||||
469 | 1038 | 232µs | if $msg{$header}; | ||
470 | |||||
471 | 1038 | 339µs | $msg{$header} = ''; | ||
472 | 1038 | 3.66ms | 1038 | 2.67ms | $seen_body = 0; # spent 2.67ms making 1038 calls to diagnostics::CORE:readline, avg 3µs/call |
473 | } | ||||
474 | |||||
475 | |||||
476 | 1 | 11µs | 1 | 6µs | close POD_DIAG unless *main::DATA eq *POD_DIAG; # spent 6µs making 1 call to diagnostics::CORE:close |
477 | |||||
478 | 1 | 300ns | die "No diagnostics?" unless %msg; | ||
479 | |||||
480 | # Apply patterns in order of decreasing sum of lengths of fixed parts | ||||
481 | # Seems the best way of hitting the right one. | ||||
482 | 1 | 1.45ms | 1 | 1.29ms | for my $hdr ( sort { $transfmt{$b}{len} <=> $transfmt{$a}{len} } # spent 1.29ms making 1 call to diagnostics::CORE:sort |
483 | keys %transfmt ){ | ||||
484 | 1038 | 351µs | $transmo .= $transfmt{$hdr}{pat}; | ||
485 | } | ||||
486 | 1 | 300ns | $transmo .= " return 0;\n}\n"; | ||
487 | 1 | 500ns | print STDERR $transmo if $DEBUG; | ||
488 | 1 | 43.2ms | eval $transmo; | ||
489 | 1 | 4µs | die $@ if $@; | ||
490 | } | ||||
491 | |||||
492 | 1 | 500ns | if ($standalone) { | ||
493 | if (!@ARGV and -t STDIN) { print STDERR "$0: Reading from STDIN\n" } | ||||
494 | while (defined (my $error = <>)) { | ||||
495 | splainthis($error) || print THITHER $error; | ||||
496 | } | ||||
497 | exit; | ||||
498 | } | ||||
499 | |||||
500 | 1 | 500ns | my $olddie; | ||
501 | my $oldwarn; | ||||
502 | |||||
503 | # spent 28µs (24+4) within diagnostics::import which was called 3 times, avg 9µs/call:
# once (16µs+4µs) by main::BEGIN@8 at line 8 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl
# once (4µs+0s) by Gradescope::Translate::BEGIN@7 at line 7 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/lib/Gradescope/Translate.pm
# once (3µs+0s) by Gradescope::Color::BEGIN@7 at line 7 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/lib/Gradescope/Color.pm | ||||
504 | 3 | 800ns | shift; | ||
505 | 3 | 2µs | $^W = 1; # yup, clobbered the global variable; | ||
506 | # tough, if you want diags, you want diags. | ||||
507 | 3 | 8µs | return if defined $SIG{__WARN__} && ($SIG{__WARN__} eq \&warn_trap); | ||
508 | |||||
509 | 1 | 1µs | for (@_) { | ||
510 | |||||
511 | 1 | 6µs | 1 | 1µs | /^-d(ebug)?$/ && do { # spent 1µs making 1 call to diagnostics::CORE:match |
512 | $DEBUG++; | ||||
513 | next; | ||||
514 | }; | ||||
515 | |||||
516 | 1 | 4µs | 1 | 3µs | /^-v(erbose)?$/ && do { # spent 3µs making 1 call to diagnostics::CORE:match |
517 | 1 | 500ns | $VERBOSE++; | ||
518 | 1 | 800ns | next; | ||
519 | }; | ||||
520 | |||||
521 | /^-p(retty)?$/ && do { | ||||
522 | print STDERR "$0: I'm afraid it's too late for prettiness.\n"; | ||||
523 | $PRETTY++; | ||||
524 | next; | ||||
525 | }; | ||||
526 | # matches trace and traceonly for legacy doc mixup reasons | ||||
527 | /^-t(race(only)?)?$/ && do { | ||||
528 | $TRACEONLY++; | ||||
529 | next; | ||||
530 | }; | ||||
531 | /^-w(arntrace)?$/ && do { | ||||
532 | $WARNTRACE++; | ||||
533 | next; | ||||
534 | }; | ||||
535 | |||||
536 | warn "Unknown flag: $_"; | ||||
537 | } | ||||
538 | |||||
539 | 1 | 300ns | $oldwarn = $SIG{__WARN__}; | ||
540 | 1 | 500ns | $olddie = $SIG{__DIE__}; | ||
541 | 1 | 2µs | $SIG{__WARN__} = \&warn_trap; | ||
542 | 1 | 3µs | $SIG{__DIE__} = \&death_trap; | ||
543 | } | ||||
544 | |||||
545 | sub enable { &import } | ||||
546 | |||||
547 | sub disable { | ||||
548 | shift; | ||||
549 | return unless $SIG{__WARN__} eq \&warn_trap; | ||||
550 | $SIG{__WARN__} = $oldwarn || ''; | ||||
551 | $SIG{__DIE__} = $olddie || ''; | ||||
552 | } | ||||
553 | |||||
554 | sub warn_trap { | ||||
555 | my $warning = $_[0]; | ||||
556 | if (caller eq __PACKAGE__ or !splainthis($warning)) { | ||||
557 | if ($WARNTRACE) { | ||||
558 | print STDERR Carp::longmess($warning); | ||||
559 | } else { | ||||
560 | print STDERR $warning; | ||||
561 | } | ||||
562 | } | ||||
563 | goto &$oldwarn if defined $oldwarn and $oldwarn and $oldwarn ne \&warn_trap; | ||||
564 | }; | ||||
565 | |||||
566 | # spent 20µs within diagnostics::death_trap which was called 3 times, avg 7µs/call:
# 3 times (20µs+0s) by Locale::Maketext::Simple::load_loc at line 140 of Locale/Maketext/Simple.pm, avg 7µs/call | ||||
567 | 3 | 2µs | my $exception = $_[0]; | ||
568 | |||||
569 | # See if we are coming from anywhere within an eval. If so we don't | ||||
570 | # want to explain the exception because it's going to get caught. | ||||
571 | 3 | 800ns | my $in_eval = 0; | ||
572 | 3 | 400ns | my $i = 0; | ||
573 | 3 | 7µs | while (my $caller = (caller($i++))[3]) { | ||
574 | 6 | 1µs | if ($caller eq '(eval)') { | ||
575 | 3 | 400ns | $in_eval = 1; | ||
576 | 3 | 2µs | last; | ||
577 | } | ||||
578 | } | ||||
579 | |||||
580 | 3 | 500ns | splainthis($exception) unless $in_eval; | ||
581 | 3 | 1µs | if (caller eq __PACKAGE__) { | ||
582 | print STDERR "INTERNAL EXCEPTION: $exception"; | ||||
583 | } | ||||
584 | 3 | 800ns | &$olddie if defined $olddie and $olddie and $olddie ne \&death_trap; | ||
585 | |||||
586 | 3 | 6µs | return if $in_eval; | ||
587 | |||||
588 | # We don't want to unset these if we're coming from an eval because | ||||
589 | # then we've turned off diagnostics. | ||||
590 | |||||
591 | # Switch off our die/warn handlers so we don't wind up in our own | ||||
592 | # traps. | ||||
593 | $SIG{__DIE__} = $SIG{__WARN__} = ''; | ||||
594 | |||||
595 | $exception =~ s/\n(?=.)/\n\t/gas; | ||||
596 | |||||
597 | die Carp::longmess("__diagnostics__") | ||||
598 | =~ s/^__diagnostics__.*?line \d+\.?\n/ | ||||
599 | "Uncaught exception from user code:\n\t$exception" | ||||
600 | /re; | ||||
601 | # up we go; where we stop, nobody knows, but i think we die now | ||||
602 | # but i'm deeply afraid of the &$olddie guy reraising and us getting | ||||
603 | # into an indirect recursion loop | ||||
604 | }; | ||||
605 | |||||
606 | my %exact_duplicate; | ||||
607 | my %old_diag; | ||||
608 | my $count; | ||||
609 | my $wantspace; | ||||
610 | sub splainthis { | ||||
611 | return 0 if $TRACEONLY; | ||||
612 | for (my $tmp = shift) { | ||||
613 | local $\; | ||||
614 | local $!; | ||||
615 | ### &finish_compilation unless %msg; | ||||
616 | s/(\.\s*)?\n+$//; | ||||
617 | my $orig = $_; | ||||
618 | # return unless defined; | ||||
619 | |||||
620 | # get rid of the where-are-we-in-input part | ||||
621 | s/, <.*?> (?:line|chunk).*$//; | ||||
622 | |||||
623 | # Discard 1st " at <file> line <no>" and all text beyond | ||||
624 | # but be aware of messages containing " at this-or-that" | ||||
625 | my $real = 0; | ||||
626 | my @secs = split( / at / ); | ||||
627 | return unless @secs; | ||||
628 | $_ = $secs[0]; | ||||
629 | for my $i ( 1..$#secs ){ | ||||
630 | if( $secs[$i] =~ /.+? (?:line|chunk) \d+/ ){ | ||||
631 | $real = 1; | ||||
632 | last; | ||||
633 | } else { | ||||
634 | $_ .= ' at ' . $secs[$i]; | ||||
635 | } | ||||
636 | } | ||||
637 | |||||
638 | # remove parenthesis occurring at the end of some messages | ||||
639 | s/^\((.*)\)$/$1/; | ||||
640 | |||||
641 | if ($exact_duplicate{$orig}++) { | ||||
642 | return &transmo; | ||||
643 | } else { | ||||
644 | return 0 unless &transmo; | ||||
645 | } | ||||
646 | |||||
647 | my $short = shorten($orig); | ||||
648 | if ($old_diag{$_}) { | ||||
649 | autodescribe(); | ||||
650 | print THITHER "$short (#$old_diag{$_})\n"; | ||||
651 | $wantspace = 1; | ||||
652 | } elsif (!$msg{$_} && $orig =~ /\n./s) { | ||||
653 | # A multiline message, like "Attempt to reload / | ||||
654 | # Compilation failed" | ||||
655 | my $found; | ||||
656 | for (split /^/, $orig) { | ||||
657 | splainthis($_) and $found = 1; | ||||
658 | } | ||||
659 | return $found; | ||||
660 | } else { | ||||
661 | autodescribe(); | ||||
662 | $old_diag{$_} = ++$count; | ||||
663 | print THITHER "\n" if $wantspace; | ||||
664 | $wantspace = 0; | ||||
665 | print THITHER "$short (#$old_diag{$_})\n"; | ||||
666 | if ($msg{$_}) { | ||||
667 | print THITHER $msg{$_}; | ||||
668 | } else { | ||||
669 | if (0 and $standalone) { | ||||
670 | print THITHER " **** Error #$old_diag{$_} ", | ||||
671 | ($real ? "is" : "appears to be"), | ||||
672 | " an unknown diagnostic message.\n\n"; | ||||
673 | } | ||||
674 | return 0; | ||||
675 | } | ||||
676 | } | ||||
677 | return 1; | ||||
678 | } | ||||
679 | } | ||||
680 | |||||
681 | sub autodescribe { | ||||
682 | if ($VERBOSE and not $count) { | ||||
683 | print THITHER &{$PRETTY ? \&bold : \&noop}("DESCRIPTION OF DIAGNOSTICS"), | ||||
684 | "\n$msg{DESCRIPTION}\n"; | ||||
685 | } | ||||
686 | } | ||||
687 | |||||
688 | # spent 2.31ms (1.96+350µs) within diagnostics::unescape which was called 2498 times, avg 924ns/call:
# 2498 times (1.96ms+350µs) by main::BEGIN@8 at line 336, avg 924ns/call | ||||
689 | 2498 | 3.01ms | 2520 | 350µs | s { # spent 342µs making 2498 calls to diagnostics::CORE:subst, avg 137ns/call
# spent 8µs making 22 calls to diagnostics::CORE:substcont, avg 377ns/call |
690 | do { | ||||
691 | exists $HTML_Escapes{$1} | ||||
692 | ? do { $HTML_Escapes{$1} } | ||||
693 | : do { | ||||
694 | 15 | 2µs | warn "Unknown escape: E<$1> in $_"; | ||
695 | "E<$1>"; | ||||
696 | } | ||||
697 | 15 | 8µs | } | ||
698 | }egx; | ||||
699 | |||||
- - | |||||
703 | } | ||||
704 | |||||
705 | sub shorten { | ||||
706 | my $line = $_[0]; | ||||
707 | if (length($line) > 79 and index($line, "\n") == -1) { | ||||
708 | my $space_place = rindex($line, ' ', 79); | ||||
709 | if ($space_place != -1) { | ||||
710 | substr($line, $space_place, 1) = "\n\t"; | ||||
711 | } | ||||
712 | } | ||||
713 | return $line; | ||||
714 | } | ||||
715 | |||||
716 | |||||
717 | 1 | 463µs | 1 unless $standalone; # or it'll complain about itself | ||
718 | __END__ # wish diag dbase were more accessible | ||||
# spent 6µs within diagnostics::CORE:close which was called:
# once (6µs+0s) by main::BEGIN@8 at line 476 | |||||
# spent 8µs within diagnostics::CORE:eof which was called:
# once (8µs+0s) by main::BEGIN@8 at line 258 | |||||
sub diagnostics::CORE:ftis; # opcode | |||||
# spent 1.04ms within diagnostics::CORE:match which was called 4557 times, avg 229ns/call:
# 2498 times (283µs+0s) by main::BEGIN@8 at line 369, avg 113ns/call
# 1718 times (428µs+0s) by main::BEGIN@8 at line 439, avg 249ns/call
# 280 times (316µs+0s) by diagnostics::_split_pod_link at line 332, avg 1µs/call
# 44 times (6µs+0s) by main::BEGIN@8 at line 399, avg 143ns/call
# 15 times (4µs+0s) by main::BEGIN@8 at line 371, avg 287ns/call
# once (3µs+0s) by diagnostics::import at line 516
# once (1µs+0s) by diagnostics::import at line 511 | |||||
# spent 12µs within diagnostics::CORE:open which was called:
# once (12µs+0s) by main::BEGIN@8 at line 234 | |||||
sub diagnostics::CORE:readline; # opcode | |||||
# spent 1.29ms within diagnostics::CORE:sort which was called:
# once (1.29ms+0s) by main::BEGIN@8 at line 482 | |||||
# spent 25.8ms within diagnostics::CORE:subst which was called 20563 times, avg 1µs/call:
# 2498 times (12.4ms+0s) by main::BEGIN@8 at line 341, avg 5µs/call
# 2498 times (444µs+0s) by main::BEGIN@8 at line 342, avg 178ns/call
# 2498 times (442µs+0s) by main::BEGIN@8 at line 351, avg 177ns/call
# 2498 times (408µs+0s) by main::BEGIN@8 at line 343, avg 163ns/call
# 2498 times (342µs+0s) by diagnostics::unescape at line 689, avg 137ns/call
# 1431 times (2.50ms+0s) by main::BEGIN@8 at line 379, avg 2µs/call
# 1063 times (2.35ms+0s) by main::BEGIN@8 at line 397, avg 2µs/call
# 1038 times (3.79ms+0s) by main::BEGIN@8 at line 432, avg 4µs/call
# 1038 times (143µs+0s) by main::BEGIN@8 at line 425, avg 137ns/call
# 1038 times (108µs+0s) by main::BEGIN@8 at line 429, avg 104ns/call
# 955 times (248µs+0s) by diagnostics::bold at line 339, avg 259ns/call
# 648 times (1.74ms+0s) by main::BEGIN@8 at line 456, avg 3µs/call
# 423 times (130µs+0s) by diagnostics::italic at line 340, avg 308ns/call
# 390 times (755µs+0s) by main::BEGIN@8 at line 462, avg 2µs/call
# 49 times (5µs+0s) by main::BEGIN@8 at line 399, avg 98ns/call | |||||
# spent 6.59ms within diagnostics::CORE:substcont which was called 14119 times, avg 467ns/call:
# 7779 times (1.49ms+0s) by diagnostics::bold at line 339, avg 191ns/call
# 4282 times (827µs+0s) by diagnostics::italic at line 340, avg 193ns/call
# 1427 times (4.07ms+0s) by main::BEGIN@8 at line 341, avg 3µs/call
# 540 times (169µs+0s) by main::BEGIN@8 at line 343, avg 313ns/call
# 69 times (26µs+0s) by main::BEGIN@8 at line 342, avg 383ns/call
# 22 times (8µs+0s) by diagnostics::unescape at line 689, avg 377ns/call |