Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
DTrace and Perl
What is DTrace?
 DTrace is a comprehensive dynamic tracing
   framework for Solaris™ and Mac OS X™.


DTrace provides a po...
Problem: Debugging a Live System
Possible Approaches
         Userspace:
•        Ad-hoc logging
•           Log4perl
•           Debugger

        Kernel ...
Or use DTrace...
#!/usr/sbin/dtrace -Zs
# pl_subcalls.d

#pragma D option quiet

dtrace:::BEGIN
{
   printf(quot;Tracing... Hit Ctrl-C to e...
#!/usr/bin/perl

use strict;
use warnings;

sub fib {
    my $n = shift;
    return 1 if $n < 2;
    return fib( $n - 1 ) ...
FILE          SUB      CALLS
strict.pm     bits         1
strict.pm     import       1
warnings.pm   import       1
fib.pl...
DTrace is...

•Fast
•Unobtrusive
•Safe
Current Tools
DTrace
DTrace in Perl

•         In 5.11.0 now

•   Patch available for 5.10.0

•     Can patch older Perls

•     See also Devel...
Probes Available


•    Subroutine Entry

•     Subroutine Exit
Probes Possible

•    Regex Compilation

•        eval / die

•   Anything you like...
DTrace in Perl is fast
   ===========================( subs )=
   standard   | dtrace     | ratio
   =====================...
DTrace Limitations

•     Perl stack traces

•         Perl data

•     Limited Platforms

•       Probe Effect
Where is DTrace?
          DTrace runs on:
  Solaris (including OpenSolaris)
          Mac OS (10.5 on)

DTrace could, but...
It’s OK:

 Linux has
SystemTap!
dtrace for Linux
  or something
     similar

(LIKE SYSTEMTAP?)
       - jdub
(NO, LIKE dtrace)
       - VLAD
 (like syste...
quot;That's the difference
between a knockoff and
 the genuine article.quot;
  Adam Leventhal, DTrace developer, Sun
Who made DTrace?
Mike      Bryan     Adam
Shapiro   Cantrill Leventhal
Andy Armstrong
  andy@hexten.net
http://hexten.net/
20082501 Leeds Pm
20082501 Leeds Pm
Upcoming SlideShare
Loading in …5
×

20082501 Leeds Pm

1,426 views

Published on

A presentation given to Leeds Perl Mongers on the subject of DTrace integration with Perl.

Published in: Technology, Business
  • Be the first to comment

20082501 Leeds Pm

  1. 1. DTrace and Perl
  2. 2. What is DTrace? DTrace is a comprehensive dynamic tracing framework for Solaris™ and Mac OS X™. DTrace provides a powerful infrastructure to permit administrators, developers, and service personnel to concisely answer arbitrary questions about the behaviour of the operating system and user programs.
  3. 3. Problem: Debugging a Live System
  4. 4. Possible Approaches Userspace: • Ad-hoc logging • Log4perl • Debugger Kernel space: • strace • ltrace • truss
  5. 5. Or use DTrace...
  6. 6. #!/usr/sbin/dtrace -Zs # pl_subcalls.d #pragma D option quiet dtrace:::BEGIN { printf(quot;Tracing... Hit Ctrl-C to end.nquot;); } perl*:::sub-entry { @subs[basename(copyinstr(arg1)), copyinstr(arg0)] = count(); } dtrace:::END { printf(quot; %-32s %-32s %8snquot;, quot;FILEquot;, quot;SUBquot;, quot;CALLSquot;); printa(quot; %-32s %-32s %@8dnquot;, @subs); }
  7. 7. #!/usr/bin/perl use strict; use warnings; sub fib { my $n = shift; return 1 if $n < 2; return fib( $n - 1 ) + fib( $n - 2 ); } print fib( 12 );
  8. 8. FILE SUB CALLS strict.pm bits 1 strict.pm import 1 warnings.pm import 1 fib.pl BEGIN 2 fib.pl fib 465
  9. 9. DTrace is... •Fast •Unobtrusive •Safe
  10. 10. Current Tools
  11. 11. DTrace
  12. 12. DTrace in Perl • In 5.11.0 now • Patch available for 5.10.0 • Can patch older Perls • See also Devel::DTrace
  13. 13. Probes Available • Subroutine Entry • Subroutine Exit
  14. 14. Probes Possible • Regex Compilation • eval / die • Anything you like...
  15. 15. DTrace in Perl is fast ===========================( subs )= standard | dtrace | ratio ==================================== 2.64732909 | 2.55084610 | 0.96355459 2.59817791 | 2.54752493 | 0.98050442 2.62265491 | 2.53197598 | 0.96542476 2.60479188 | 2.54577494 | 0.97734293 2.58312511 | 2.54531789 | 0.98536377 ==================================== dtrace | standard | ratio ==================================== 2.55562115 | 2.61360312 | 0.97781531 2.51933718 | 2.59808207 | 0.96969115 2.51130199 | 2.61182499 | 0.96151235 2.55779004 | 2.62898207 | 0.97292031 2.54250908 | 2.60577297 | 0.97572164 ====================================
  16. 16. DTrace Limitations • Perl stack traces • Perl data • Limited Platforms • Probe Effect
  17. 17. Where is DTrace? DTrace runs on: Solaris (including OpenSolaris) Mac OS (10.5 on) DTrace could, but doesn’t, run on: Linux FreeBSD Windows
  18. 18. It’s OK: Linux has SystemTap!
  19. 19. dtrace for Linux or something similar (LIKE SYSTEMTAP?) - jdub (NO, LIKE dtrace) - VLAD (like systemtap, but not crap) Seen on a whiteboard at OSCON
  20. 20. quot;That's the difference between a knockoff and the genuine article.quot; Adam Leventhal, DTrace developer, Sun
  21. 21. Who made DTrace?
  22. 22. Mike Bryan Adam Shapiro Cantrill Leventhal
  23. 23. Andy Armstrong andy@hexten.net http://hexten.net/

×