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