xref: /titanic_41/usr/src/lib/libtnfprobe/tnf_trace.h (revision 6185db853e024a486ff8837e6784dd290d866112)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *      Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #ifndef _TNF_TRACE_H
27 #define	_TNF_TRACE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <tnf/probe.h>
32 #include "tnf_buf.h"
33 #include "tnf_types.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Size of a TNF buffer block
41  */
42 
43 #define	TNF_BLOCK_SIZE 	512
44 #define	TNF_BLOCK_MASK	~(TNF_BLOCK_SIZE - 1)
45 
46 /*
47  * Size of TNF file directory area
48  */
49 
50 #define	TNF_DIRECTORY_SIZE	(1 << 16)
51 
52 /*
53  * specification of index field of probe control block
54  */
55 
56 #define	PROBE_INDEX_TYPE_MASK	0x3
57 #define	PROBE_INDEX_MEM_PTR	0x0	/* index is a normal memory ptr */
58 #define	PROBE_INDEX_FILE_PTR	0x1	/* index is a file abs ptr */
59 #define	PROBE_INDEX_LOW_MASK	0xffff0000
60 #define	PROBE_INDEX_SHIFT	16
61 
62 #define	PROBE_IS_FILE_PTR(x)	\
63 	(((x) & PROBE_INDEX_TYPE_MASK) == PROBE_INDEX_FILE_PTR)
64 
65 #define	ATTR_SEPARATOR		';'
66 #define	VAL_SEPARATOR		' '
67 
68 typedef struct {
69 	tnf_record_p		record_p;
70 	tnf_uint32_t		record_gen;
71 	unsigned long		tid;
72 	unsigned long		lwpid;
73 	long			pid;
74 	hrtime_t		time_base;
75 } tnf_schedule_t;
76 
77 typedef struct {
78 	tnf_tag_t		tag;
79 	tnf_uint32_t		tid;
80 	tnf_uint32_t		lwpid;
81 	pid_t			pid;
82 	/*
83 	 * time base should be on a double word boundary to avoid pads
84 	 */
85 	tnf_longlong_t	time_base;
86 } tnf_schedule_prototype_t;
87 
88 typedef struct {
89 	tnf_tag_t		tag;
90 	tnf_name_t		name;
91 	tnf_properties_t	properties;
92 	tnf_slot_types_t	slot_types;
93 	tnf_type_size_t		type_size;
94 	tnf_slot_names_t	slot_names;
95 	tnf_string_t		string;
96 } tnf_probe_prototype_t;
97 
98 /*
99  * TNF output ops
100  */
101 
102 /*
103  * Data structure that is the glue between the tnf layer and the buffering
104  * layer.
105  */
106 struct _tnf_ops {
107 	/* fields needed by TNF writing layer */
108 	enum tnf_alloc_mode mode;
109 	void * (*alloc)(TNFW_B_WCB *, size_t, enum tnf_alloc_mode);
110 	TNFW_B_STATUS (*commit)(TNFW_B_WCB *);
111 	TNFW_B_STATUS (*rollback)(TNFW_B_WCB *);
112 	TNFW_B_WCB wcb;
113 	/* fields needed by tracing allocation and final function */
114 	int			busy;
115 	tnf_schedule_t		schedule;
116 };
117 
118 /*
119  * Tag data variables
120  */
121 extern tnf_tag_data_t	*tnf_probe_type_tag_data;
122 extern tnf_tag_data_t	*tnf_sched_rec_tag_data;
123 
124 tnf_record_p 	tnf_schedule_write(tnf_ops_t *ops, tnf_schedule_t *sched);
125 uintptr_t 	tnf_probe_tag(tnf_ops_t *ops, tnf_probe_control_t *probe);
126 void		_tnf_sched_init(tnf_schedule_t *, hrtime_t);
127 int 		_tnf_trace_initialize(void);
128 void 		_tnf_fork_thread_setup(void);
129 
130 extern char tnf_trace_file_name[];
131 
132 /* PROJECT PRIVATE interfaces between prex and libtnfprobe */
133 
134 void *tnf_trace_alloc(tnf_ops_t *, tnf_probe_control_t *, tnf_probe_setup_t *);
135 
136 void tnf_trace_end(tnf_probe_setup_t *);
137 
138 void tnf_trace_commit(tnf_probe_setup_t *);
139 
140 void tnf_trace_rollback(tnf_probe_setup_t *);
141 
142 void tnf_probe_debug(tnf_probe_setup_t *);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* _TNF_TRACE_H */
149