Refactoring: hide internal fields of ring buffer context
[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 "jhash.h"
17
18 static CDS_LIST_HEAD(lttng_transport_list);
19 static CDS_LIST_HEAD(lttng_counter_transport_list);
20
21 struct lttng_transport *lttng_ust_transport_find(const char *name)
22 {
23 struct lttng_transport *transport;
24
25 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
26 if (!strcmp(transport->name, name))
27 return transport;
28 }
29 return NULL;
30 }
31
32 struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
33 {
34 struct lttng_counter_transport *transport;
35
36 cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
37 if (!strcmp(transport->name, name))
38 return transport;
39 }
40 return NULL;
41 }
42
43 /**
44 * lttng_transport_register - LTT transport registration
45 * @transport: transport structure
46 *
47 * Registers a transport which can be used as output to extract the data out of
48 * LTTng. Called with ust_lock held.
49 */
50 void lttng_transport_register(struct lttng_transport *transport)
51 {
52 cds_list_add_tail(&transport->node, &lttng_transport_list);
53 }
54
55 /**
56 * lttng_transport_unregister - LTT transport unregistration
57 * @transport: transport structure
58 * Called with ust_lock held.
59 */
60 void lttng_transport_unregister(struct lttng_transport *transport)
61 {
62 cds_list_del(&transport->node);
63 }
64
65 /**
66 * lttng_counter_transport_register - LTTng counter transport registration
67 * @transport: transport structure
68 *
69 * Registers a counter transport which can be used as output to extract
70 * the data out of LTTng. Called with ust_lock held.
71 */
72 void lttng_counter_transport_register(struct lttng_counter_transport *transport)
73 {
74 cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
75 }
76
77 /**
78 * lttng_counter_transport_unregister - LTTng counter transport unregistration
79 * @transport: transport structure
80 * Called with ust_lock held.
81 */
82 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
83 {
84 cds_list_del(&transport->node);
85 }
86
87 /*
88 * Needed by comm layer.
89 */
90 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session,
91 struct lttng_ust_enum_desc *enum_desc)
92 {
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);
97 uint32_t hash;
98
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) {
102 assert(_enum->desc);
103 if (_enum->desc == enum_desc)
104 return _enum;
105 }
106 return NULL;
107 }
108
109 size_t lttng_ust_dummy_get_size(struct lttng_ust_ctx_field *field, size_t offset)
110 {
111 size_t size = 0;
112
113 size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(char));
114 size += sizeof(char); /* tag */
115 return size;
116 }
117
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)
121 {
122 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
123
124 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(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.033396 seconds and 5 git commands to generate.