Commit | Line | Data |
---|---|---|
5e96a467 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
5e96a467 MD |
3 | * |
4 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5e96a467 MD |
5 | */ |
6 | ||
3fbec7dc | 7 | #define _LGPL_SOURCE |
fb31eb73 | 8 | #include <stdint.h> |
b4051ad8 | 9 | #include <stddef.h> |
5e96a467 | 10 | #include <stdlib.h> |
bb7ad29d | 11 | |
b62f8205 | 12 | #include "context-internal.h" |
36c52fff | 13 | #include "lib/lttng-ust/events.h" |
9d315d6d | 14 | #include "common/logging.h" |
797b05f6 | 15 | #include "lttng-tracer-core.h" |
f27f1026 MD |
16 | #include "lttng-rb-clients.h" |
17 | #include "lttng-counter-client.h" | |
e58e5ad5 | 18 | #include "common/jhash.h" |
5e96a467 | 19 | |
7dd08bec | 20 | static CDS_LIST_HEAD(lttng_transport_list); |
ebabbf58 | 21 | static CDS_LIST_HEAD(lttng_counter_transport_list); |
c1fca457 | 22 | |
65c48d6a | 23 | struct lttng_transport *lttng_ust_transport_find(const char *name) |
c1fca457 | 24 | { |
7dd08bec | 25 | struct lttng_transport *transport; |
c1fca457 | 26 | |
7dd08bec | 27 | cds_list_for_each_entry(transport, <tng_transport_list, node) { |
c1fca457 MD |
28 | if (!strcmp(transport->name, name)) |
29 | return transport; | |
30 | } | |
31 | return NULL; | |
32 | } | |
33 | ||
ebabbf58 MD |
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, <tng_counter_transport_list, node) { | |
39 | if (!strcmp(transport->name, name)) | |
40 | return transport; | |
41 | } | |
42 | return NULL; | |
43 | } | |
44 | ||
c1fca457 | 45 | /** |
7dd08bec | 46 | * lttng_transport_register - LTT transport registration |
c1fca457 MD |
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 | */ | |
7dd08bec | 52 | void lttng_transport_register(struct lttng_transport *transport) |
c1fca457 | 53 | { |
7dd08bec | 54 | cds_list_add_tail(&transport->node, <tng_transport_list); |
c1fca457 MD |
55 | } |
56 | ||
57 | /** | |
7dd08bec | 58 | * lttng_transport_unregister - LTT transport unregistration |
c1fca457 MD |
59 | * @transport: transport structure |
60 | * Called with ust_lock held. | |
61 | */ | |
7dd08bec | 62 | void lttng_transport_unregister(struct lttng_transport *transport) |
c1fca457 MD |
63 | { |
64 | cds_list_del(&transport->node); | |
65 | } | |
c785c634 | 66 | |
ebabbf58 MD |
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, <tng_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 | ||
4e48b5d2 | 89 | size_t lttng_ust_dummy_get_size(void *priv __attribute__((unused)), |
b2e37d27 | 90 | struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)), |
2208d8b5 | 91 | size_t offset) |
797b05f6 MD |
92 | { |
93 | size_t size = 0; | |
94 | ||
b5457df5 | 95 | size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(char)); |
797b05f6 MD |
96 | size += sizeof(char); /* tag */ |
97 | return size; | |
98 | } | |
99 | ||
4e48b5d2 | 100 | void lttng_ust_dummy_record(void *priv __attribute__((unused)), |
b2e37d27 MD |
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) | |
797b05f6 MD |
104 | { |
105 | char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE; | |
106 | ||
8936b6c0 | 107 | chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char)); |
797b05f6 MD |
108 | } |
109 | ||
4e48b5d2 | 110 | void lttng_ust_dummy_get_value(void *priv __attribute__((unused)), |
b2e37d27 | 111 | struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)), |
daacdbfc | 112 | struct lttng_ust_ctx_value *value) |
797b05f6 MD |
113 | { |
114 | value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE; | |
115 | } | |
ce47f5d8 MD |
116 | |
117 | int lttng_context_is_app(const char *name) | |
118 | { | |
119 | if (strncmp(name, "$app.", strlen("$app.")) != 0) { | |
120 | return 0; | |
121 | } | |
122 | return 1; | |
123 | } | |
e7bc0ef6 MD |
124 | |
125 | struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void) | |
126 | { | |
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; | |
130 | ||
131 | lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer)); | |
132 | if (!lttng_chan_buf) | |
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; | |
149 | ||
150 | return lttng_chan_buf; | |
151 | ||
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: | |
157 | return NULL; | |
158 | } | |
159 | ||
160 | void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan) | |
161 | { | |
162 | switch (chan->type) { | |
163 | case LTTNG_UST_CHANNEL_TYPE_BUFFER: | |
164 | { | |
165 | struct lttng_ust_channel_buffer *chan_buf; | |
166 | ||
167 | chan_buf = (struct lttng_ust_channel_buffer *)chan->child; | |
168 | free(chan_buf->parent); | |
169 | free(chan_buf->priv); | |
170 | free(chan_buf); | |
171 | break; | |
172 | } | |
173 | default: | |
174 | abort(); | |
175 | } | |
176 | } | |
f27f1026 MD |
177 | |
178 | void lttng_ust_ring_buffer_clients_init(void) | |
179 | { | |
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(); | |
185 | } | |
186 | ||
187 | void lttng_ust_ring_buffer_clients_exit(void) | |
188 | { | |
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(); | |
194 | } | |
195 | ||
196 | void lttng_ust_counter_clients_init(void) | |
197 | { | |
198 | lttng_counter_client_percpu_64_modular_init(); | |
199 | lttng_counter_client_percpu_32_modular_init(); | |
200 | } | |
201 | ||
202 | void lttng_ust_counter_clients_exit(void) | |
203 | { | |
204 | lttng_counter_client_percpu_32_modular_exit(); | |
205 | lttng_counter_client_percpu_64_modular_exit(); | |
206 | } |