Created
July 6, 2011 23:13
-
-
Save sartak/1068562 to your computer and use it in GitHub Desktop.
dtrace probe for phase change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kaitain% cat test.pl | |
#!/usr/bin/env perl | |
use 5.14.0; | |
package Class { | |
sub new { bless {} } | |
sub DESTROY { say "Bye at ${^GLOBAL_PHASE} time" } | |
}; | |
BEGIN { Class->new } | |
Class->new; | |
kaitain% perl test.pl | |
Bye at START time | |
Bye at RUN time | |
kaitain% cat begin-destroy.d | |
#!/usr/sbin/dtrace -qZs | |
:perl::phase-change | |
{ | |
self->phase = copyinstr(arg0); | |
} | |
:perl::phase-change | |
/copyinstr(arg0) == "RUN"/ | |
{ | |
self->started = 1; | |
} | |
:perl::sub-entry | |
/!self->started && copyinstr(arg0) == "DESTROY"/ | |
{ | |
printf("%s::%s called at %s time\n", copyinstr(arg3), copyinstr(arg0), self->phase); | |
} | |
kaitain% sudo ./begin-destroy.d & | |
[1] 49504 | |
kaitain% perl test.pl | |
Bye at START time | |
Bye at RUN time | |
kaitain% Class::DESTROY called at START time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment