My freshly installed FreeBSD9 does not have dtrace? While using it I got this error:
dtrace: failed to initialize dtrace: DTrace device not available on system
Doing a “kldstat” command query, dtrace kernel module was not listed.
And reading further:
http://forums.freebsd.org/showthread.php?t=19385
The answer given was to read:
http://wiki.freebsd.org/DTrace
But that seemed to take too much time, so I start investigating the kernel module – first “cd /boot/kernel” to go to the kernel modules directory:
kldload if_ath
kldload: can't load if_ath: File exists
Oops, this kernel modules is already loaded – as verified via “kldstat”. And just trying another file:
kldload dtrace
kldload dtraceall
No error message, so it seemed by default dtrace-related kernel module are not loaded? Not always, sometimes mismatched errors occurred (eg, after another FreeBSD 8.1 installation), and so rebulding the kernel modules are needed.
Steps are as followed:
cd /usr/src/sys/amd64/conf
cp GENERIC MYDTKERNEL
And inside MYDTKERNEL file:
options KDTRACE_FRAME # Ensure frames are compiled in
options KDTRACE_HOOKS # Kernel DTrace hooks
Other options are instruction to backup the current kernel to /boot/kernel.old and this is not enabled by default – my advice is to enable it.
config MYDTKERNEL
And you will see that ../compile/MYDTKERNEL returned, now cd to this directory and continue the compilation:
make depend
make
make install
Hopefully the above will all work without producing an error. If you get an error, like me, getting and “No space left on device” error, what I do is to move the /boot/kernel.old directory to the /usr directory which still have lots of space left. Next reboot the machine, and do a “kldstat” to check that dtrace is loaded or not, which is not.
cd /boot/kernel
kldload dtrace
kldload dtraceall
References:
http://www.freebsd.org/doc/handbook/kernelconfig-building.html