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
));
85 if (ctx
->nr_fields
+ 1 > ctx
->allocated_fields
) {
86 struct lttng_ctx_field
*new_fields
;
88 ctx
->allocated_fields
= max_t(size_t, 1, 2 * ctx
->allocated_fields
);
89 new_fields
= zmalloc(ctx
->allocated_fields
* sizeof(struct lttng_ctx_field
));
93 memcpy(new_fields
, ctx
->fields
, sizeof(*ctx
->fields
) * ctx
->nr_fields
);
95 ctx
->fields
= new_fields
;
97 field
= &ctx
->fields
[ctx
->nr_fields
];
103 * Remove last context field.
105 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
106 struct lttng_ctx_field
*field
)
108 struct lttng_ctx
*ctx
;
112 assert(&ctx
->fields
[ctx
->nr_fields
] == field
);
113 memset(&ctx
->fields
[ctx
->nr_fields
], 0, sizeof(struct lttng_ctx_field
));
116 void lttng_destroy_context(struct lttng_ctx
*ctx
)
122 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
123 if (ctx
->fields
[i
].destroy
)
124 ctx
->fields
[i
].destroy(&ctx
->fields
[i
]);
130 void lttng_context_init(void)
134 ret
= lttng_add_pthread_id_to_ctx(<tng_static_ctx
);
136 WARN("Cannot add context lttng_add_pthread_id_to_ctx");
138 ret
= lttng_add_vtid_to_ctx(<tng_static_ctx
);
140 WARN("Cannot add context lttng_add_vtid_to_ctx");
142 ret
= lttng_add_vpid_to_ctx(<tng_static_ctx
);
144 WARN("Cannot add context lttng_add_vpid_to_ctx");
146 ret
= lttng_add_procname_to_ctx(<tng_static_ctx
);
148 WARN("Cannot add context lttng_add_procname_to_ctx");
152 void lttng_context_exit(void)
154 lttng_destroy_context(lttng_static_ctx
);
155 lttng_static_ctx
= NULL
;
This page took 0.058447 seconds and 4 git commands to generate.