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 for more information. Also see DTrace Introduction, Brendan Gregg's DTrace one liners and his notes for DTrace on FreeBSD.

Current status

Supported platforms

DTrace is a work-in-progress effort and it is for x86 systems and some arm boards.

Supported providers

TODO for netbsd-7

TODO for netbsd-6

Need to identify changes to pull up to netbsd-6 and pull them up. Candidates:

How to use

Building DTrace

You need the following options in your kernel:

options         KDTRACE_HOOKS   # kernel DTrace hooks
options         MODULAR

Optionally:

options         INSECURE   # permit modules to loaded from user space once system has gone multiuser and securelevel has been raised.

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/

For example, add the following to /etc/modules.conf (the file may not exist already on a system):

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

   ID   PROVIDER            MODULE                          FUNCTION NAME
    1     dtrace                                                     BEGIN
    2     dtrace                                                     END
    3     dtrace                                                     ERROR
    4        fbt            netbsd             AcpiAcquireGlobalLock entry
    5        fbt            netbsd             AcpiAcquireGlobalLock return
    6        fbt            netbsd             AcpiAllocateRootTable entry
    7        fbt            netbsd                    AcpiAttachData entry
    . 
    .
29129        fbt           solaris                   zfs_vop_getattr entry 
29130        fbt           solaris                   zfs_vop_getattr return
29131       proc                                                     create
29132       proc                                                     exec 
    .
    .
29140       proc                                                     lwp_start
29141       proc                                                     lwp_exit

Running hello world

Put the following into the file hello.d:

BEGIN
{
    trace("Hello world");
    exit(0);
}

Run the hello world script:

dtrace -s hello.d

dtrace: script './hello.d' matched 1 probe
CPU     ID                    FUNCTION:NAME
  0      1                           :BEGIN   Hello world

A more complex example that traces the execution of a sleep operation in the kernel. Put it in sleep.d:

#pragma D option flowindent

fbt::syscall:entry
/execname == "sleep" && guard++ == 0/
{
        self->traceme = 1;
        printf("fd: %d", arg0);
}

fbt::syscall:entry /self->traceme/ {}

fbt::syscall:return
/self->traceme/
{
        self->traceme = 0;
        exit(0);
}

Start the script running (dtrace -s sleep.d) and then execute a "sleep 2" in another shell.

(NetBSD 7.0 i386)

please fix.

add to build.sh option:

-V SLOPPY_FLIST=yes 

modload command miss. Properly do this:

modload solaris
modload dtrace
modload sdt
modload fbt
modload profile
Comment by miwarin Thursday afternoon, May 5th, 2016
Add a comment
Contact | Disclaimer | Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.
NetBSD® is a registered trademark of The NetBSD Foundation, Inc.