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 "ust-events-internal.h"
14 #include <usterr-signal-safe.h>
15 #include "lttng-tracer-core.h"
18 static CDS_LIST_HEAD(lttng_transport_list
);
19 static CDS_LIST_HEAD(lttng_counter_transport_list
);
21 struct lttng_transport
*lttng_ust_transport_find(const char *name
)
23 struct lttng_transport
*transport
;
25 cds_list_for_each_entry(transport
, <tng_transport_list
, node
) {
26 if (!strcmp(transport
->name
, name
))
32 struct lttng_counter_transport
*lttng_counter_transport_find(const char *name
)
34 struct lttng_counter_transport
*transport
;
36 cds_list_for_each_entry(transport
, <tng_counter_transport_list
, node
) {
37 if (!strcmp(transport
->name
, name
))
44 * lttng_transport_register - LTT transport registration
45 * @transport: transport structure
47 * Registers a transport which can be used as output to extract the data out of
48 * LTTng. Called with ust_lock held.
50 void lttng_transport_register(struct lttng_transport
*transport
)
52 cds_list_add_tail(&transport
->node
, <tng_transport_list
);
56 * lttng_transport_unregister - LTT transport unregistration
57 * @transport: transport structure
58 * Called with ust_lock held.
60 void lttng_transport_unregister(struct lttng_transport
*transport
)
62 cds_list_del(&transport
->node
);
66 * lttng_counter_transport_register - LTTng counter transport registration
67 * @transport: transport structure
69 * Registers a counter transport which can be used as output to extract
70 * the data out of LTTng. Called with ust_lock held.
72 void lttng_counter_transport_register(struct lttng_counter_transport
*transport
)
74 cds_list_add_tail(&transport
->node
, <tng_counter_transport_list
);
78 * lttng_counter_transport_unregister - LTTng counter transport unregistration
79 * @transport: transport structure
80 * Called with ust_lock held.
82 void lttng_counter_transport_unregister(struct lttng_counter_transport
*transport
)
84 cds_list_del(&transport
->node
);
88 * Needed by comm layer.
90 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_ust_session
*session
,
91 struct lttng_ust_enum_desc
*enum_desc
)
93 struct lttng_enum
*_enum
;
94 struct cds_hlist_head
*head
;
95 struct cds_hlist_node
*node
;
96 size_t name_len
= strlen(enum_desc
->name
);
99 hash
= jhash(enum_desc
->name
, name_len
, 0);
100 head
= &session
->priv
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
101 cds_hlist_for_each_entry(_enum
, node
, head
, hlist
) {
103 if (_enum
->desc
== enum_desc
)
109 size_t lttng_ust_dummy_get_size(struct lttng_ust_ctx_field
*field
, size_t offset
)
113 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(char));
114 size
+= sizeof(char); /* tag */
118 void lttng_ust_dummy_record(struct lttng_ust_ctx_field
*field
,
119 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
120 struct lttng_ust_channel_buffer
*chan
)
122 char sel_char
= (char) LTTNG_UST_DYNAMIC_TYPE_NONE
;
124 chan
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
), lttng_ust_rb_alignof(sel_char
));
127 void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field
*field
,
128 struct lttng_ust_ctx_value
*value
)
130 value
->sel
= LTTNG_UST_DYNAMIC_TYPE_NONE
;
133 int lttng_context_is_app(const char *name
)
135 if (strncmp(name
, "$app.", strlen("$app.")) != 0) {
141 struct lttng_ust_channel_buffer
*lttng_ust_alloc_channel_buffer(void)
143 struct lttng_ust_channel_buffer
*lttng_chan_buf
;
144 struct lttng_ust_channel_common
*lttng_chan_common
;
145 struct lttng_ust_channel_buffer_private
*lttng_chan_buf_priv
;
147 lttng_chan_buf
= zmalloc(sizeof(struct lttng_ust_channel_buffer
));
149 goto lttng_chan_buf_error
;
150 lttng_chan_buf
->struct_size
= sizeof(struct lttng_ust_channel_buffer
);
151 lttng_chan_common
= zmalloc(sizeof(struct lttng_ust_channel_common
));
152 if (!lttng_chan_common
)
153 goto lttng_chan_common_error
;
154 lttng_chan_common
->struct_size
= sizeof(struct lttng_ust_channel_common
);
155 lttng_chan_buf_priv
= zmalloc(sizeof(struct lttng_ust_channel_buffer_private
));
156 if (!lttng_chan_buf_priv
)
157 goto lttng_chan_buf_priv_error
;
158 lttng_chan_buf
->parent
= lttng_chan_common
;
159 lttng_chan_common
->type
= LTTNG_UST_CHANNEL_TYPE_BUFFER
;
160 lttng_chan_common
->child
= lttng_chan_buf
;
161 lttng_chan_buf
->priv
= lttng_chan_buf_priv
;
162 lttng_chan_common
->priv
= <tng_chan_buf_priv
->parent
;
163 lttng_chan_buf_priv
->pub
= lttng_chan_buf
;
164 lttng_chan_buf_priv
->parent
.pub
= lttng_chan_common
;
166 return lttng_chan_buf
;
168 lttng_chan_buf_priv_error
:
169 free(lttng_chan_common
);
170 lttng_chan_common_error
:
171 free(lttng_chan_buf
);
172 lttng_chan_buf_error
:
176 void lttng_ust_free_channel_common(struct lttng_ust_channel_common
*chan
)
178 switch (chan
->type
) {
179 case LTTNG_UST_CHANNEL_TYPE_BUFFER
:
181 struct lttng_ust_channel_buffer
*chan_buf
;
183 chan_buf
= (struct lttng_ust_channel_buffer
*)chan
->child
;
184 free(chan_buf
->parent
);
185 free(chan_buf
->priv
);