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