"loading-file" and "loaded-file" DTrace probes

This commit is contained in:
Shawn M Moore 2012-08-19 17:12:27 +02:00 committed by Father Chrysostomos
parent fe83c362fb
commit 32aeab29cd
6 changed files with 78 additions and 2 deletions

View File

@ -38,6 +38,18 @@
PERL_OP_ENTRY(tmp_name, file, line, stash); \
}
# define LOADING_FILE_PROBE(name) \
if (PERL_LOADING_FILE_ENABLED()) { \
const char *tmp_name = name; \
PERL_LOADING_FILE(tmp_name); \
}
# define LOADED_FILE_PROBE(name) \
if (PERL_LOADED_FILE_ENABLED()) { \
const char *tmp_name = name; \
PERL_LOADED_FILE(tmp_name); \
}
# else
# define ENTRY_PROBE(func, file, line, stash) \
@ -55,6 +67,16 @@
PERL_OP_ENTRY(name); \
}
# define LOADING_FILE_PROBE(name) \
if (PERL_LOADING_FILE_ENABLED()) { \
PERL_LOADING_FILE(name); \
}
# define LOADED_FILE_PROBE(name) \
if (PERL_LOADED_FILE_ENABLED()) { \
PERL_LOADED_FILE(name); \
}
# endif
# define PHASE_CHANGE_PROBE(new_phase, old_phase) \
@ -69,6 +91,8 @@
# define RETURN_PROBE(func, file, line, stash)
# define PHASE_CHANGE_PROBE(new_phase, old_phase)
# define OP_ENTRY_PROBE(name)
# define LOADING_FILE_PROBE(name)
# define LOADED_FILE_PROBE(name)
#endif

View File

@ -10,6 +10,9 @@ provider perl {
probe phase__change(const char *, const char *);
probe op__entry(const char *);
probe loading__file(const char *);
probe loaded__file(const char *);
};
/*

View File

@ -57,7 +57,7 @@ The C<phase-change> probe was added.
=item 5.18.0
The C<op-entry> probe was added.
The C<op-entry>, C<loading-file>, and C<loaded-file> probes weree added.
=back
@ -112,6 +112,29 @@ still before the opcode itself is executed).
printf("About to execute opcode %s\n", copyinstr(arg0));
}
=item loading-file(FILENAME)
Fires when Perl is about to load an individual file, whether from
C<use>, C<require>, or C<do>. This probe fires before the file is
read from disk. The filename argument is converted to local filesystem
paths instead of providing C<Module::Name>-style names.
:*perl*:loading-file {
printf("About to load %s\n", copyinstr(arg0));
}
=item loaded-file(FILENAME)
Fires when Perl has successfully loaded an individual file, whether
from C<use>, C<require>, or C<do>. This probe fires after the file
is read from disk and its contentss evaluated. The filename argument
is converted to local filesystem paths instead of providing
C<Module::Name>-style names.
:*perl*:loaded-file {
printf("Successfully loaded %s\n", copyinstr(arg0));
}
=back
=head1 EXAMPLES
@ -179,6 +202,8 @@ still before the opcode itself is executed).
Exporter::Heavy::_rebuild_cache 5039
Exporter::import 14578
=item
=back
=head1 REFERENCES

View File

@ -3696,6 +3696,8 @@ PP(pp_require)
}
}
LOADING_FILE_PROBE(unixname);
/* prepare to compile file */
if (path_is_absolute(name)) {
@ -3998,6 +4000,8 @@ PP(pp_require)
/* Restore encoding. */
PL_encoding = encoding;
LOADED_FILE_PROBE(unixname);
return op;
}

1
t/run/dtrace.pl Normal file
View File

@ -0,0 +1 @@
42

View File

@ -24,7 +24,7 @@ use strict;
use warnings;
use IPC::Open2;
plan(tests => 7);
plan(tests => 9);
dtrace_like(
'1',
@ -132,6 +132,25 @@ D_SCRIPT
'basic op probe',
);
dtrace_like(<< 'PERL_SCRIPT',
use strict;
require HTTP::Tiny;
do "run/dtrace.pl";
PERL_SCRIPT
<< 'D_SCRIPT',
loading-file { printf("loading-file <%s>\n", copyinstr(arg0)) }
loaded-file { printf("loaded-file <%s>\n", copyinstr(arg0)) }
D_SCRIPT
[
# the original test made sure that each file generated a loading-file then a loaded-file,
# but that had a race condition when the kernel would push the perl process onto a different
# CPU, so the DTrace output would appear out of order
qr{loading-file <strict\.pm>.*loading-file <HTTP/Tiny\.pm>.*loading-file <run/dtrace\.pl>}s,
qr{loaded-file <strict\.pm>.*loaded-file <HTTP/Tiny\.pm>.*loaded-file <run/dtrace\.pl>}s,
],
'loading-file, loaded-file probes',
);
sub dtrace_like {
my $perl = shift;
my $probes = shift;