Skip to content

Instantly share code, notes, and snippets.

@nascheme
Last active September 5, 2017 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nascheme/c1cece36a3369926ee93cecc3d024179 to your computer and use it in GitHub Desktop.
Save nascheme/c1cece36a3369926ee93cecc3d024179 to your computer and use it in GitHub Desktop.
Profiling Python imports using DTrace probes
/* 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