4 * Holds LTTng probes registry.
6 * Copyright 2010-2012 (c) - 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
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/tracepoint.h>
29 #include "tracepoint-internal.h"
34 #include "ltt-tracer-core.h"
39 * probe list is protected by ust_lock()/ust_unlock().
41 static CDS_LIST_HEAD(probe_list
);
44 const struct lttng_probe_desc
*find_provider(const char *provider
)
46 struct lttng_probe_desc
*iter
;
48 cds_list_for_each_entry(iter
, &probe_list
, head
) {
49 if (!strcmp(iter
->provider
, provider
))
56 const struct lttng_event_desc
*find_event(const char *name
)
58 struct lttng_probe_desc
*probe_desc
;
61 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
62 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
63 if (!strncmp(probe_desc
->event_desc
[i
]->name
, name
,
64 LTTNG_UST_SYM_NAME_LEN
- 1))
65 return probe_desc
->event_desc
[i
];
71 int ltt_probe_register(struct lttng_probe_desc
*desc
)
73 struct lttng_probe_desc
*iter
;
78 if (find_provider(desc
->provider
)) {
83 * TODO: This is O(N^2). Turn into a hash table when probe registration
84 * overhead becomes an issue.
86 for (i
= 0; i
< desc
->nr_events
; i
++) {
87 if (find_event(desc
->event_desc
[i
]->name
)) {
94 * We sort the providers by struct lttng_probe_desc pointer
97 cds_list_for_each_entry_reverse(iter
, &probe_list
, head
) {
98 BUG_ON(iter
== desc
); /* Should never be in the list twice */
100 /* We belong to the location right after iter. */
101 cds_list_add(&desc
->head
, &iter
->head
);
105 /* We should be added at the head of the list */
106 cds_list_add(&desc
->head
, &probe_list
);
108 DBG("just registered probe %s containing %u events",
109 desc
->provider
, desc
->nr_events
);
111 * fix the events awaiting probe load.
113 for (i
= 0; i
< desc
->nr_events
; i
++) {
114 const struct lttng_event_desc
*ed
;
116 ed
= desc
->event_desc
[i
];
117 DBG("Registered event probe \"%s\" with signature \"%s\"",
118 ed
->name
, ed
->signature
);
119 ret
= pending_probe_fix_events(ed
);
127 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
130 cds_list_del(&desc
->head
);
131 DBG("just unregistered probe %s", desc
->provider
);
136 * called with UST lock held.
138 const struct lttng_event_desc
*ltt_event_get(const char *name
)
140 const struct lttng_event_desc
*event
;
142 event
= find_event(name
);
148 void ltt_event_put(const struct lttng_event_desc
*event
)
152 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
154 struct tp_list_entry
*list_entry
, *tmp
;
156 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
157 cds_list_del(&list_entry
->head
);
163 * called with UST lock held.
165 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
167 struct lttng_probe_desc
*probe_desc
;
170 CDS_INIT_LIST_HEAD(&list
->head
);
171 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
172 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
173 struct tp_list_entry
*list_entry
;
175 list_entry
= zmalloc(sizeof(*list_entry
));
178 cds_list_add(&list_entry
->head
, &list
->head
);
179 strncpy(list_entry
->tp
.name
,
180 probe_desc
->event_desc
[i
]->name
,
181 LTTNG_UST_SYM_NAME_LEN
);
182 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
183 if (!probe_desc
->event_desc
[i
]->loglevel
) {
184 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
186 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
190 if (cds_list_empty(&list
->head
))
194 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
198 ltt_probes_prune_event_list(list
);
203 * Return current iteration position, advance internal iterator to next.
204 * Return NULL if end of list.
206 struct lttng_ust_tracepoint_iter
*
207 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
209 struct tp_list_entry
*entry
;
214 if (entry
->head
.next
== &list
->head
)
217 list
->iter
= cds_list_entry(entry
->head
.next
,
218 struct tp_list_entry
, head
);
222 void ltt_probes_prune_field_list(struct lttng_ust_field_list
*list
)
224 struct tp_field_list_entry
*list_entry
, *tmp
;
226 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
227 cds_list_del(&list_entry
->head
);
233 * called with UST lock held.
235 int ltt_probes_get_field_list(struct lttng_ust_field_list
*list
)
237 struct lttng_probe_desc
*probe_desc
;
240 CDS_INIT_LIST_HEAD(&list
->head
);
241 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
242 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
243 const struct lttng_event_desc
*event_desc
=
244 probe_desc
->event_desc
[i
];
247 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
248 const struct lttng_event_field
*event_field
=
249 &event_desc
->fields
[j
];
250 struct tp_field_list_entry
*list_entry
;
252 list_entry
= zmalloc(sizeof(*list_entry
));
255 cds_list_add(&list_entry
->head
, &list
->head
);
256 strncpy(list_entry
->field
.event_name
,
258 LTTNG_UST_SYM_NAME_LEN
);
259 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
260 strncpy(list_entry
->field
.field_name
,
262 LTTNG_UST_SYM_NAME_LEN
);
263 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
264 switch (event_field
->type
.atype
) {
266 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
269 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
272 if (event_field
->type
.u
.array
.elem_type
.atype
!= atype_integer
273 || event_field
->type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
274 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
276 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
279 if (event_field
->type
.u
.sequence
.elem_type
.atype
!= atype_integer
280 || event_field
->type
.u
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
281 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
283 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
286 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
289 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
292 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
294 if (!event_desc
->loglevel
) {
295 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
297 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
302 if (cds_list_empty(&list
->head
))
306 cds_list_first_entry(&list
->head
,
307 struct tp_field_list_entry
, head
);
311 ltt_probes_prune_field_list(list
);
316 * Return current iteration position, advance internal iterator to next.
317 * Return NULL if end of list.
319 struct lttng_ust_field_iter
*
320 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
322 struct tp_field_list_entry
*entry
;
327 if (entry
->head
.next
== &list
->head
)
330 list
->iter
= cds_list_entry(entry
->head
.next
,
331 struct tp_field_list_entry
, head
);
332 return &entry
->field
;
336 * marshall all probes/all events and create those that fit the
337 * wildcard. Add them to the events list as created.
339 void ltt_probes_create_wildcard_events(struct wildcard_entry
*entry
,
340 struct session_wildcard
*wildcard
)
342 struct lttng_probe_desc
*probe_desc
;
343 struct lttng_ust_event event_param
;
346 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
347 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
348 const struct lttng_event_desc
*event_desc
;
351 event_desc
= probe_desc
->event_desc
[i
];
352 /* compare excluding final '*' */
353 assert(strlen(entry
->name
) > 0);
354 if (strcmp(event_desc
->name
, "lttng_ust:metadata")
355 && (strlen(entry
->name
) == 1
356 || !strncmp(event_desc
->name
, entry
->name
,
357 strlen(entry
->name
) - 1))) {
358 if (ltt_loglevel_match(event_desc
,
359 entry
->loglevel_type
,
365 struct ltt_event
*ev
;
368 memcpy(&event_param
, &wildcard
->event_param
,
369 sizeof(event_param
));
370 memcpy(event_param
.name
,
372 sizeof(event_param
.name
));
374 ret
= ltt_event_create(wildcard
->chan
,
377 DBG("Error creating event");
380 cds_list_add(&ev
->wildcard_list
,
385 lttng_filter_wildcard_link_bytecode(wildcard
);