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.
2: Also see [DTrace Introduction](http://dtrace.org/guide/preface.html), Brendan Gregg's [DTrace one liners](http://www.brendangregg.com/DTrace/dtrace_oneliners.txt) and his notes for [DTrace on FreeBSD](https://wiki.freebsd.org/DTrace/).
3:
4: # Current status
5:
6: ## Supported platforms
7:
8: DTrace is a work-in-progress effort and it is for x86 systems and some arm boards.
9:
10: * i386 and amd64
11: * earm* (evbarm and armv4 based ports)
12:
13: ## Supported providers
14:
15: * SDT: Statically Defined Tracing
16: * FBT: Function Boundary Tracing
17: * Lockstat: Kernel Lock Statistics
18: * Profile: Time based interrupt event source for Profiling
19: * Syscall: System Calls
20: * Syscall Linux (32bit & 64 bit): System calls via the Linux binary emulation layer
21:
22: ## TODO for netbsd-7
23:
24: * Measure effect of `options KDTRACE_HOOKS` on system performance.
25: * Determine whether the profile module works and list it here.
26: * Integrate [[riz|users/riz]]'s syscall provider patch.
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:
35: # How to use
36:
37: ## Building DTrace
38:
39: You need the following options in your kernel:
40:
41: options KDTRACE_HOOKS # kernel DTrace hooks
42: options MODULAR
43:
44: Optionally:
45:
46: options INSECURE # permit modules to loaded from user space once system has gone multiuser and securelevel has been raised.
47:
48: A Distribution needs to be built with the options `MKDTRACE=yes` and `MKCTF=yes`, this is taken care of automatically and doesn't need to be specified manually. The list of platforms it is applied to automatically is set in `src/share/mk/bsd.own.mk`
49:
50: Set the system to load the solaris and dtrace related modules in `/etc/modules.conf`, for a list of available modules, see `/stand/$MACHINE/$VERSION/modules/`
51:
52: For example, add the following to `/etc/modules.conf` (the file may not exist already on a system):
53:
54: - `solaris`
55: - `dtrace`
56: - `dtrace_sdt`
57: - `dtrace_fbt`
58: - `dtrace_lockstat`
59: - `dtrace_profile`
60: - `dtrace_syscall`
61:
62: A `dtrace` device node is created automatically in `/dev/dtrace` when the modules are loaded into place.
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: ## Running hello world
89:
90: Put the following into the file hello.d:
91:
92: BEGIN
93: {
94: trace("Hello world");
95: exit(0);
96: }
97:
98:
99: Run the hello world script:
100:
101: dtrace -s hello.d
102:
103: dtrace: script './hello.d' matched 1 probe
104: CPU ID FUNCTION:NAME
105: 0 1 :BEGIN Hello world
106:
107:
108: ## A more complex example
109:
110: The following script traces the execution of a sleep operation
111: in the kernel. Put it in sleep.d:
112:
113: #pragma D option flowindent
114:
115: syscall::nanosleep:entry
116: /execname == "sleep" && guard++ == 0/
117: {
118: self->traceme = 1;
119: }
120:
121: fbt:::
122: /self->traceme/
123: {}
124:
125: syscall::nanosleep:return
126: /self->traceme/
127: {
128: self->traceme = 0;
129: exit(0);
130: }
131:
132: Start the script running:
133:
134: dtrace -s sleep.d
135:
136: This will take a while as the script instruments every function in the
137: kernel. When it's ready, it will print a message like "dtrace: script
138: 'sleep.d' matched 59268 probes". Then execute a "sleep 2" in another
139: shell.
140:
141: ## Tools included base
142:
143: Starting with NetBSD-8, on builds where `MKDTRACE=yes` is set, scripts from
144: [Brendan Gregg's DTrace toolkit](https://github.com/opendtrace/toolkit/) are installed in base as standard.
145:
146: At present, the following scripts are installed in `/usr/sbin`:
147:
148: - `dtruss` - An implementation of the truss utility in DTrace which traces the system calls
149: made by a process
150: - `execsnoop` - snoop on execution of processes as they occur
151: - `opensnoop` - snoop on openning of files as they occur
152: - `procsystime` - print process system call time details.
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb