2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include "context-internal.h"
13 #include "lib/lttng-ust/events.h"
14 #include "common/logging.h"
15 #include "lttng-tracer-core.h"
16 #include "lttng-rb-clients.h"
17 #include "lttng-counter-client.h"
18 #include "common/jhash.h"
20 static CDS_LIST_HEAD(lttng_transport_list
);
21 static CDS_LIST_HEAD(lttng_counter_transport_list
);
23 struct lttng_transport
*lttng_ust_transport_find(const char *name
)
25 struct lttng_transport
*transport
;
27 cds_list_for_each_entry(transport
, <tng_transport_list
, node
) {
28 if (!strcmp(transport
->name
, name
))
34 struct lttng_counter_transport
*lttng_counter_transport_find(const char *name
)
36 struct lttng_counter_transport
*transport
;
38 cds_list_for_each_entry(transport
, <tng_counter_transport_list
, node
) {
39 if (!strcmp(transport
->name
, name
))
46 * lttng_transport_register - LTT transport registration
47 * @transport: transport structure
49 * Registers a transport which can be used as output to extract the data out of
50 * LTTng. Called with ust_lock held.
52 void lttng_transport_register(struct lttng_transport
*transport
)
54 cds_list_add_tail(&transport
->node
, <tng_transport_list
);
58 * lttng_transport_unregister - LTT transport unregistration
59 * @transport: transport structure
60 * Called with ust_lock held.
62 void lttng_transport_unregister(struct lttng_transport
*transport
)
64 cds_list_del(&transport
->node
);
68 * lttng_counter_transport_register - LTTng counter transport registration
69 * @transport: transport structure
71 * Registers a counter transport which can be used as output to extract
72 * the data out of LTTng. Called with ust_lock held.
74 void lttng_counter_transport_register(struct lttng_counter_transport
*transport
)
76 cds_list_add_tail(&transport
->node
, <tng_counter_transport_list
);
80 * lttng_counter_transport_unregister - LTTng counter transport unregistration
81 * @transport: transport structure
82 * Called with ust_lock held.
84 void lttng_counter_transport_unregister(struct lttng_counter_transport
*transport
)
86 cds_list_del(&transport
->node
);
89 size_t lttng_ust_dummy_get_size(void *priv
__attribute__((unused
)),
90 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
95 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(char));
96 size
+= sizeof(char); /* tag */
100 void lttng_ust_dummy_record(void *priv
__attribute__((unused
)),
101 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
102 struct lttng_ust_ring_buffer_ctx
*ctx
,
103 struct lttng_ust_channel_buffer
*chan
)
105 char sel_char
= (char) LTTNG_UST_DYNAMIC_TYPE_NONE
;
107 chan
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
), lttng_ust_rb_alignof(sel_char
));
110 void lttng_ust_dummy_get_value(void *priv
__attribute__((unused
)),
111 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
112 struct lttng_ust_ctx_value
*value
)
114 value
->sel
= LTTNG_UST_DYNAMIC_TYPE_NONE
;
117 int lttng_context_is_app(const char *name
)
119 if (strncmp(name
, "$app.", strlen("$app.")) != 0) {
125 struct lttng_ust_channel_buffer
*lttng_ust_alloc_channel_buffer(void)
127 struct lttng_ust_channel_buffer
*lttng_chan_buf
;
128 struct lttng_ust_channel_common
*lttng_chan_common
;
129 struct lttng_ust_channel_buffer_private
*lttng_chan_buf_priv
;
131 lttng_chan_buf
= zmalloc(sizeof(struct lttng_ust_channel_buffer
));
133 goto lttng_chan_buf_error
;
134 lttng_chan_buf
->struct_size
= sizeof(struct lttng_ust_channel_buffer
);
135 lttng_chan_common
= zmalloc(sizeof(struct lttng_ust_channel_common
));
136 if (!lttng_chan_common
)
137 goto lttng_chan_common_error
;
138 lttng_chan_common
->struct_size
= sizeof(struct lttng_ust_channel_common
);
139 lttng_chan_buf_priv
= zmalloc(sizeof(struct lttng_ust_channel_buffer_private
));
140 if (!lttng_chan_buf_priv
)
141 goto lttng_chan_buf_priv_error
;
142 lttng_chan_buf
->parent
= lttng_chan_common
;
143 lttng_chan_common
->type
= LTTNG_UST_CHANNEL_TYPE_BUFFER
;
144 lttng_chan_common
->child
= lttng_chan_buf
;
145 lttng_chan_buf
->priv
= lttng_chan_buf_priv
;
146 lttng_chan_common
->priv
= <tng_chan_buf_priv
->parent
;
147 lttng_chan_buf_priv
->pub
= lttng_chan_buf
;
148 lttng_chan_buf_priv
->parent
.pub
= lttng_chan_common
;
150 return lttng_chan_buf
;
152 lttng_chan_buf_priv_error
:
153 free(lttng_chan_common
);
154 lttng_chan_common_error
:
155 free(lttng_chan_buf
);
156 lttng_chan_buf_error
:
160 void lttng_ust_free_channel_common(struct lttng_ust_channel_common
*chan
)
162 switch (chan
->type
) {
163 case LTTNG_UST_CHANNEL_TYPE_BUFFER
:
165 struct lttng_ust_channel_buffer
*chan_buf
;
167 chan_buf
= (struct lttng_ust_channel_buffer
*)chan
->child
;
168 free(chan_buf
->parent
);
169 free(chan_buf
->priv
);
178 void lttng_ust_ring_buffer_clients_init(void)
180 lttng_ring_buffer_metadata_client_init();
181 lttng_ring_buffer_client_overwrite_init();
182 lttng_ring_buffer_client_overwrite_rt_init();
183 lttng_ring_buffer_client_discard_init();
184 lttng_ring_buffer_client_discard_rt_init();
187 void lttng_ust_ring_buffer_clients_exit(void)
189 lttng_ring_buffer_client_discard_rt_exit();
190 lttng_ring_buffer_client_discard_exit();
191 lttng_ring_buffer_client_overwrite_rt_exit();
192 lttng_ring_buffer_client_overwrite_exit();
193 lttng_ring_buffer_metadata_client_exit();
196 void lttng_ust_counter_clients_init(void)
198 lttng_counter_client_percpu_64_modular_init();
199 lttng_counter_client_percpu_32_modular_init();
202 void lttng_ust_counter_clients_exit(void)
204 lttng_counter_client_percpu_32_modular_exit();
205 lttng_counter_client_percpu_64_modular_exit();