Diff for /wikisrc/tutorials/how_to_enable_and_run_dtrace.mdwn between versions 1.1 and 1.15

version 1.1, 2011/11/20 20:55:21 version 1.15, 2017/03/22 15:43:09
Line 1 Line 1
 DTrace is a Dynamic Tracing framework developed by Sun and ported to NetBSD. It enables extensive instrumentation of the kernel and user space. See the [DTrace Community Page](http://hub.opensolaris.org/bin/view/Community+Group+dtrace/WebHome) for more information. Also see [DTrace Introduction](http://wikis.sun.com/display/DTrace/Introduction).  DTrace is a Dynamic Tracing framework developed by Sun and ported to NetBSD. It enables extensive instrumentation of the kernel and user space. See the [DTrace Community Page](http://dtrace.org) for more information.
   Also see [DTrace Introduction](http://dtrace.org/guide/preface.html), Brendan Gregg's [DTrace one liners](http://www.brendangregg.com/DTrace/dtrace_oneliners.txt) and his notes for [DTrace on FreeBSD](https://wiki.freebsd.org/DTrace/).
   
 DTrace is a work-in-progress effort and it is for i386 systems only. Two providers are available; the Statically Defined Tracing (SDT) provider and the Function Boundary Tracer (FBT) provider.  # Current status
   
 You can currently run a hello world DScript.  ## Supported platforms
   
 ##  Building DTrace  DTrace is a work-in-progress effort and it is for x86 systems and some arm boards.
   
 You need the following options in your kernel:  * i386 and amd64
      * earm* (evbarm and armv4 based ports (armv4 side requires further testing but system is built with CTF)
     options         INSECURE  
     options         KDTRACE_HOOKS   # DTrace support  ## Supported providers
     options         MODULAR  
      * SDT: Statically Defined Tracing
   * FBT: Function Boundary Tracing
 You also need to build distribution with the options MKMODULAR=yes and MKDTRACE=yes.  * Lockstat: Kernel Lock Statistics
   * Profile: Time based interrupt event source for Profiling
 ##  Running hello world  * Syscall: System Calls
   * Syscall Linux (32bit & 64 bit): System calls via the Linux binary emulation layer
 Load the solaris and dtrace modules, and the SDT (Statically Defined Tracing) and FBT (Function Boundary Tracing) modules:  
      ## TODO for netbsd-7
     modload solaris  
     modload dtrace  * Measure effect of `options KDTRACE_HOOKS` on system performance.
     modload sdt  * Determine whether the profile module works and list it here.
     modload fbt  * Integrate [[riz|users/riz]]'s syscall provider patch.
      
   ## TODO for netbsd-6
 Make the dtrace device node:  
      Need to identify changes to pull up to netbsd-6 and pull them up.
     mkdir /dev/dtrace  Candidates:
     mknod /dev/dtrace/dtrace c dtrace 0  
      * Profile provider.
   
 List the dtrace probes  # How to use
      
     dtrace -l  ##  Building DTrace 
      
        ID   PROVIDER            MODULE                          FUNCTION NAME  You need the following options in your kernel: 
         1     dtrace                                                     BEGIN      
         2     dtrace                                                     END      options         KDTRACE_HOOKS   # kernel DTrace hooks
         3     dtrace                                                     ERROR      options         MODULAR
         4        fbt            netbsd             AcpiAcquireGlobalLock entry  
         5        fbt            netbsd             AcpiAcquireGlobalLock return  Optionally:
         6        fbt            netbsd             AcpiAllocateRootTable entry      options         INSECURE   # permit modules to loaded from user space once system has gone multiuser and securelevel has been raised.
         7        fbt            netbsd                    AcpiAttachData entry  
         .  A Distribution needs to be built with the options `MKDTRACE=yes` and `MKCTF=yes`, this is taken care of automatically and doesn't need to be specified manually. The list of platforms it is applied to automatically is set in `src/share/mk/bsd.own.mk`
         .  
     29129        fbt           solaris                   zfs_vop_getattr entry  Set the system to load the solaris and dtrace related modules in `/etc/modules.conf`, for a list of available modules, see `/stand/$MACHINE/$VERSION/modules/`
     29130        fbt           solaris                   zfs_vop_getattr return      
     29131       proc                                                     create      solaris
     29132       proc                                                     exec      dtrace
         .      dtrace_sdt
         .      dtrace_fbt
     29140       proc                                                     lwp_start      dtrace_lockstat
     29141       proc                                                     lwp_exit      dtrace_profile
          dtrace_syscall
       
    A `dtrace` device node is created automatically in `/dev/dtrace` when the modules are loaded into place.
       
   List the dtrace probes 
 Put the following into the file hello.d      
          dtrace -l
     BEGIN      
     {         ID   PROVIDER            MODULE                          FUNCTION NAME
         trace("Hello world");          1     dtrace                                                     BEGIN
         exit(0);          2     dtrace                                                     END
     }          3     dtrace                                                     ERROR
              4        fbt            netbsd             AcpiAcquireGlobalLock entry
           5        fbt            netbsd             AcpiAcquireGlobalLock return
 Run the hello world script:          6        fbt            netbsd             AcpiAllocateRootTable entry
              7        fbt            netbsd                    AcpiAttachData entry
     dtrace -s hello.d          . 
              .
     dtrace: script './hello.d' matched 1 probe      29129        fbt           solaris                   zfs_vop_getattr entry 
     CPU     ID                    FUNCTION:NAME      29130        fbt           solaris                   zfs_vop_getattr return
       0      1                           :BEGIN   Hello world      29131       proc                                                     create
          29132       proc                                                     exec 
           .
 A more complex example that traces the execution of a sleep operation in the kernel:          .
          29140       proc                                                     lwp_start
     #pragma D option flowindent      29141       proc                                                     lwp_exit
      
     fbt::syscall:entry  
     /execname == "sleep" && guard++ == 0/  ##  Running hello world 
     {  
             self->traceme = 1;  Put the following into the file hello.d:
             printf("fd: %d", arg0);      
     }      BEGIN
          {
     fbt:::          trace("Hello world");
     /self->traceme/          exit(0);
     {}      }
          
     fbt::syscall:return  
     /self->traceme/  Run the hello world script: 
     {      
             self->traceme = 0;      dtrace -s hello.d
             exit(0);      
     }      dtrace: script './hello.d' matched 1 probe
          CPU     ID                    FUNCTION:NAME
         0      1                           :BEGIN   Hello world
 Start the script running (dtrace -s <scriptname.d>) and then execute a sleep 2 in another shell.      
   
   A more complex example that traces the execution of a sleep operation
   in the kernel. Put it in sleep.d:
       
       #pragma D option flowindent
       
       fbt::syscall:entry
       /execname == "sleep" && guard++ == 0/
       {
               self->traceme = 1;
               printf("fd: %d", arg0);
       }
       
       fbt::syscall:entry /self->traceme/ {}
       
       fbt::syscall:return
       /self->traceme/
       {
               self->traceme = 0;
               exit(0);
       }
       
   
   Start the script running (dtrace -s sleep.d) and then execute a "sleep 2" in another shell. 

Removed from v.1.1  
changed lines
  Added in v.1.15


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb