File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_enable_and_run_dtrace.mdwn
Revision 1.12: download - view: text, annotated - select for diffs
Thu Sep 18 19:46:11 2014 UTC (5 years, 10 months ago) by wiz
Branches: MAIN
CVS tags: HEAD
dtrace module renaming done.

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