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
);
43 struct cds_list_head
*lttng_get_probe_list_head(void)
49 const struct lttng_probe_desc
*find_provider(const char *provider
)
51 struct lttng_probe_desc
*iter
;
52 struct cds_list_head
*probe_list
;
54 probe_list
= lttng_get_probe_list_head();
55 cds_list_for_each_entry(iter
, probe_list
, head
) {
56 if (!strcmp(iter
->provider
, provider
))
63 int check_event_provider(struct lttng_probe_desc
*desc
)
66 size_t provider_name_len
;
68 provider_name_len
= strnlen(desc
->provider
,
69 LTTNG_UST_SYM_NAME_LEN
- 1);
70 for (i
= 0; i
< desc
->nr_events
; i
++) {
71 if (strncmp(desc
->event_desc
[i
]->name
,
74 return 0; /* provider mismatch */
79 int lttng_probe_register(struct lttng_probe_desc
*desc
)
81 struct lttng_probe_desc
*iter
;
84 struct cds_list_head
*probe_list
;
89 * Check if the provider has already been registered.
91 if (find_provider(desc
->provider
)) {
97 * Each provider enforce that every event name begins with the
98 * provider name. Check this in an assertion for extra
99 * carefulness. This ensures we cannot have duplicate event
100 * names across providers.
102 assert(check_event_provider(desc
));
105 * The provider ensures there are no duplicate event names.
106 * Duplicated TRACEPOINT_EVENT event names would generate a
107 * compile-time error due to duplicated symbol names.
111 * We sort the providers by struct lttng_probe_desc pointer
114 probe_list
= lttng_get_probe_list_head();
115 cds_list_for_each_entry_reverse(iter
, probe_list
, head
) {
116 BUG_ON(iter
== desc
); /* Should never be in the list twice */
118 /* We belong to the location right after iter. */
119 cds_list_add(&desc
->head
, &iter
->head
);
123 /* We should be added at the head of the list */
124 cds_list_add(&desc
->head
, probe_list
);
126 DBG("just registered probe %s containing %u events",
127 desc
->provider
, desc
->nr_events
);
129 * fix the events awaiting probe load.
131 for (i
= 0; i
< desc
->nr_events
; i
++) {
132 const struct lttng_event_desc
*ed
;
134 ed
= desc
->event_desc
[i
];
135 DBG("Registered event probe \"%s\" with signature \"%s\"",
136 ed
->name
, ed
->signature
);
137 ret
= lttng_fix_pending_event_desc(ed
);
145 /* Backward compatibility with UST 2.0 */
146 int ltt_probe_register(struct lttng_probe_desc
*desc
)
148 return lttng_probe_register(desc
);
151 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
154 cds_list_del(&desc
->head
);
155 DBG("just unregistered probe %s", desc
->provider
);
159 /* Backward compatibility with UST 2.0 */
160 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
162 lttng_probe_unregister(desc
);
165 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
167 struct tp_list_entry
*list_entry
, *tmp
;
169 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
170 cds_list_del(&list_entry
->head
);
176 * called with UST lock held.
178 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
180 struct lttng_probe_desc
*probe_desc
;
182 struct cds_list_head
*probe_list
;
184 probe_list
= lttng_get_probe_list_head();
185 CDS_INIT_LIST_HEAD(&list
->head
);
186 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
187 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
188 struct tp_list_entry
*list_entry
;
190 list_entry
= zmalloc(sizeof(*list_entry
));
193 cds_list_add(&list_entry
->head
, &list
->head
);
194 strncpy(list_entry
->tp
.name
,
195 probe_desc
->event_desc
[i
]->name
,
196 LTTNG_UST_SYM_NAME_LEN
);
197 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
198 if (!probe_desc
->event_desc
[i
]->loglevel
) {
199 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
201 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
205 if (cds_list_empty(&list
->head
))
209 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
213 lttng_probes_prune_event_list(list
);
218 * Return current iteration position, advance internal iterator to next.
219 * Return NULL if end of list.
221 struct lttng_ust_tracepoint_iter
*
222 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
224 struct tp_list_entry
*entry
;
229 if (entry
->head
.next
== &list
->head
)
232 list
->iter
= cds_list_entry(entry
->head
.next
,
233 struct tp_list_entry
, head
);
237 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
239 struct tp_field_list_entry
*list_entry
, *tmp
;
241 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
242 cds_list_del(&list_entry
->head
);
248 * called with UST lock held.
250 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
252 struct lttng_probe_desc
*probe_desc
;
254 struct cds_list_head
*probe_list
;
256 probe_list
= lttng_get_probe_list_head();
257 CDS_INIT_LIST_HEAD(&list
->head
);
258 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
259 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
260 const struct lttng_event_desc
*event_desc
=
261 probe_desc
->event_desc
[i
];
264 if (event_desc
->nr_fields
== 0) {
265 /* Events without fields. */
266 struct tp_field_list_entry
*list_entry
;
268 list_entry
= zmalloc(sizeof(*list_entry
));
271 cds_list_add(&list_entry
->head
, &list
->head
);
272 strncpy(list_entry
->field
.event_name
,
274 LTTNG_UST_SYM_NAME_LEN
);
275 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
276 list_entry
->field
.field_name
[0] = '\0';
277 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
278 if (!event_desc
->loglevel
) {
279 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
281 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
283 list_entry
->field
.nowrite
= 1;
286 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
287 const struct lttng_event_field
*event_field
=
288 &event_desc
->fields
[j
];
289 struct tp_field_list_entry
*list_entry
;
291 list_entry
= zmalloc(sizeof(*list_entry
));
294 cds_list_add(&list_entry
->head
, &list
->head
);
295 strncpy(list_entry
->field
.event_name
,
297 LTTNG_UST_SYM_NAME_LEN
);
298 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
299 strncpy(list_entry
->field
.field_name
,
301 LTTNG_UST_SYM_NAME_LEN
);
302 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
303 switch (event_field
->type
.atype
) {
305 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
308 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
311 if (event_field
->type
.u
.array
.elem_type
.atype
!= atype_integer
312 || event_field
->type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
313 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
315 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
318 if (event_field
->type
.u
.sequence
.elem_type
.atype
!= atype_integer
319 || event_field
->type
.u
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
320 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
322 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
325 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
328 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
331 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
333 if (!event_desc
->loglevel
) {
334 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
336 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
338 list_entry
->field
.nowrite
= event_field
->nowrite
;
342 if (cds_list_empty(&list
->head
))
346 cds_list_first_entry(&list
->head
,
347 struct tp_field_list_entry
, head
);
351 lttng_probes_prune_field_list(list
);
356 * Return current iteration position, advance internal iterator to next.
357 * Return NULL if end of list.
359 struct lttng_ust_field_iter
*
360 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
362 struct tp_field_list_entry
*entry
;
367 if (entry
->head
.next
== &list
->head
)
370 list
->iter
= cds_list_entry(entry
->head
.next
,
371 struct tp_field_list_entry
, head
);
372 return &entry
->field
;