Go to main content

man pages section 3: Library Interfaces and Headers

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

libdtrace(3LIB)

Name

libdtrace - DTrace dynamic tracing software library

Synopsis

cc [ flag... ] file... –ldtrace [ library... ]
#include <dtrace.h>

Description

Functions in this library define the interface for interacting with the DTrace dynamic tracing software, including the D language compiler and facilities for enabling probes and consuming trace data.

INTERFACES

The interfaces provided by libdtrace.so.1 are currently private to the implementation of the Oracle Solaris system and DTrace subsystem and are subject to change at any time without notice. Applications using these interfaces might fail to run on future releases. For more information, see the Oracle Solaris 11.4 DTrace (Dynamic Tracing) Guide for a description of the public documented interfaces available for the DTrace facility.

     dtrace_addr2str                      	dtrace_lookup_by_type
     dtrace_aggregate_clear               	dtrace_object_info
     dtrace_aggregate_print               	dtrace_object_iter
     dtrace_aggregate_snap                	dtrace_open
     dtrace_aggregate_walk                	dtrace_printa_create
     dtrace_aggregate_walk_joined         	dtrace_printf_create
     dtrace_aggregate_walk_keyrevsorted   	dtrace_printf_format
     dtrace_aggregate_walk_keysorted      	dtrace_probe_info
     dtrace_aggregate_walk_keyvarrevsorted	dtrace_probe_iter
     dtrace_aggregate_walk_keyvarsorted   	dtrace_proc_continue
     dtrace_aggregate_walk_sorted         	dtrace_proc_create
     dtrace_aggregate_walk_valrevsorted   	dtrace_proc_grab
     dtrace_aggregate_walk_valsorted      	dtrace_proc_release
     dtrace_aggregate_walk_valvarrevsorted	dtrace_program_exec
     dtrace_aggregate_walk_valvarsorted   	dtrace_program_fcompile
     dtrace_attr2str                      	dtrace_program_header
     dtrace_class_name                    	dtrace_program_info
     dtrace_close                         	dtrace_program_link
     dtrace_consume                       	dtrace_program_strcompile
     dtrace_ctlfd                         	dtrace_provider_modules
     dtrace_desc2str                      	dtrace_setopt
     dtrace_dof_create                    	dtrace_sleep
     dtrace_dof_destroy                   	dtrace_sprintf
     dtrace_errmsg                        	dtrace_stability_name
     dtrace_errno                         	dtrace_status
     dtrace_faultstr                      	dtrace_stmt_action
     dtrace_fire_extern                   	dtrace_stmt_add
     dtrace_format_lookup                 	dtrace_stmt_create
     dtrace_fprinta                       	dtrace_stmt_destroy
     dtrace_fprintf                       	dtrace_stmt_iter
     dtrace_freopen                       	dtrace_stop
     dtrace_getctf_dof                    	dtrace_str2attr
     dtrace_geterr_dof                    	dtrace_str2desc
     dtrace_getopt                        	dtrace_subrstr
     dtrace_getopt_dof                    	dtrace_symbol_type
     dtrace_go                            	dtrace_system
     dtrace_handle_buffered               	dtrace_type_fcompile
     dtrace_handle_drop                   	dtrace_type_strcompile
     dtrace_handle_err                    	dtrace_uaddr2str
     dtrace_handle_proc                   	dtrace_update
     dtrace_handle_setopt                 	dtrace_vopen
     dtrace_id2desc                       	dtrace_work
     dtrace_lookup_by_addr                	dtrace_xstr2desc
     dtrace_lookup_by_name

Files

/lib/libdtrace.so.1

shared object

/lib/64/libdtrace.so.1

64-bit shared object

Examples

Example 1 Simple DTrace Consumer
#include <dtrace.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

	static dtrace_hdl_t *g_dtp;

	static void
	fatal(const char *fmt, ...)
	{
		va_list ap;

		va_start(ap, fmt);
		(void) vfprintf(stderr, fmt, ap);

		if (fmt[strlen(fmt) - 1] != '\n')
			(void) fprintf(stderr, ": %s\n",
			    dtrace_errmsg(g_dtp, dtrace_errno(g_dtp)));

		exit(EXIT_FAILURE);
	}

	static int
	chewrec(const dtrace_probedata_t *data, const dtrace_recdesc_t *rec,
	    void *arg)
	{
		dtrace_actkind_t act;

		if (rec == NULL)
			return (DTRACE_CONSUME_NEXT);

		act = rec->dtrd_action;

		if (act == DTRACEACT_EXIT)
			return (DTRACE_CONSUME_NEXT);

		return (DTRACE_CONSUME_THIS);
	}

	static int
	chew(const dtrace_probedata_t *data, void *arg)
	{
		return (DTRACE_CONSUME_THIS);
	}

	int
	main(int argc, char **argv)
	{
		dtrace_prog_t *prog;
		dtrace_proginfo_t info;
		int err;
		FILE *fp;

		if ((g_dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL)
			fatal("cannot open dtrace library: %s\n",
			    dtrace_errmsg(NULL, err));

		if ((fp = fopen(argv[1], "r")) == NULL)
			fatal("cannot open %s\n", argv[1]);

		if ((prog = dtrace_program_fcompile(g_dtp, fp, 0, 0,
		    NULL)) == NULL)
			fatal("invalid program");

		if (dtrace_program_exec(g_dtp, prog, &info) == -1)
			fatal("failed to enable probes");

		if (dtrace_setopt(g_dtp, "bufsize", "512k") == -1)
			fatal("failed to set bufsize");

		if (dtrace_setopt(g_dtp, "aggsize", "512k") == -1)
			fatal("failed to set aggsize");

		if (dtrace_go(g_dtp) != 0)
			fatal("dtrace_go()");

		while (1) {
			int done = 0;

			dtrace_sleep(g_dtp);

			switch (dtrace_work(g_dtp, stdout, chew, chewrec,
			    NULL)) {
			case DTRACE_WORKSTATUS_DONE:
				done = 1;
				break;

			case DTRACE_WORKSTATUS_OKAY:
				break;

			default:
				fatal("processing aborted");
			}

			if (done)
			    break;
		}

		if (dtrace_status(g_dtp) == -1)
			fatal("dtrace_stop()");

		if (dtrace_stop(g_dtp) == -1)
			fatal("dtrace_stop()");

		if (dtrace_aggregate_print(g_dtp, stdout, NULL) == -1)
			fatal("aggregate processing failed");

		fclose(fp);
		dtrace_close(g_dtp);

		return (0);
	}

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Architecture
all
Availability
system/dtrace
Interface Stability
Committed
MT-Level
Safe

See Also

dtrace(8), attributes(7), intro(3)

Oracle Solaris 11.4 DTrace (Dynamic Tracing) Guide