libust 2.0 + ringbuffer + TRACEPOINT_EVENT builds and runs
[lttng-ust.git] / libust / ltt-probes.c
1 /*
2 * ltt-probes.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng probes registry.
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11 #include <string.h>
12 #include <errno.h>
13 #include <urcu/list.h>
14 #include <ust/core.h>
15 #include <ust/lttng-events.h>
16
17 static CDS_LIST_HEAD(probe_list);
18 static DEFINE_MUTEX(probe_mutex);
19
20 static
21 const struct lttng_event_desc *find_event(const char *name)
22 {
23 struct lttng_probe_desc *probe_desc;
24 int i;
25
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];
30 }
31 }
32 return NULL;
33 }
34
35 int ltt_probe_register(struct lttng_probe_desc *desc)
36 {
37 int ret = 0;
38 int i;
39
40 pthread_mutex_lock(&probe_mutex);
41 /*
42 * TODO: This is O(N^2). Turn into a hash table when probe registration
43 * overhead becomes an issue.
44 */
45 for (i = 0; i < desc->nr_events; i++) {
46 if (find_event(desc->event_desc[i].name)) {
47 ret = -EEXIST;
48 goto end;
49 }
50 }
51 cds_list_add(&desc->head, &probe_list);
52 end:
53 pthread_mutex_unlock(&probe_mutex);
54 return ret;
55 }
56
57 void ltt_probe_unregister(struct lttng_probe_desc *desc)
58 {
59 pthread_mutex_lock(&probe_mutex);
60 cds_list_del(&desc->head);
61 pthread_mutex_unlock(&probe_mutex);
62 }
63
64 const struct lttng_event_desc *ltt_event_get(const char *name)
65 {
66 const struct lttng_event_desc *event;
67
68 pthread_mutex_lock(&probe_mutex);
69 event = find_event(name);
70 pthread_mutex_unlock(&probe_mutex);
71 if (!event)
72 return NULL;
73 return event;
74 }
75
76 void ltt_event_put(const struct lttng_event_desc *event)
77 {
78 }
79
80 #if 0
81 static
82 void *tp_list_start(struct seq_file *m, loff_t *pos)
83 {
84 struct lttng_probe_desc *probe_desc;
85 int iter = 0, i;
86
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++) {
90 if (iter++ >= *pos)
91 return (void *) &probe_desc->event_desc[i];
92 }
93 }
94 /* End of list */
95 return NULL;
96 }
97
98 static
99 void *tp_list_next(struct seq_file *m, void *p, loff_t *ppos)
100 {
101 struct lttng_probe_desc *probe_desc;
102 int iter = 0, i;
103
104 (*ppos)++;
105 cds_list_for_each_entry(probe_desc, &probe_list, head) {
106 for (i = 0; i < probe_desc->nr_events; i++) {
107 if (iter++ >= *ppos)
108 return (void *) &probe_desc->event_desc[i];
109 }
110 }
111 /* End of list */
112 return NULL;
113 }
114
115 static
116 void tp_list_stop(struct seq_file *m, void *p)
117 {
118 pthread_mutex_unlock(&probe_mutex);
119 }
120
121 static
122 int tp_list_show(struct seq_file *m, void *p)
123 {
124 const struct lttng_event_desc *probe_desc = p;
125
126 /*
127 * Don't export lttng internal events (metadata).
128 */
129 if (!strncmp(probe_desc->name, "lttng_", sizeof("lttng_") - 1))
130 return 0;
131 seq_printf(m, "event { name = %s; };\n",
132 probe_desc->name);
133 return 0;
134 }
135
136 static
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,
142 };
143
144 static
145 int lttng_tracepoint_list_open(struct inode *inode, struct file *file)
146 {
147 return seq_open(file, &lttng_tracepoint_list_seq_ops);
148 }
149
150 const struct file_operations lttng_tracepoint_list_fops = {
151 .open = lttng_tracepoint_list_open,
152 .read = seq_read,
153 .llseek = seq_lseek,
154 .release = seq_release,
155 };
156 #endif //0
This page took 0.032092 seconds and 4 git commands to generate.