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 "lttng-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 lttng_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 /* Backward compatibility with UST 2.0 */
128 int ltt_probe_register(struct lttng_probe_desc
*desc
)
130 return lttng_probe_register(desc
);
133 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
136 cds_list_del(&desc
->head
);
137 DBG("just unregistered probe %s", desc
->provider
);
141 /* Backward compatibility with UST 2.0 */
142 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
144 lttng_probe_unregister(desc
);
148 * called with UST lock held.
150 const struct lttng_event_desc
*lttng_event_get(const char *name
)
152 const struct lttng_event_desc
*event
;
154 event
= find_event(name
);
160 void lttng_event_put(const struct lttng_event_desc
*event
)
164 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
166 struct tp_list_entry
*list_entry
, *tmp
;
168 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
169 cds_list_del(&list_entry
->head
);
175 * called with UST lock held.
177 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
179 struct lttng_probe_desc
*probe_desc
;
182 CDS_INIT_LIST_HEAD(&list
->head
);
183 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
184 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
185 struct tp_list_entry
*list_entry
;
187 list_entry
= zmalloc(sizeof(*list_entry
));
190 cds_list_add(&list_entry
->head
, &list
->head
);
191 strncpy(list_entry
->tp
.name
,
192 probe_desc
->event_desc
[i
]->name
,
193 LTTNG_UST_SYM_NAME_LEN
);
194 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
195 if (!probe_desc
->event_desc
[i
]->loglevel
) {
196 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
198 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
202 if (cds_list_empty(&list
->head
))
206 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
210 lttng_probes_prune_event_list(list
);
215 * Return current iteration position, advance internal iterator to next.
216 * Return NULL if end of list.
218 struct lttng_ust_tracepoint_iter
*
219 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
221 struct tp_list_entry
*entry
;
226 if (entry
->head
.next
== &list
->head
)
229 list
->iter
= cds_list_entry(entry
->head
.next
,
230 struct tp_list_entry
, head
);
234 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
236 struct tp_field_list_entry
*list_entry
, *tmp
;
238 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
239 cds_list_del(&list_entry
->head
);
245 * called with UST lock held.
247 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
249 struct lttng_probe_desc
*probe_desc
;
252 CDS_INIT_LIST_HEAD(&list
->head
);
253 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
254 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
255 const struct lttng_event_desc
*event_desc
=
256 probe_desc
->event_desc
[i
];
259 if (event_desc
->nr_fields
== 0) {
260 /* Events without fields. */
261 struct tp_field_list_entry
*list_entry
;
263 list_entry
= zmalloc(sizeof(*list_entry
));
266 cds_list_add(&list_entry
->head
, &list
->head
);
267 strncpy(list_entry
->field
.event_name
,
269 LTTNG_UST_SYM_NAME_LEN
);
270 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
271 list_entry
->field
.field_name
[0] = '\0';
272 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
273 if (!event_desc
->loglevel
) {
274 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
276 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
278 list_entry
->field
.nowrite
= 1;
281 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
282 const struct lttng_event_field
*event_field
=
283 &event_desc
->fields
[j
];
284 struct tp_field_list_entry
*list_entry
;
286 list_entry
= zmalloc(sizeof(*list_entry
));
289 cds_list_add(&list_entry
->head
, &list
->head
);
290 strncpy(list_entry
->field
.event_name
,
292 LTTNG_UST_SYM_NAME_LEN
);
293 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
294 strncpy(list_entry
->field
.field_name
,
296 LTTNG_UST_SYM_NAME_LEN
);
297 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
298 switch (event_field
->type
.atype
) {
300 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
303 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
306 if (event_field
->type
.u
.array
.elem_type
.atype
!= atype_integer
307 || event_field
->type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
308 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
310 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
313 if (event_field
->type
.u
.sequence
.elem_type
.atype
!= atype_integer
314 || event_field
->type
.u
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
315 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
317 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
320 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
323 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
326 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
328 if (!event_desc
->loglevel
) {
329 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
331 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
333 list_entry
->field
.nowrite
= event_field
->nowrite
;
337 if (cds_list_empty(&list
->head
))
341 cds_list_first_entry(&list
->head
,
342 struct tp_field_list_entry
, head
);
346 lttng_probes_prune_field_list(list
);
351 * Return current iteration position, advance internal iterator to next.
352 * Return NULL if end of list.
354 struct lttng_ust_field_iter
*
355 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
357 struct tp_field_list_entry
*entry
;
362 if (entry
->head
.next
== &list
->head
)
365 list
->iter
= cds_list_entry(entry
->head
.next
,
366 struct tp_field_list_entry
, head
);
367 return &entry
->field
;
371 * marshall all probes/all events and create those that fit the
372 * wildcard. Add them to the events list as created.
374 void lttng_probes_create_wildcard_events(struct wildcard_entry
*entry
,
375 struct session_wildcard
*wildcard
)
377 struct lttng_probe_desc
*probe_desc
;
378 struct lttng_ust_event event_param
;
381 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
382 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
383 const struct lttng_event_desc
*event_desc
;
386 event_desc
= probe_desc
->event_desc
[i
];
387 /* compare excluding final '*' */
388 assert(strlen(entry
->name
) > 0);
389 if (strcmp(event_desc
->name
, "lttng_ust:metadata")
390 && (strlen(entry
->name
) == 1
391 || !strncmp(event_desc
->name
, entry
->name
,
392 strlen(entry
->name
) - 1))) {
393 if (lttng_loglevel_match(event_desc
,
394 entry
->loglevel_type
,
400 struct lttng_event
*ev
;
403 memcpy(&event_param
, &wildcard
->event_param
,
404 sizeof(event_param
));
405 strncpy(event_param
.name
,
407 sizeof(event_param
.name
));
408 event_param
.name
[sizeof(event_param
.name
) - 1] = '\0';
410 ret
= lttng_event_create(wildcard
->chan
,
413 DBG("Error creating event");
416 cds_list_add(&ev
->wildcard_list
,
421 lttng_filter_wildcard_link_bytecode(wildcard
);