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 <lttng/ust-events.h>
18 #include "ltt-tracer-core.h"
21 * probe list is protected by ust_lock()/ust_unlock().
23 static CDS_LIST_HEAD(probe_list
);
26 const struct lttng_probe_desc
*find_provider(const char *provider
)
28 struct lttng_probe_desc
*iter
;
30 cds_list_for_each_entry(iter
, &probe_list
, head
) {
31 if (!strcmp(iter
->provider
, provider
))
38 const struct lttng_event_desc
*find_event(const char *name
)
40 struct lttng_probe_desc
*probe_desc
;
43 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
44 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
45 if (!strcmp(probe_desc
->event_desc
[i
]->name
, name
))
46 return probe_desc
->event_desc
[i
];
52 int ltt_probe_register(struct lttng_probe_desc
*desc
)
54 struct lttng_probe_desc
*iter
;
59 if (find_provider(desc
->provider
)) {
64 * TODO: This is O(N^2). Turn into a hash table when probe registration
65 * overhead becomes an issue.
67 for (i
= 0; i
< desc
->nr_events
; i
++) {
68 if (find_event(desc
->event_desc
[i
]->name
)) {
75 * We sort the providers by struct lttng_probe_desc pointer
78 cds_list_for_each_entry_reverse(iter
, &probe_list
, head
) {
79 BUG_ON(iter
== desc
); /* Should never be in the list twice */
81 /* We belong to the location right after iter. */
82 cds_list_add(&desc
->head
, &iter
->head
);
86 /* We should be added at the head of the list */
87 cds_list_add(&desc
->head
, &probe_list
);
91 * fix the events awaiting probe load.
93 for (i
= 0; i
< desc
->nr_events
; i
++) {
94 ret
= pending_probe_fix_events(desc
->event_desc
[i
]);
102 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
105 cds_list_del(&desc
->head
);
110 * called with UST lock held.
112 const struct lttng_event_desc
*ltt_event_get(const char *name
)
114 const struct lttng_event_desc
*event
;
116 event
= find_event(name
);
122 void ltt_event_put(const struct lttng_event_desc
*event
)
126 void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
128 struct tp_list_entry
*list_entry
, *tmp
;
130 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
131 cds_list_del(&list_entry
->head
);
137 * called with UST lock held.
139 int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
141 struct lttng_probe_desc
*probe_desc
;
144 CDS_INIT_LIST_HEAD(&list
->head
);
145 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
146 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
147 struct tp_list_entry
*list_entry
;
149 list_entry
= zmalloc(sizeof(*list_entry
));
152 cds_list_add(&list_entry
->head
, &list
->head
);
153 strncpy(list_entry
->tp
.name
,
154 probe_desc
->event_desc
[i
]->name
,
155 LTTNG_UST_SYM_NAME_LEN
);
156 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
157 if (!probe_desc
->event_desc
[i
]->loglevel
) {
158 list_entry
->tp
.loglevel
[0] = '\0';
159 list_entry
->tp
.loglevel_value
= 0;
161 strncpy(list_entry
->tp
.loglevel
,
162 (*probe_desc
->event_desc
[i
]->loglevel
)->identifier
,
163 LTTNG_UST_SYM_NAME_LEN
);
164 list_entry
->tp
.loglevel
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
165 list_entry
->tp
.loglevel_value
=
166 (*probe_desc
->event_desc
[i
]->loglevel
)->value
;
170 if (cds_list_empty(&list
->head
))
174 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
178 ltt_probes_prune_event_list(list
);
183 * Return current iteration position, advance internal iterator to next.
184 * Return NULL if end of list.
186 struct lttng_ust_tracepoint_iter
*
187 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
189 struct tp_list_entry
*entry
;
194 if (entry
->head
.next
== &list
->head
)
197 list
->iter
= cds_list_entry(entry
->head
.next
,
198 struct tp_list_entry
, head
);