dtrace_open() Function

The dtrace_open() function opens the DTrace driver and returns a handle to the consumer, which can be used for subsequent interactions with DTrace. dtrace_hdl_t is an opaque data structure that contains all the information related to the invocation of DTrace. The DTrace handle is passed to the other libdtrace functions, but a consumer does not need to access individual members of the dtrace_hdl_t structure.

dtrace_hdl_t *dtrace_open(int version, int flags, int *errp)

The arguments to the dtrace_open() function are:

  • The DTrace version in use, DTRACE_VERSION. Specifying any version other than the current version causes DTrace to fail.

  • Flags. The available flags are:

    DTRACE_O_NODEV

    Does not open the DTrace device. This flag is used when instrumentation is not enabled. For example, the -G option to dtrace generates an ELF file that contain an embedded D program but does not enable the specified probes.

    DTRACE_O_NOSYS

    Does not load the /system/object modules. By default, the libdtrace library gathers information about each of the loaded kernel modules. This flag is also used in a typical consumer.

    DTRACE_O_LP64

    Forces the D compiler to be 64-bit.

    DTRACE_O_ILP32

    Forces the D compiler to be 32-bit.

  • A pass-by-reference error variable. The dtrace_errmsg() function uses the value passed back by this variable to generate an error string.

In Embedding DTrace in a Consumer, the consumer first calls the dtrace_open() function to open the DTrace driver and return the DTrace handle.