4 * LTTng UST trace/channel/event context management.
6 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <lttng/ust-events.h>
25 #include <lttng/ust-tracer.h>
26 #include <usterr-signal-safe.h>
32 * The filter implementation requires that two consecutive "get" for the
33 * same context performed by the same thread return the same result.
37 * Static array of contexts, for $ctx filters.
39 struct lttng_ctx
*lttng_static_ctx
;
41 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
)
45 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
46 /* Skip allocated (but non-initialized) contexts */
47 if (!ctx
->fields
[i
].event_field
.name
)
49 if (!strcmp(ctx
->fields
[i
].event_field
.name
, name
))
55 int lttng_get_context_index(struct lttng_ctx
*ctx
, const char *name
)
61 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
62 /* Skip allocated (but non-initialized) contexts */
63 if (!ctx
->fields
[i
].event_field
.name
)
65 if (!strcmp(ctx
->fields
[i
].event_field
.name
, name
))
72 * Note: as we append context information, the pointer location may change.
74 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
)
76 struct lttng_ctx_field
*field
;
77 struct lttng_ctx
*ctx
;
80 *ctx_p
= zmalloc(sizeof(struct lttng_ctx
));
83 (*ctx_p
)->largest_align
= 1;
86 if (ctx
->nr_fields
+ 1 > ctx
->allocated_fields
) {
87 struct lttng_ctx_field
*new_fields
;
89 ctx
->allocated_fields
= max_t(size_t, 1, 2 * ctx
->allocated_fields
);
90 new_fields
= zmalloc(ctx
->allocated_fields
* sizeof(struct lttng_ctx_field
));
94 memcpy(new_fields
, ctx
->fields
, sizeof(*ctx
->fields
) * ctx
->nr_fields
);
96 ctx
->fields
= new_fields
;
98 field
= &ctx
->fields
[ctx
->nr_fields
];
104 * lttng_context_update() should be called at least once between context
105 * modification and trace start.
107 void lttng_context_update(struct lttng_ctx
*ctx
)
110 size_t largest_align
= 8; /* in bits */
112 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
113 struct lttng_type
*type
;
114 size_t field_align
= 8;
116 type
= &ctx
->fields
[i
].event_field
.type
;
117 switch (type
->atype
) {
119 field_align
= type
->u
.basic
.integer
.alignment
;
123 struct lttng_basic_type
*btype
;
125 btype
= &type
->u
.array
.elem_type
;
126 switch (btype
->atype
) {
128 field_align
= btype
->u
.basic
.integer
.alignment
;
143 struct lttng_basic_type
*btype
;
145 btype
= &type
->u
.sequence
.length_type
;
146 switch (btype
->atype
) {
148 field_align
= btype
->u
.basic
.integer
.alignment
;
159 btype
= &type
->u
.sequence
.elem_type
;
160 switch (btype
->atype
) {
162 field_align
= max_t(size_t,
164 btype
->u
.basic
.integer
.alignment
);
186 largest_align
= max_t(size_t, largest_align
, field_align
);
188 ctx
->largest_align
= largest_align
>> 3; /* bits to bytes */
192 * Remove last context field.
194 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
195 struct lttng_ctx_field
*field
)
197 struct lttng_ctx
*ctx
;
201 assert(&ctx
->fields
[ctx
->nr_fields
] == field
);
202 memset(&ctx
->fields
[ctx
->nr_fields
], 0, sizeof(struct lttng_ctx_field
));
205 void lttng_destroy_context(struct lttng_ctx
*ctx
)
211 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
212 if (ctx
->fields
[i
].destroy
)
213 ctx
->fields
[i
].destroy(&ctx
->fields
[i
]);
219 void lttng_context_init(void)
223 ret
= lttng_add_pthread_id_to_ctx(<tng_static_ctx
);
225 WARN("Cannot add context lttng_add_pthread_id_to_ctx");
227 ret
= lttng_add_vtid_to_ctx(<tng_static_ctx
);
229 WARN("Cannot add context lttng_add_vtid_to_ctx");
231 ret
= lttng_add_vpid_to_ctx(<tng_static_ctx
);
233 WARN("Cannot add context lttng_add_vpid_to_ctx");
235 ret
= lttng_add_procname_to_ctx(<tng_static_ctx
);
237 WARN("Cannot add context lttng_add_procname_to_ctx");
239 ret
= lttng_add_cpu_id_to_ctx(<tng_static_ctx
);
241 WARN("Cannot add context lttng_add_cpu_id_to_ctx");
245 void lttng_context_exit(void)
247 lttng_destroy_context(lttng_static_ctx
);
248 lttng_static_ctx
= NULL
;
This page took 0.036212 seconds and 4 git commands to generate.