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 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
;
53 cds_list_for_each_entry(iter
, &probe_list
, head
) {
54 if (!strcmp(iter
->provider
, provider
))
61 const struct lttng_event_desc
*find_event(const char *name
)
63 struct lttng_probe_desc
*probe_desc
;
66 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
67 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
68 if (!strncmp(probe_desc
->event_desc
[i
]->name
, name
,
69 LTTNG_UST_SYM_NAME_LEN
- 1))
70 return probe_desc
->event_desc
[i
];
76 int lttng_probe_register(struct lttng_probe_desc
*desc
)
78 struct lttng_probe_desc
*iter
;
83 if (find_provider(desc
->provider
)) {
88 * TODO: This is O(N^2). Turn into a hash table when probe registration
89 * overhead becomes an issue.
91 for (i
= 0; i
< desc
->nr_events
; i
++) {
92 if (find_event(desc
->event_desc
[i
]->name
)) {
99 * We sort the providers by struct lttng_probe_desc pointer
102 cds_list_for_each_entry_reverse(iter
, &probe_list
, head
) {
103 BUG_ON(iter
== desc
); /* Should never be in the list twice */
105 /* We belong to the location right after iter. */
106 cds_list_add(&desc
->head
, &iter
->head
);
110 /* We should be added at the head of the list */
111 cds_list_add(&desc
->head
, &probe_list
);
113 DBG("just registered probe %s containing %u events",
114 desc
->provider
, desc
->nr_events
);
116 * fix the events awaiting probe load.
118 for (i
= 0; i
< desc
->nr_events
; i
++) {
119 const struct lttng_event_desc
*ed
;
121 ed
= desc
->event_desc
[i
];
122 DBG("Registered event probe \"%s\" with signature \"%s\"",
123 ed
->name
, ed
->signature
);
124 ret
= lttng_fix_pending_event_desc(ed
);
132 /* Backward compatibility with UST 2.0 */
133 int ltt_probe_register(struct lttng_probe_desc
*desc
)
135 return lttng_probe_register(desc
);
138 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
141 cds_list_del(&desc
->head
);
142 DBG("just unregistered probe %s", desc
->provider
);
146 /* Backward compatibility with UST 2.0 */
147 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
149 lttng_probe_unregister(desc
);
153 * called with UST lock held.
155 const struct lttng_event_desc
*lttng_event_get(const char *name
)
157 const struct lttng_event_desc
*event
;
159 event
= find_event(name
);
165 void lttng_event_put(const struct lttng_event_desc
*event
)
169 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
171 struct tp_list_entry
*list_entry
, *tmp
;
173 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
174 cds_list_del(&list_entry
->head
);
180 * called with UST lock held.
182 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
184 struct lttng_probe_desc
*probe_desc
;
187 CDS_INIT_LIST_HEAD(&list
->head
);
188 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
189 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
190 struct tp_list_entry
*list_entry
;
192 list_entry
= zmalloc(sizeof(*list_entry
));
195 cds_list_add(&list_entry
->head
, &list
->head
);
196 strncpy(list_entry
->tp
.name
,
197 probe_desc
->event_desc
[i
]->name
,
198 LTTNG_UST_SYM_NAME_LEN
);
199 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
200 if (!probe_desc
->event_desc
[i
]->loglevel
) {
201 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
203 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
207 if (cds_list_empty(&list
->head
))
211 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
215 lttng_probes_prune_event_list(list
);
220 * Return current iteration position, advance internal iterator to next.
221 * Return NULL if end of list.
223 struct lttng_ust_tracepoint_iter
*
224 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
226 struct tp_list_entry
*entry
;
231 if (entry
->head
.next
== &list
->head
)
234 list
->iter
= cds_list_entry(entry
->head
.next
,
235 struct tp_list_entry
, head
);
239 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
241 struct tp_field_list_entry
*list_entry
, *tmp
;
243 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
244 cds_list_del(&list_entry
->head
);
250 * called with UST lock held.
252 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
254 struct lttng_probe_desc
*probe_desc
;
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
;