--- wikisrc/tutorials/how_to_enable_and_run_dtrace.mdwn 2014/08/23 00:33:07 1.6 +++ wikisrc/tutorials/how_to_enable_and_run_dtrace.mdwn 2017/04/08 21:38:18 1.18 @@ -1,4 +1,5 @@ -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). +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), 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/). # Current status @@ -7,22 +8,22 @@ DTrace is a Dynamic Tracing framework de DTrace is a work-in-progress effort and it is for x86 systems and some arm boards. * i386 and amd64 -* evbarm - * BEAGLEBONE and SHEEVAPLUG +* earm* (evbarm and armv4 based ports) ## Supported providers * SDT: Statically Defined Tracing * FBT: Function Boundary Tracing - -You can currently run a hello world DScript. +* Lockstat: Kernel Lock Statistics +* Profile: Time based interrupt event source for Profiling +* Syscall: System Calls +* Syscall Linux (32bit & 64 bit): System calls via the Linux binary emulation layer ## TODO for netbsd-7 -* Rename provider modules to `dtrace_*.kmod`: `dtrace_fbt.kmod`, &c. * Measure effect of `options KDTRACE_HOOKS` on system performance. * Determine whether the profile module works and list it here. -* Put a dtrace target in /dev/MAKEDEV. +* Integrate [[riz|users/riz]]'s syscall provider patch. ## TODO for netbsd-6 @@ -30,7 +31,6 @@ Need to identify changes to pull up to n Candidates: * Profile provider. -* Syscall provider. # How to use @@ -38,29 +38,29 @@ Candidates: You need the following options in your kernel: - options INSECURE - options KDTRACE_HOOKS # DTrace support + options KDTRACE_HOOKS # kernel DTrace hooks options MODULAR - -You also need to build distribution with the options MKMODULAR=yes and MKDTRACE=yes. +Optionally: -## Running hello world + options INSECURE # permit modules to loaded from user space once system has gone multiuser and securelevel has been raised. -Load the solaris and dtrace modules, and the SDT (Statically Defined Tracing) and FBT (Function Boundary Tracing) modules: - - modload solaris - modload dtrace - modload sdt - modload fbt - +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` + +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/` -Make the dtrace device node: +For example, add the following to `/etc/modules.conf` (the file may not exist already on a system): - mkdir /dev/dtrace - mknod /dev/dtrace/dtrace c dtrace 0 + solaris + dtrace + dtrace_sdt + dtrace_fbt + dtrace_lockstat + dtrace_profile + dtrace_syscall + +A `dtrace` device node is created automatically in `/dev/dtrace` when the modules are loaded into place. - List the dtrace probes dtrace -l @@ -83,12 +83,11 @@ List the dtrace probes . 29140 proc lwp_start 29141 proc lwp_exit - - +## Running hello world -Put the following into the file hello.d +Put the following into the file hello.d: BEGIN { @@ -106,7 +105,8 @@ Run the hello world script: 0 1 :BEGIN Hello world -A more complex example that traces the execution of a sleep operation in the kernel: +A more complex example that traces the execution of a sleep operation +in the kernel. Put it in sleep.d: #pragma D option flowindent @@ -117,9 +117,7 @@ A more complex example that traces the e printf("fd: %d", arg0); } - fbt::: - /self->traceme/ - {} + fbt::syscall:entry /self->traceme/ {} fbt::syscall:return /self->traceme/ @@ -129,4 +127,4 @@ A more complex example that traces the e } -Start the script running (dtrace -s ) and then execute a sleep 2 in another shell. +Start the script running (dtrace -s sleep.d) and then execute a "sleep 2" in another shell.