Annotation of wikisrc/tutorials/how_to_enable_and_run_dtrace.mdwn, revision 1.12
1.4 wiki 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).
1.2 schmonz 2:
1.5 wiki 3: # Current status
1.2 schmonz 4:
1.5 wiki 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
1.2 schmonz 17:
18: You can currently run a hello world DScript.
19:
1.6 riastrad 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.
1.7 riastrad 24: * Integrate [[riz|users/riz]]'s syscall provider patch.
1.6 riastrad 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:
1.5 wiki 33: # How to use
34:
1.2 schmonz 35: ## Building DTrace
36:
37: You need the following options in your kernel:
38:
39: options INSECURE
1.10 wiz 40: options KDTRACE_HOOKS # kernel DTrace hooks
1.2 schmonz 41: options MODULAR
42:
43:
1.8 riastrad 44: You also need to build distribution with the options MKDTRACE=yes.
1.2 schmonz 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
1.12 ! wiz 52: modload dtrace_sdt
! 53: modload dtrace_fbt
1.2 schmonz 54:
55:
56: Make the dtrace device node:
57:
1.11 wiz 58: cd /dev
59: sh MAKEDEV dtrace
1.2 schmonz 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:
1.9 wiz 89: Put the following into the file hello.d:
1.2 schmonz 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:
1.9 wiz 107: A more complex example that traces the execution of a sleep operation
108: in the kernel. Put it in sleep.d:
1.2 schmonz 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:
1.9 wiz 119: fbt::syscall:entry /self->traceme/ {}
1.2 schmonz 120:
121: fbt::syscall:return
122: /self->traceme/
123: {
124: self->traceme = 0;
125: exit(0);
126: }
127:
128:
1.9 wiz 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