perl, DTrace and you

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

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

Jade Allen

June 04, 2013

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

47 slides
  1. DTrace, Perl and you! ! ! Mark Allen! [email protected]! @bytemeorg!

    http://byte-me.org! https://github.com/mrallen1! https://metacpan.org/author/MALLEN!
  2. DTrace Basics Dynamic versus! warn Dumper $object if $debug; print

    "got here!\n"; my $start = time(); do_stuff(); my $elapsed = time() - $start;
  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, perl and

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

    perl 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 subentry.d #!/usr/sbin/dtrace -qFZs sub-entry, sub-return

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

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

    { /* arg0 is subroutine name */ trace(copyinstr(arg0)) }
  12. 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) }
  13. 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) }
  14. 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) }
  15. 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) }
  16. D Language Basics Common aggregation functions! •  avg! •  count!

    •  lquantize (linear)! •  quantize (log - power of 2)! •  sum! •  min! •  max!
  17. DTrace and Perl Build your own with perlbrew perlbrew install

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

    \ perl-5.18.0 \ --as 5.18-dtrace \ -Dusedtrace
  19. 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!
  20. 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.!
  21. 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)!
  22. DTrace and Perl Make your own DTrace probes in Perl

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

    hit your DBI handle.! •  Trace when you connect to a socket.! •  Lots of other possibilities.! !
  24. 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

More Decks by Jade Allen

Other Decks in Technology