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

DTrace Your Application

DTrace Your Application

Many know that DTrace is a great tool for profiling and understanding operating system level behavior. Less know that many popular programming languages provide DTrace probes which enable full stack tracing and probing.

Jade Allen

July 25, 2013
Tweet

More Decks by Jade Allen

Other Decks in Technology

Transcript

  1. DTrace Your Application! (Not Your Operating System)! ! ! Mark

    Allen! [email protected]! @bytemeorg! http://byte-me.org! https://github.com/mrallen1! https://speakerdeck.com/mrallen1!
  2. DTrace Your Application! (Not AND Your Operating System)! ! !

    Mark Allen! [email protected]! @bytemeorg! http://byte-me.org! https://github.com/mrallen1! https://speakerdeck.com/mrallen1!
  3. DTrace Basics Dynamic versus! print "got here!" time_it(Module, Func, Args)

    -> S = now(), Result = Module:Func(Args), log_elapsed_time(S, now()), Result.
  4. I work at Alert Logic*.! ! I write a lot

    of Erlang for work, but I have open source projects in Golang, Clojure, bash, Python and Perl.! * We're hiring.!
  5. DTrace Basics DTrace enabled OSes:! •  Solaris 10+! •  OpenSolarisIllumos!

    •  SmartOS (Joyent)! •  OmniOS (OmniTI)! •  FreeBSD! •  Mac OS X!
  6. DTrace Basics Provider! ! In our case, this is the

    application language itself. ! ! (More on this soon)!
  7. 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}'
  8. D Language Basics #!/usr/sbin/dtrace -qZs sub-entry { /* Count sub

    entries by package and sub name * arg3 = package name (Foo::Bar) * arg0 = subroutine name (do_something) */ @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  9. D Language Basics #!/usr/sbin/dtrace -qZs sub-entry { /* Count sub

    entries by package and sub name * arg3 = package name (Foo::Bar) * arg0 = subroutine name (do_something) */ @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  10. D Language Basics #!/usr/sbin/dtrace -qZs sub-entry { /* Count sub

    entries by package and sub name * arg3 = package name (Foo::Bar) * arg0 = subroutine name (do_something) */ @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  11. D Language Basics #!/usr/sbin/dtrace -qZs sub-entry { /* Count sub

    entries by package and sub name * arg3 = package name (Foo::Bar) * arg0 = subroutine name (do_something) */ @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END { /* Give me top 10 highest counts; throw away rest */ trunc(@, 10) }
  12. D Language Basics #!/usr/sbin/dtrace -qs erlang*:::process-spawn { printf("pid %s mfa

    %s\n", copyinstr(arg0), copyinstr(arg1)); } erlang*:::process-exit { printf("pid %s reason %s\n", copyinstr(arg0), copyinstr(arg1)); } erlang*:::process-exit_signal { printf("sender %s -> pid %s reason %s\n", copyinstr(arg0), copyinstr(arg1), copyinstr(arg2)); }
  13. D Language Basics Common aggregation functions! •  avg! •  count!

    •  lquantize (linear)! •  quantize (log - power of 2)! •  sum! •  min! •  max!
  14. DTrace and Perl Mac OS X vendor perl and OmniOS

    vendor perl ! ship with DTrace.!
  15. DTrace and Perl Build your own with perlbrew perlbrew install

    \ perl-5.18.0 \ --as 5.18-dtrace \ -Dusedtrace
  16. DTrace and Perl DTrace support by Perl release! Perl release!

    DTrace probes! 5.10.1! sub-entry, sub-return! 5.14.x! sub-entry and return get package name as an argument! 5.16.x! phase-change! 5.18.0! op-entry, loading-file, loaded- file!
  17. DTrace and Perl op-entry! (OPNAME) Fires before op executed. If

    the debugger is active, fires after debug hooks but still before the op is executed.!
  18. DTrace and Perl loading-file (fires before load)! loaded-file (fires after

    load)! ! (FILENAME) The filename is a path! (e.g., Foo/Bar not Foo::Bar)!
  19. DTrace and Perl Make your own DTrace probes in Perl

    by using ! ! Devel::DTrace::Provider! !
  20. DTrace and Python Build your own with pythonz* pythonz install

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

    by using ! ! http://tmetsch.github.io/python-dtrace/! ! Available on PyPI too!
  22. DTrace and Erlang Build your own with kerl $ KERL_CONFIGURE_OPTIONS="--with-

    dynamic-trace=dtrace" \ kerl build R16B01 \ r16b01-dtrace
  23. DTrace and Erlang Build your own with kerl $ kerl

    install \ r16b01-dtrace $ ~`whoami`/activate
  24. DTrace and Perl Make your own DTrace probes in Erlang

    by using ! ! dyntrace:p()! ! Comes with the standard install.!
  25. DTrace and Erlang user_trace-n0 .. user_trace-n950! (PID, USER_TAG, INT_ARG0, INT_ARG1,

    INT_ARG2, INT_ARG3, STR_ARG0, STR_ARG1, STR_ARG2, STR_ARG3)
  26. DTrace and Perl Erlang DTrace resources:! •  $ERL_INSTALL/ runtime_tools-*/examples! • 

    http://www.erlang.org/ doc/apps/runtime_tools/ DTRACE.html! •  http://vimeo.com/33999876!
  27. Resources DTrace resources: •  http://dtracehol.com/#Intro •  http://dtrace.org/guide/preface.html •  http://dtracebook.com/index.php/ Languages

    •  http://www.amazon.com/dp/0132091518 •  Brendan Gregg's talk Friday: http:// www.oscon.com/oscon2013/public/ schedule/detail/29398