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

Python, DTrace and you

Python, DTrace and you

Learn about how Python and DTrace operate together

Jade Allen

June 18, 2013
Tweet

More Decks by Jade Allen

Other Decks in Technology

Transcript

  1. DTrace, Python and you! ! ! Mark Allen! [email protected]! @bytemeorg!

    http://byte-me.org! https://github.com/mrallen1!
  2. DTrace Basics Dynamic versus! print "got here!" @profile def do_stuff(self,

    **kwargs): print "This is fun!" See  h%p://mg.pov.lt/profilehooks/  for  @profile  decorator  
  3. DTrace Basics It's like X-Ray vision into your application and

    operating system.! ! (And it's fun!)! (And it's neckbeardy!1one)!
  4. DTrace Basics Examples:! •  Trace socket accepts and debug your

    web application's "real" code execution pathway! •  Profile why NFS gets super busy at 0430 and a directory tree traversal takes 2 hours instead of 2 minutes.!
  5. DTrace Basics DTrace enabled OSes:! •  Solaris 10+! •  OpenSolarisIllumos!

    •  SmartOS (Joyent)! •  OmniOS (OmniTI)! •  FreeBSD! •  Mac OS X!
  6. DTrace Basics You're looking for the talk! "SystemTap, python and

    you"! ! Try down the hall, on the left.! ! ! (Sorry)  
  7. DTrace Basics Provider! ! In our case, this is the

    python binary itself. ! ! (More on this soon)!
  8. D Language Basics D Language Overview! •  awk-like! •  Define

    a probe, optional predicate and optional actions in a braced clause! •  Supports BEGIN and END blocks! •  Local variables (this->foo = 42)! •  Aggregate/associative variables (prefixed with @)! •  One liner support in the form! dtrace -n 'probe /predicate/ {action}'
  9. D Language Basics $ cat subcount.d #!/usr/sbin/dtrace -qZs function-entry {

    /* Count sub entries by package and sub name * arg0 = source file name * arg1 = function name (def do_something():) */ @[strjoin(strjoin(copyinstr(arg0),"-"),copyinstr(arg1))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  10. D Language Basics $ cat subcount.d #!/usr/sbin/dtrace -qZs function-entry {

    /* Count sub entries by package and sub name * arg0 = source file name * arg1 = functiuon name (def do_something():) */ @[strjoin(strjoin(copyinstr(arg0),"-"),copyinstr(arg1))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  11. D Language Basics $ cat subcount.d #!/usr/sbin/dtrace -qZs function-entry {

    /* Count sub entries by package and sub name * arg0 = source file name * arg1 = functiuon name (def do_something():) */ @[strjoin(strjoin(copyinstr(arg0),"-"),copyinstr(arg1))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  12. D Language Basics $ cat subcount.d #!/usr/sbin/dtrace -qZs function-entry {

    /* Count sub entries by package and sub name * arg0 = source file name * arg1 = functiuon name (def do_something():) */ @[strjoin(strjoin(copyinstr(arg0),"-"),copyinstr(arg1))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  13. D Language Basics Common aggregation functions! •  avg! •  count!

    •  lquantize (linear)! •  quantize (log - power of 2)! •  sum! •  min! •  max!
  14. DTrace and Python Build your own with pythonz* pythonz install

    \ --dtrace 2.7.5 (* apply https://github.com/saghul/pythonz/pull/43)
  15. DTrace and Python Make your own DTrace probes in Python

    by using ! ! http://tmetsch.github.io/python-dtrace/! ! Available on PyPI too!