Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DTrace & Python

DTrace & Python

An introduction to DTrace and to using DTrace to inspect Python programs.

Avatar for Conor McDermottroe

Conor McDermottroe

March 13, 2013
Tweet

Other Decks in Technology

Transcript

  1. WARNING • I’ve only been using DTrace for a couple

    of months • Sometimes it helps to know C • Sometimes it helps to know AWK
  2. What is it? • It’s like having logging everywhere •

    ... but without being slow • ... and with good query tools
  3. How do you get it? • Solaris (>= 10) •

    Mac OS X (>= 10.5) • FreeBSD (>= 7.1) • Linux - https://github.com/dtrace4linux/linux
  4. How do you use it? # dtrace -n '<some D>'

    -c /some/cmd # dtrace -s myscript.d -c /some/cmd # dtrace -s myscript.d -p 1234 # dtrace -s myscript.d
  5. Lots of functions copyin copyinstr stringof trace tracemem printf printa

    count sum avg stack ustack clear trunc min max quantize stop copyout copyoutstr breakpoint panic chill
  6. What about Python? • You need a patched copy of

    Python • Already patched on Solaris • OS X: brew install python --with-dtrace • WARNING: The syntax may differ, depending on the patch
  7. Timing breakdown for sub :Python::function-entry /copyinstr(arg1) == "sub"/ { self->start

    = timestamp; } :Python::function-return /copyinstr(arg1) == "sub"/ { self->t = timestamp - self->start; @time[execname] = quantize(self->t); self->ts = 0; }
  8. Timing breakdown for sub Python value ------------- Distribution ------------- count

    65536 | 0 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 7 262144 |@@@@@ 1 524288 | 0
  9. Things to look out for • It’s fast but it's

    not free - be selective • Probe names may differ across operating systems • For non-standard probes arg documentation can be sparse