File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_enable_and_run_dtrace.mdwn
Revision 1.9: download - view: text, annotated - select for diffs
Wed Sep 10 20:42:10 2014 UTC (5 years, 11 months ago) by wiz
Branches: MAIN
CVS tags: HEAD
Fix example. From Tyler.
Make steps more explicit.

    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://dtrace.org) for more information. Also see [DTrace Introduction](http://dtrace.org/guide/preface.html). 
    2: 
    3: # Current status
    4: 
    5: ## Supported platforms
    6: 
    7: DTrace is a work-in-progress effort and it is for x86 systems and some arm boards.
    8: 
    9: * i386 and amd64
   10: * evbarm
   11:     * BEAGLEBONE and SHEEVAPLUG
   12: 
   13: ## Supported providers
   14: 
   15: * SDT: Statically Defined Tracing
   16: * FBT: Function Boundary Tracing
   17: 
   18: You can currently run a hello world DScript. 
   19: 
   20: ## TODO for netbsd-7
   21: 
   22: * Rename provider modules to `dtrace_*.kmod`: `dtrace_fbt.kmod`, &c.
   23: * Measure effect of `options KDTRACE_HOOKS` on system performance.
   24: * Determine whether the profile module works and list it here.
   25: * Put a dtrace target in /dev/MAKEDEV.
   26: * Integrate [[riz|users/riz]]'s syscall provider patch.
   27: 
   28: ## TODO for netbsd-6
   29: 
   30: Need to identify changes to pull up to netbsd-6 and pull them up.
   31: Candidates:
   32: 
   33: * Profile provider.
   34: 
   35: # How to use
   36: 
   37: ##  Building DTrace 
   38: 
   39: You need the following options in your kernel: 
   40:     
   41:     options         INSECURE
   42:     options         KDTRACE_HOOKS   # DTrace support
   43:     options         MODULAR
   44:     
   45: 
   46: You also need to build distribution with the options MKDTRACE=yes.
   47: 
   48: ##  Running hello world 
   49: 
   50: Load the solaris and dtrace modules, and the SDT (Statically Defined Tracing) and FBT (Function Boundary Tracing) modules: 
   51:     
   52:     modload solaris
   53:     modload dtrace
   54:     modload sdt
   55:     modload fbt
   56:     
   57: 
   58: Make the dtrace device node: 
   59:     
   60:     mkdir /dev/dtrace
   61:     mknod /dev/dtrace/dtrace c dtrace 0
   62:     
   63: 
   64: List the dtrace probes 
   65:     
   66:     dtrace -l
   67:     
   68:        ID   PROVIDER            MODULE                          FUNCTION NAME
   69:         1     dtrace                                                     BEGIN
   70:         2     dtrace                                                     END
   71:         3     dtrace                                                     ERROR
   72:         4        fbt            netbsd             AcpiAcquireGlobalLock entry
   73:         5        fbt            netbsd             AcpiAcquireGlobalLock return
   74:         6        fbt            netbsd             AcpiAllocateRootTable entry
   75:         7        fbt            netbsd                    AcpiAttachData entry
   76:         . 
   77:         .
   78:     29129        fbt           solaris                   zfs_vop_getattr entry 
   79:     29130        fbt           solaris                   zfs_vop_getattr return
   80:     29131       proc                                                     create
   81:     29132       proc                                                     exec 
   82:         .
   83:         .
   84:     29140       proc                                                     lwp_start
   85:     29141       proc                                                     lwp_exit
   86:     
   87: 
   88:   
   89: 
   90: 
   91: Put the following into the file hello.d:
   92:     
   93:     BEGIN
   94:     {
   95:         trace("Hello world");
   96:         exit(0);
   97:     }
   98:     
   99: 
  100: Run the hello world script: 
  101:     
  102:     dtrace -s hello.d
  103:     
  104:     dtrace: script './hello.d' matched 1 probe
  105:     CPU     ID                    FUNCTION:NAME
  106:       0      1                           :BEGIN   Hello world
  107:     
  108: 
  109: A more complex example that traces the execution of a sleep operation
  110: in the kernel. Put it in sleep.d:
  111:     
  112:     #pragma D option flowindent
  113:     
  114:     fbt::syscall:entry
  115:     /execname == "sleep" && guard++ == 0/
  116:     {
  117:             self->traceme = 1;
  118:             printf("fd: %d", arg0);
  119:     }
  120:     
  121:     fbt::syscall:entry /self->traceme/ {}
  122:     
  123:     fbt::syscall:return
  124:     /self->traceme/
  125:     {
  126:             self->traceme = 0;
  127:             exit(0);
  128:     }
  129:     
  130: 
  131: Start the script running (dtrace -s sleep.d) and then execute a "sleep 2" in another shell. 

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