perl, DTrace and you

perl, DTrace and you

This is an overview of the DTrace functionality in perl 5.10.1 and later. It's suitable for someone familiar with perl but not very familiar with DTrace.

https://github.com/mrallen1/perl-Tombala

7330b65ea54e1b90a987a552e5c5cf32?s=128

Mark Allen

June 04, 2013
Tweet

Transcript

  1. DTrace, Perl and you! ! ! Mark Allen! mrallen1@yahoo.com! @bytemeorg!

    http://byte-me.org! https://github.com/mrallen1! https://metacpan.org/author/MALLEN!
  2. DTrace Basics What is DTrace?!

  3. DTrace Basics Dynamic Tracing!

  4. DTrace Basics Dude! Srsly?!! Dynamic versus what?!!

  5. DTrace Basics Dynamic versus! warn Dumper $object if $debug; print

    "got here!\n"; my $start = time(); do_stuff(); my $elapsed = time() - $start;
  6. DTrace Basics "Observability technology"1! 1  DTrace:  Dynamic  Tracing  in  Oracle

     Solaris,  Pren(ce  Hall,  2nd  ed,  2012.  
  7. DTrace Basics In a DTrace enabled OS, you get full

    scope visibility!
  8. DTrace Basics Applica(on   Libraries   System   Calls  

    Kernel  
  9. DTrace Basics It's turtles all the way down...! h?p://flic.kr/p/aQDPrZ  

  10. DTrace Basics It's like X-Ray vision into your application and

    operating system.! ! (And it's fun!)! (And it's neckbeardy!1one)!
  11. 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.!
  12. DTrace Basics DTrace enabled OSes:! •  Solaris 10+! •  OpenSolarisIllumos!

    •  SmartOS (Joyent)! •  OmniOS (OmniTI)! •  FreeBSD! •  Mac OS X!
  13. DTrace Basics What about Linux?!

  14. DTrace Basics You're looking for the talk! "SystemTap, perl and

    you"! ! Try down the hall, on the left.! ! ! (Sorry)  
  15. DTrace Basics DTrace Terms!

  16. DTrace Basics Provider! ! Manages probes in a subsystem!

  17. DTrace Basics Provider! ! In our case, this is the

    perl binary itself. ! ! (More on this soon)!
  18. DTrace Basics Probes! ! DTrace ! instrumentation or! "observables"!

  19. DTrace Basics Consumer! ! A user-mode program! that calls into

    DTrace!
  20. D Language Basics D Language Basics!

  21. 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}'
  22. D Language Basics $ cat dtrace-example.d #!/usr/sbin/dtrace -s probe /predicate/

    { actions }
  23. D Language Basics Example 1!

  24. D Language Basics REAL Example 1!

  25. D Language Basics $ cat subentry.d #!/usr/sbin/dtrace -qFZs sub-entry, sub-return

    { /* arg0 is subroutine name */ trace(copyinstr(arg0)) }
  26. D Language Basics $ cat subentry.d #!/usr/sbin/dtrace -qFZs sub-entry, sub-return

    { /* arg0 is subroutine name */ trace(copyinstr(arg0)) }
  27. D Language Basics $ cat subentry.d #!/usr/sbin/dtrace -qFZs sub-entry, sub-return

    { /* arg0 is subroutine name */ trace(copyinstr(arg0)) }
  28. D Language Basics REAL Example 2!

  29. D Language Basics $ cat subcount.d #!/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) }
  30. D Language Basics $ cat subcount.d #!/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) }
  31. D Language Basics $ cat subcount.d #!/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) }
  32. D Language Basics $ cat subcount.d #!/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) }
  33. D Language Basics subcount.d  for  Pod::Perldoc  3.20  

  34. D Language Basics Common aggregation functions! •  avg! •  count!

    •  lquantize (linear)! •  quantize (log - power of 2)! •  sum! •  min! •  max!
  35. DTrace and Perl DTrace and Perl!

  36. DTrace and Perl Mac OS X vendor perl ships with

    DTrace.!
  37. DTrace and Perl Build your own with perlbrew perlbrew install

    \ perl-5.18.0 \ --as 5.18-dtrace \ -Dusedtrace
  38. DTrace and Perl Build your own with perlbrew perlbrew install

    \ perl-5.18.0 \ --as 5.18-dtrace \ -Dusedtrace
  39. 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!
  40. DTrace and Perl sub-entry! sub-return! (SUBNAME, FILE, LINE, PACKAGE)

  41. DTrace and Perl phase-change! (NEWPHASE, OLDPHASE)

  42. 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.!
  43. 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)!
  44. DTrace and Perl Make your own DTrace probes in Perl

    by using ! ! Devel::DTrace::Provider! !
  45. DTrace and Perl Sample use cases:! •  Trace when you

    hit your DBI handle.! •  Trace when you connect to a socket.! •  Lots of other possibilities.! !
  46. Resources DTrace resources:! •  perldoc dtrace •  http://dtracehol.com/#Intro •  http://dtrace.org/guide/preface.html

    •  http://dtracebook.com/index.php/ Languages#Perl •  http://www.amazon.com/dp/0132091518
  47. Thanks! Thank you!!