8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libtnfprobe / tnf_trace.c
blob3e765a4bc82f5543c04d71ec8c6faee7704b9347
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #ifndef DEBUG
29 #define NDEBUG 1
30 #endif
32 #include <stdlib.h>
33 #include <string.h>
34 #include <tnf/com.h>
35 #include <tnf/writer.h>
36 #include <tnf/probe.h>
37 #include <assert.h>
39 #include "tnf_types.h"
40 #include "tnf_trace.h"
42 #ifdef TNFWB_DEBUG
43 #ifdef _KERNEL
44 #error TNFWB_DEBUG
45 #else /* _KERNEL */
46 #include <stdio.h>
47 #include <thread.h>
48 #endif /* _KERNEL */
49 #endif /* TNFW_DEBUG */
53 * Defines
56 #ifdef _KERNEL
57 #define TNF_ASSERT(expr) ASSERT(expr)
58 #else
59 #define TNF_ASSERT(expr) assert(expr)
60 #endif
63 * New properties need for tracing
66 static tnf_tag_data_t **derived_tagarg_properties[] = {
67 &TAG_DATA(tnf_derived),
68 &TAG_DATA(tnf_tag_arg),
72 static tnf_tag_data_t ***derived_tagarg_properties_ptr =
73 derived_tagarg_properties;
76 * New derived types for probes
79 TNF_STD_DERIVED_TAG(tnf_probe_event, tnf_tag,
80 derived_tagarg_properties_ptr, TNF_OPAQUE);
82 TNF_STD_DERIVED_TAG(tnf_time_base, tnf_int64,
83 tnf_derived_properties, TNF_INT64);
85 TNF_STD_DERIVED_TAG(tnf_time_delta, tnf_uint32,
86 tnf_derived_properties, TNF_UINT32);
88 TNF_STD_DERIVED_TAG(tnf_pid, tnf_int32,
89 tnf_derived_properties, TNF_INT32);
91 TNF_STD_DERIVED_TAG(tnf_lwpid, tnf_uint32,
92 tnf_derived_properties, TNF_UINT32);
95 * Schedule records -CAUTION- keep in sync with tnf_internal.h
96 * Note that tnf_schedule_prototype_t has different sizes for
97 * kernel and user.
100 static char *user_schedule_slot_names[] = {
101 TNF_N_TAG,
102 TNF_N_TID,
103 TNF_N_LWPID,
104 TNF_N_PID,
105 TNF_N_TIME_BASE,
108 static tnf_tag_data_t **user_schedule_slots[] = {
109 &TAG_DATA(tnf_tag), /* tag */
110 &TAG_DATA(tnf_uint32), /* tid XXX */
111 &TAG_DATA(tnf_lwpid), /* lwpid */
112 &TAG_DATA(tnf_pid), /* pid */
113 &TAG_DATA(tnf_time_base), /* time_base */
116 TNF_STD_STRUCT_TAG(tnf_sched_rec,
117 user_schedule_slots,
118 user_schedule_slot_names,
119 sizeof (tnf_schedule_prototype_t));
122 * Probe type record (metatag)
125 static tnf_tag_data_t **probe_type_slots[] = {
126 &TAG_DATA(tnf_tag),
127 &TAG_DATA(tnf_name),
128 &TAG_DATA(tnf_properties),
129 &TAG_DATA(tnf_slot_types),
130 &TAG_DATA(tnf_type_size),
131 &TAG_DATA(tnf_slot_names),
132 &TAG_DATA(tnf_string), /* detail */
135 TNF_STRUCT_TAG(tnf_probe_type,
136 tnf_type_properties,
137 probe_type_slots,
139 sizeof (tnf_probe_prototype_t));
142 * export all tags
145 TAG_EXPORT(tnf_probe_event);
146 TAG_EXPORT(tnf_time_base);
147 TAG_EXPORT(tnf_time_delta);
148 TAG_EXPORT(tnf_pid);
149 TAG_EXPORT(tnf_lwpid);
151 TAG_EXPORT(tnf_sched_rec);
152 TAG_EXPORT(tnf_probe_type);
155 * Write a schedule record
156 * Can only be written in reusable data space.
159 tnf_record_p
160 tnf_schedule_write(tnf_ops_t *ops, tnf_schedule_t *sched)
162 tnf_tag_data_t *metatag_data;
163 tnf_record_p metatag_index;
164 tnf_schedule_prototype_t *buffer;
166 #ifdef _TNF_VERBOSE
167 fprintf(stderr, "tnf_schedule_write: \n");
168 #endif
169 /* Cannot be called when writing into tag space */
170 TNF_ASSERT(ops->mode == TNF_ALLOC_REUSABLE);
171 ALLOC(ops, sizeof (*buffer), buffer, sched->record_p, ops->mode);
173 metatag_data = TAG_DATA(tnf_sched_rec);
175 metatag_index = metatag_data->tag_index ?
176 metatag_data->tag_index :
177 metatag_data->tag_desc(ops, metatag_data);
179 ASSIGN(buffer, tag, metatag_index);
180 /* LINTED - tid is 32 bits */
181 ASSIGN2(buffer, tid, sched->tid, uint32);
182 /* LINTED - lwpid is 32 bits */
183 ASSIGN(buffer, lwpid, sched->lwpid);
184 /* LINTED - pid is 32 bits */
185 ASSIGN(buffer, pid, sched->pid);
186 ASSIGN(buffer, time_base, sched->time_base);
189 * Remember schedule record generation number so the distance
190 * in virtual space can be calculated from an event record
192 sched->record_gen = ((tnf_block_header_t *)
193 ((uintptr_t)buffer & TNF_BLOCK_MASK))->generation;
194 /* Cannot have been written into tag space */
195 TNF_ASSERT(sched->record_gen != TNF_TAG_GENERATION_NUM);
197 return ((tnf_record_p) buffer);