File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_enable_and_run_dtrace.mdwn
Revision 1.5: download - view: text, annotated - select for diffs
Thu Apr 3 11:55:12 2014 UTC (6 years, 4 months ago) by wiki
Branches: MAIN
CVS tags: HEAD
web commit by ozakir: Write about ARM support

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

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