Just checking for the sys/sdt.h
header isn’t enough, as systems like macOS have the header, but it doesn’t actually have the DTRACE_PROBE*
probes, which leads to compile failures. The contents of sys/sdt.h
in the macOS SDK is:
0#ifndef _SYS_SDT_H
1#define _SYS_SDT_H
2
3/*
4 * This is a wrapper header that wraps the mach visible sdt.h header so that
5 * the header file ends up visible where software expects it to be. We also
6 * do the C/C++ symbol wrapping here, since Mach headers are technically C
7 * interfaces.
8 *
9 * Note: The process of adding USDT probes to code is slightly different
10 * than documented in the "Solaris Dynamic Tracing Guide".
11 * The DTRACE_PROBE*() macros are not supported on Mac OS X -- instead see
12 * "BUILDING CODE CONTAINING USDT PROBES" in the dtrace(1) manpage
13 *
14 */
15#include <sys/cdefs.h>
16__BEGIN_DECLS
17#include <mach/sdt.h>
18__END_DECLS
19
20#endif /* _SYS_SDT_H */
The BUILDING CODE CONTAINING USDT PROBES
section from the dtrace manpage is available here, and outlines the more involved process of using USDT probes on macOS.