4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng probes registry.
8 * Dual LGPL v2.1/GPL v2 license.
13 #include <urcu/list.h>
14 #include <urcu/hlist.h>
15 #include <lttng/ust-events.h>
16 #include <lttng/tracepoint.h>
21 #include "ltt-tracer-core.h"
26 * probe list is protected by ust_lock()/ust_unlock().
28 static CDS_LIST_HEAD(probe_list
);
31 const struct lttng_probe_desc
*find_provider(const char *provider
)
33 struct lttng_probe_desc
*iter
;
35 cds_list_for_each_entry(iter
, &probe_list
, head
) {
36 if (!strcmp(iter
->provider
, provider
))
43 const struct lttng_event_desc
*find_event(const char *name
)
45 struct lttng_probe_desc
*probe_desc
;
48 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
49 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
50 if (!strncmp(probe_desc
->event_desc
[i
]->name
, name
,
51 LTTNG_UST_SYM_NAME_LEN
- 1))
52 return probe_desc
->event_desc
[i
];
58 int ltt_probe_register(struct lttng_probe_desc
*desc
)
60 struct lttng_probe_desc
*iter
;
65 if (find_provider(desc
->provider
)) {
70 * TODO: This is O(N^2). Turn into a hash table when probe registration
71 * overhead becomes an issue.
73 for (i
= 0; i
< desc
->nr_events
; i
++) {
74 if (find_event(desc
->event_desc
[i
]->name
)) {
81 * We sort the providers by struct lttng_probe_desc pointer
84 cds_list_for_each_entry_reverse(iter
, &probe_list
, head
) {
85 BUG_ON(iter
== desc
); /* Should never be in the list twice */
87 /* We belong to the location right after iter. */
88 cds_list_add(&desc
->head
, &iter
->head
);
92 /* We should be added at the head of the list */
93 cds_list_add(&desc
->head
, &probe_list
);
95 DBG("just registered probe %s containing %u events",
96 desc
->provider
, desc
->nr_events
);
98 * fix the events awaiting probe load.
100 for (i
= 0; i
< desc
->nr_events
; i
++) {
101 ret
= pending_probe_fix_events(desc
->event_desc
[i
]);
109 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
112 cds_list_del(&desc
->head
);
113 DBG("just unregistered probe %s", desc
->provider
);
118 * called with UST lock held.
120 const struct lttng_event_desc
*ltt_event_get(const char *name
)
122 const struct lttng_event_desc
*event
;
124 event
= find_event(name
);
130 void ltt_event_put(const struct lttng_event_desc
*event
)
134 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
136 struct tp_list_entry
*list_entry
, *tmp
;
138 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
139 cds_list_del(&list_entry
->head
);
145 * called with UST lock held.
147 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
149 struct lttng_probe_desc
*probe_desc
;
152 CDS_INIT_LIST_HEAD(&list
->head
);
153 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
154 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
155 struct tp_list_entry
*list_entry
;
157 list_entry
= zmalloc(sizeof(*list_entry
));
160 cds_list_add(&list_entry
->head
, &list
->head
);
161 strncpy(list_entry
->tp
.name
,
162 probe_desc
->event_desc
[i
]->name
,
163 LTTNG_UST_SYM_NAME_LEN
);
164 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
165 if (!probe_desc
->event_desc
[i
]->loglevel
) {
166 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
168 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
172 if (cds_list_empty(&list
->head
))
176 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
180 ltt_probes_prune_event_list(list
);
185 * Return current iteration position, advance internal iterator to next.
186 * Return NULL if end of list.
188 struct lttng_ust_tracepoint_iter
*
189 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
191 struct tp_list_entry
*entry
;
196 if (entry
->head
.next
== &list
->head
)
199 list
->iter
= cds_list_entry(entry
->head
.next
,
200 struct tp_list_entry
, head
);
205 * marshall all probes/all events and create those that fit the
206 * wildcard. Add them to the events list as created.
208 void ltt_probes_create_wildcard_events(struct wildcard_entry
*entry
,
209 struct session_wildcard
*wildcard
)
211 struct lttng_probe_desc
*probe_desc
;
212 struct lttng_ust_event event_param
;
215 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
216 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
217 const struct lttng_event_desc
*event_desc
;
220 event_desc
= probe_desc
->event_desc
[i
];
221 /* compare excluding final '*' */
222 assert(strlen(entry
->name
) > 0);
223 if (strcmp(event_desc
->name
, "lttng_ust:metadata")
224 && (strlen(entry
->name
) == 1
225 || !strncmp(event_desc
->name
, entry
->name
,
226 strlen(entry
->name
) - 1))) {
227 if (ltt_loglevel_match(event_desc
,
228 entry
->loglevel_type
,
234 struct ltt_event
*ev
;
237 memcpy(&event_param
, &wildcard
->event_param
,
238 sizeof(event_param
));
239 memcpy(event_param
.name
,
241 sizeof(event_param
.name
));
243 ret
= ltt_event_create(wildcard
->chan
,
247 DBG("Error creating event");
250 cds_list_add(&ev
->wildcard_list
,