Fix: liblttng-ust-ctl: missing ring buffer and counter clients init/exit symbols
[lttng-ust.git] / liblttng-ust / ust-core.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #define _LGPL_SOURCE
8 #include <stdint.h>
9 #include <stddef.h>
10 #include <stdlib.h>
11
12 #include "context-internal.h"
13 #include "ust-events-internal.h"
14 #include <usterr-signal-safe.h>
15 #include "lttng-tracer-core.h"
16 #include "lttng-rb-clients.h"
17 #include "lttng-counter-client.h"
18 #include "jhash.h"
19
20 static CDS_LIST_HEAD(lttng_transport_list);
21 static CDS_LIST_HEAD(lttng_counter_transport_list);
22
23 struct lttng_transport *lttng_ust_transport_find(const char *name)
24 {
25 struct lttng_transport *transport;
26
27 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
28 if (!strcmp(transport->name, name))
29 return transport;
30 }
31 return NULL;
32 }
33
34 struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
35 {
36 struct lttng_counter_transport *transport;
37
38 cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
39 if (!strcmp(transport->name, name))
40 return transport;
41 }
42 return NULL;
43 }
44
45 /**
46 * lttng_transport_register - LTT transport registration
47 * @transport: transport structure
48 *
49 * Registers a transport which can be used as output to extract the data out of
50 * LTTng. Called with ust_lock held.
51 */
52 void lttng_transport_register(struct lttng_transport *transport)
53 {
54 cds_list_add_tail(&transport->node, &lttng_transport_list);
55 }
56
57 /**
58 * lttng_transport_unregister - LTT transport unregistration
59 * @transport: transport structure
60 * Called with ust_lock held.
61 */
62 void lttng_transport_unregister(struct lttng_transport *transport)
63 {
64 cds_list_del(&transport->node);
65 }
66
67 /**
68 * lttng_counter_transport_register - LTTng counter transport registration
69 * @transport: transport structure
70 *
71 * Registers a counter transport which can be used as output to extract
72 * the data out of LTTng. Called with ust_lock held.
73 */
74 void lttng_counter_transport_register(struct lttng_counter_transport *transport)
75 {
76 cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
77 }
78
79 /**
80 * lttng_counter_transport_unregister - LTTng counter transport unregistration
81 * @transport: transport structure
82 * Called with ust_lock held.
83 */
84 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
85 {
86 cds_list_del(&transport->node);
87 }
88
89 /*
90 * Needed by comm layer.
91 */
92 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session,
93 struct lttng_ust_enum_desc *enum_desc)
94 {
95 struct lttng_enum *_enum;
96 struct cds_hlist_head *head;
97 struct cds_hlist_node *node;
98 size_t name_len = strlen(enum_desc->name);
99 uint32_t hash;
100
101 hash = jhash(enum_desc->name, name_len, 0);
102 head = &session->priv->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
103 cds_hlist_for_each_entry(_enum, node, head, hlist) {
104 assert(_enum->desc);
105 if (_enum->desc == enum_desc)
106 return _enum;
107 }
108 return NULL;
109 }
110
111 size_t lttng_ust_dummy_get_size(struct lttng_ust_ctx_field *field, size_t offset)
112 {
113 size_t size = 0;
114
115 size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(char));
116 size += sizeof(char); /* tag */
117 return size;
118 }
119
120 void lttng_ust_dummy_record(struct lttng_ust_ctx_field *field,
121 struct lttng_ust_lib_ring_buffer_ctx *ctx,
122 struct lttng_ust_channel_buffer *chan)
123 {
124 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
125
126 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char));
127 }
128
129 void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field *field,
130 struct lttng_ust_ctx_value *value)
131 {
132 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
133 }
134
135 int lttng_context_is_app(const char *name)
136 {
137 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
138 return 0;
139 }
140 return 1;
141 }
142
143 struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
144 {
145 struct lttng_ust_channel_buffer *lttng_chan_buf;
146 struct lttng_ust_channel_common *lttng_chan_common;
147 struct lttng_ust_channel_buffer_private *lttng_chan_buf_priv;
148
149 lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer));
150 if (!lttng_chan_buf)
151 goto lttng_chan_buf_error;
152 lttng_chan_buf->struct_size = sizeof(struct lttng_ust_channel_buffer);
153 lttng_chan_common = zmalloc(sizeof(struct lttng_ust_channel_common));
154 if (!lttng_chan_common)
155 goto lttng_chan_common_error;
156 lttng_chan_common->struct_size = sizeof(struct lttng_ust_channel_common);
157 lttng_chan_buf_priv = zmalloc(sizeof(struct lttng_ust_channel_buffer_private));
158 if (!lttng_chan_buf_priv)
159 goto lttng_chan_buf_priv_error;
160 lttng_chan_buf->parent = lttng_chan_common;
161 lttng_chan_common->type = LTTNG_UST_CHANNEL_TYPE_BUFFER;
162 lttng_chan_common->child = lttng_chan_buf;
163 lttng_chan_buf->priv = lttng_chan_buf_priv;
164 lttng_chan_common->priv = &lttng_chan_buf_priv->parent;
165 lttng_chan_buf_priv->pub = lttng_chan_buf;
166 lttng_chan_buf_priv->parent.pub = lttng_chan_common;
167
168 return lttng_chan_buf;
169
170 lttng_chan_buf_priv_error:
171 free(lttng_chan_common);
172 lttng_chan_common_error:
173 free(lttng_chan_buf);
174 lttng_chan_buf_error:
175 return NULL;
176 }
177
178 void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
179 {
180 switch (chan->type) {
181 case LTTNG_UST_CHANNEL_TYPE_BUFFER:
182 {
183 struct lttng_ust_channel_buffer *chan_buf;
184
185 chan_buf = (struct lttng_ust_channel_buffer *)chan->child;
186 free(chan_buf->parent);
187 free(chan_buf->priv);
188 free(chan_buf);
189 break;
190 }
191 default:
192 abort();
193 }
194 }
195
196 void lttng_ust_ring_buffer_clients_init(void)
197 {
198 lttng_ring_buffer_metadata_client_init();
199 lttng_ring_buffer_client_overwrite_init();
200 lttng_ring_buffer_client_overwrite_rt_init();
201 lttng_ring_buffer_client_discard_init();
202 lttng_ring_buffer_client_discard_rt_init();
203 }
204
205 void lttng_ust_ring_buffer_clients_exit(void)
206 {
207 lttng_ring_buffer_client_discard_rt_exit();
208 lttng_ring_buffer_client_discard_exit();
209 lttng_ring_buffer_client_overwrite_rt_exit();
210 lttng_ring_buffer_client_overwrite_exit();
211 lttng_ring_buffer_metadata_client_exit();
212 }
213
214 void lttng_ust_counter_clients_init(void)
215 {
216 lttng_counter_client_percpu_64_modular_init();
217 lttng_counter_client_percpu_32_modular_init();
218 }
219
220 void lttng_ust_counter_clients_exit(void)
221 {
222 lttng_counter_client_percpu_32_modular_exit();
223 lttng_counter_client_percpu_64_modular_exit();
224 }
This page took 0.034103 seconds and 5 git commands to generate.