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>
15 #include <ust/lttng-events.h>
17 static CDS_LIST_HEAD(probe_list
);
18 static DEFINE_MUTEX(probe_mutex
);
21 const struct lttng_event_desc
*find_event(const char *name
)
23 struct lttng_probe_desc
*probe_desc
;
26 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
27 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
28 if (!strcmp(probe_desc
->event_desc
[i
].name
, name
))
29 return &probe_desc
->event_desc
[i
];
35 int ltt_probe_register(struct lttng_probe_desc
*desc
)
40 pthread_mutex_lock(&probe_mutex
);
42 * TODO: This is O(N^2). Turn into a hash table when probe registration
43 * overhead becomes an issue.
45 for (i
= 0; i
< desc
->nr_events
; i
++) {
46 if (find_event(desc
->event_desc
[i
].name
)) {
51 cds_list_add(&desc
->head
, &probe_list
);
53 pthread_mutex_unlock(&probe_mutex
);
57 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
59 pthread_mutex_lock(&probe_mutex
);
60 cds_list_del(&desc
->head
);
61 pthread_mutex_unlock(&probe_mutex
);
64 const struct lttng_event_desc
*ltt_event_get(const char *name
)
66 const struct lttng_event_desc
*event
;
68 pthread_mutex_lock(&probe_mutex
);
69 event
= find_event(name
);
70 pthread_mutex_unlock(&probe_mutex
);
76 void ltt_event_put(const struct lttng_event_desc
*event
)
82 void *tp_list_start(struct seq_file
*m
, loff_t
*pos
)
84 struct lttng_probe_desc
*probe_desc
;
87 pthread_mutex_lock(&probe_mutex
);
88 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
89 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
91 return (void *) &probe_desc
->event_desc
[i
];
99 void *tp_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
101 struct lttng_probe_desc
*probe_desc
;
105 cds_list_for_each_entry(probe_desc
, &probe_list
, head
) {
106 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
108 return (void *) &probe_desc
->event_desc
[i
];
116 void tp_list_stop(struct seq_file
*m
, void *p
)
118 pthread_mutex_unlock(&probe_mutex
);
122 int tp_list_show(struct seq_file
*m
, void *p
)
124 const struct lttng_event_desc
*probe_desc
= p
;
127 * Don't export lttng internal events (metadata).
129 if (!strncmp(probe_desc
->name
, "lttng_", sizeof("lttng_") - 1))
131 seq_printf(m
, "event { name = %s; };\n",
137 const struct seq_operations lttng_tracepoint_list_seq_ops
= {
138 .start
= tp_list_start
,
139 .next
= tp_list_next
,
140 .stop
= tp_list_stop
,
141 .show
= tp_list_show
,
145 int lttng_tracepoint_list_open(struct inode
*inode
, struct file
*file
)
147 return seq_open(file
, <tng_tracepoint_list_seq_ops
);
150 const struct file_operations lttng_tracepoint_list_fops
= {
151 .open
= lttng_tracepoint_list_open
,
154 .release
= seq_release
,