Last active
September 5, 2017 22:48
-
-
Save nascheme/c1cece36a3369926ee93cecc3d024179 to your computer and use it in GitHub Desktop.
Profiling Python imports using DTrace probes
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
/* run using: | |
$ sudo dtrace -q -s module_import_trace.d -c './python.exe -c True' | |
*/ | |
self int indent; | |
self int traceit; | |
python$target:::module-exec-start | |
{ | |
printf("%d\t%*s:", timestamp, 15, probename); | |
printf("%*s", self->indent, ""); | |
printf("start %s\n", copyinstr(arg0)); | |
self->indent++; | |
} | |
python$target:::module-exec-done | |
{ | |
printf("%d\t%*s:", timestamp, 15, probename); | |
printf("%*s", self->indent, ""); | |
printf("done %s\n", copyinstr(arg0)); | |
self->indent--; | |
} | |
python$target:::module-exec-start | |
/copyinstr(arg0) == "mymodule"/ | |
{ | |
self->traceit = 1; | |
} | |
python$target:::module-exec-done | |
/copyinstr(arg0) == "mymodule"/ | |
{ | |
self->traceit = 0; | |
} | |
python$target:::function-entry | |
/self->traceit/ | |
{ | |
printf("%d\t%*s:", timestamp, 15, probename); | |
printf("%*s", self->indent, ""); | |
printf("%s:%s:%d\n", copyinstr(arg0), copyinstr(arg1), arg2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment