Namespace remaining symbols in lttng/ringbuffer-context.h
[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 "ust-events-internal.h"
13 #include <usterr-signal-safe.h>
14 #include "lttng-tracer-core.h"
15 #include "jhash.h"
16
17 static CDS_LIST_HEAD(lttng_transport_list);
18 static CDS_LIST_HEAD(lttng_counter_transport_list);
19
20 struct lttng_transport *lttng_ust_transport_find(const char *name)
21 {
22 struct lttng_transport *transport;
23
24 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
25 if (!strcmp(transport->name, name))
26 return transport;
27 }
28 return NULL;
29 }
30
31 struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
32 {
33 struct lttng_counter_transport *transport;
34
35 cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
36 if (!strcmp(transport->name, name))
37 return transport;
38 }
39 return NULL;
40 }
41
42 /**
43 * lttng_transport_register - LTT transport registration
44 * @transport: transport structure
45 *
46 * Registers a transport which can be used as output to extract the data out of
47 * LTTng. Called with ust_lock held.
48 */
49 void lttng_transport_register(struct lttng_transport *transport)
50 {
51 cds_list_add_tail(&transport->node, &lttng_transport_list);
52 }
53
54 /**
55 * lttng_transport_unregister - LTT transport unregistration
56 * @transport: transport structure
57 * Called with ust_lock held.
58 */
59 void lttng_transport_unregister(struct lttng_transport *transport)
60 {
61 cds_list_del(&transport->node);
62 }
63
64 /**
65 * lttng_counter_transport_register - LTTng counter transport registration
66 * @transport: transport structure
67 *
68 * Registers a counter transport which can be used as output to extract
69 * the data out of LTTng. Called with ust_lock held.
70 */
71 void lttng_counter_transport_register(struct lttng_counter_transport *transport)
72 {
73 cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
74 }
75
76 /**
77 * lttng_counter_transport_unregister - LTTng counter transport unregistration
78 * @transport: transport structure
79 * Called with ust_lock held.
80 */
81 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
82 {
83 cds_list_del(&transport->node);
84 }
85
86 /*
87 * Needed by comm layer.
88 */
89 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session,
90 struct lttng_ust_enum_desc *enum_desc)
91 {
92 struct lttng_enum *_enum;
93 struct cds_hlist_head *head;
94 struct cds_hlist_node *node;
95 size_t name_len = strlen(enum_desc->name);
96 uint32_t hash;
97
98 hash = jhash(enum_desc->name, name_len, 0);
99 head = &session->priv->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
100 cds_hlist_for_each_entry(_enum, node, head, hlist) {
101 assert(_enum->desc);
102 if (_enum->desc == enum_desc)
103 return _enum;
104 }
105 return NULL;
106 }
107
108 size_t lttng_ust_dummy_get_size(struct lttng_ust_ctx_field *field, size_t offset)
109 {
110 size_t size = 0;
111
112 size += lttng_ust_lib_ring_buffer_align(offset, lttng_alignof(char));
113 size += sizeof(char); /* tag */
114 return size;
115 }
116
117 void lttng_ust_dummy_record(struct lttng_ust_ctx_field *field,
118 struct lttng_ust_lib_ring_buffer_ctx *ctx,
119 struct lttng_ust_channel_buffer *chan)
120 {
121 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
122
123 lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_alignof(sel_char));
124 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char));
125 }
126
127 void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field *field,
128 struct lttng_ust_ctx_value *value)
129 {
130 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
131 }
132
133 int lttng_context_is_app(const char *name)
134 {
135 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
136 return 0;
137 }
138 return 1;
139 }
140
141 struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
142 {
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;
146
147 lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer));
148 if (!lttng_chan_buf)
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 = &lttng_chan_buf_priv->parent;
163 lttng_chan_buf_priv->pub = lttng_chan_buf;
164 lttng_chan_buf_priv->parent.pub = lttng_chan_common;
165
166 return lttng_chan_buf;
167
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:
173 return NULL;
174 }
175
176 void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
177 {
178 switch (chan->type) {
179 case LTTNG_UST_CHANNEL_TYPE_BUFFER:
180 {
181 struct lttng_ust_channel_buffer *chan_buf;
182
183 chan_buf = (struct lttng_ust_channel_buffer *)chan->child;
184 free(chan_buf->parent);
185 free(chan_buf->priv);
186 free(chan_buf);
187 break;
188 }
189 default:
190 abort();
191 }
192 }
This page took 0.03383 seconds and 5 git commands to generate.