File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_enable_and_run_dtrace.mdwn
Revision 1.11: download - view: text, annotated - select for diffs
Thu Sep 18 15:05:39 2014 UTC (5 years, 10 months ago) by wiz
Branches: MAIN
CVS tags: HEAD
Use existing MAKEDEV dtrace target to create nodes.

    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: * Integrate [[riz|users/riz]]'s syscall provider patch.
   26: 
   27: ## TODO for netbsd-6
   28: 
   29: Need to identify changes to pull up to netbsd-6 and pull them up.
   30: Candidates:
   31: 
   32: * Profile provider.
   33: 
   34: # How to use
   35: 
   36: ##  Building DTrace 
   37: 
   38: You need the following options in your kernel: 
   39:     
   40:     options         INSECURE
   41:     options         KDTRACE_HOOKS   # kernel DTrace hooks
   42:     options         MODULAR
   43:     
   44: 
   45: You also need to build distribution with the options MKDTRACE=yes.
   46: 
   47: ##  Running hello world 
   48: 
   49: Load the solaris and dtrace modules, and the SDT (Statically Defined Tracing) and FBT (Function Boundary Tracing) modules: 
   50:     
   51:     modload solaris
   52:     modload dtrace
   53:     modload sdt
   54:     modload fbt
   55:     
   56: 
   57: Make the dtrace device node: 
   58:     
   59:     cd /dev
   60:     sh MAKEDEV dtrace
   61:     
   62: 
   63: List the dtrace probes 
   64:     
   65:     dtrace -l
   66:     
   67:        ID   PROVIDER            MODULE                          FUNCTION NAME
   68:         1     dtrace                                                     BEGIN
   69:         2     dtrace                                                     END
   70:         3     dtrace                                                     ERROR
   71:         4        fbt            netbsd             AcpiAcquireGlobalLock entry
   72:         5        fbt            netbsd             AcpiAcquireGlobalLock return
   73:         6        fbt            netbsd             AcpiAllocateRootTable entry
   74:         7        fbt            netbsd                    AcpiAttachData entry
   75:         . 
   76:         .
   77:     29129        fbt           solaris                   zfs_vop_getattr entry 
   78:     29130        fbt           solaris                   zfs_vop_getattr return
   79:     29131       proc                                                     create
   80:     29132       proc                                                     exec 
   81:         .
   82:         .
   83:     29140       proc                                                     lwp_start
   84:     29141       proc                                                     lwp_exit
   85:     
   86: 
   87:   
   88: 
   89: 
   90: Put the following into the file hello.d:
   91:     
   92:     BEGIN
   93:     {
   94:         trace("Hello world");
   95:         exit(0);
   96:     }
   97:     
   98: 
   99: Run the hello world script: 
  100:     
  101:     dtrace -s hello.d
  102:     
  103:     dtrace: script './hello.d' matched 1 probe
  104:     CPU     ID                    FUNCTION:NAME
  105:       0      1                           :BEGIN   Hello world
  106:     
  107: 
  108: A more complex example that traces the execution of a sleep operation
  109: in the kernel. Put it in sleep.d:
  110:     
  111:     #pragma D option flowindent
  112:     
  113:     fbt::syscall:entry
  114:     /execname == "sleep" && guard++ == 0/
  115:     {
  116:             self->traceme = 1;
  117:             printf("fd: %d", arg0);
  118:     }
  119:     
  120:     fbt::syscall:entry /self->traceme/ {}
  121:     
  122:     fbt::syscall:return
  123:     /self->traceme/
  124:     {
  125:             self->traceme = 0;
  126:             exit(0);
  127:     }
  128:     
  129: 
  130: 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