Move private ABI counter client symbols to dedicated header
[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 lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(sel_char));
125 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char));
126 }
127
128 void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field *field,
129 struct lttng_ust_ctx_value *value)
130 {
131 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
132 }
133
134 int lttng_context_is_app(const char *name)
135 {
136 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
137 return 0;
138 }
139 return 1;
140 }
141
142 struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
143 {
144 struct lttng_ust_channel_buffer *lttng_chan_buf;
145 struct lttng_ust_channel_common *lttng_chan_common;
146 struct lttng_ust_channel_buffer_private *lttng_chan_buf_priv;
147
148 lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer));
149 if (!lttng_chan_buf)
150 goto lttng_chan_buf_error;
151 lttng_chan_buf->struct_size = sizeof(struct lttng_ust_channel_buffer);
152 lttng_chan_common = zmalloc(sizeof(struct lttng_ust_channel_common));
153 if (!lttng_chan_common)
154 goto lttng_chan_common_error;
155 lttng_chan_common->struct_size = sizeof(struct lttng_ust_channel_common);
156 lttng_chan_buf_priv = zmalloc(sizeof(struct lttng_ust_channel_buffer_private));
157 if (!lttng_chan_buf_priv)
158 goto lttng_chan_buf_priv_error;
159 lttng_chan_buf->parent = lttng_chan_common;
160 lttng_chan_common->type = LTTNG_UST_CHANNEL_TYPE_BUFFER;
161 lttng_chan_common->child = lttng_chan_buf;
162 lttng_chan_buf->priv = lttng_chan_buf_priv;
163 lttng_chan_common->priv = &lttng_chan_buf_priv->parent;
164 lttng_chan_buf_priv->pub = lttng_chan_buf;
165 lttng_chan_buf_priv->parent.pub = lttng_chan_common;
166
167 return lttng_chan_buf;
168
169 lttng_chan_buf_priv_error:
170 free(lttng_chan_common);
171 lttng_chan_common_error:
172 free(lttng_chan_buf);
173 lttng_chan_buf_error:
174 return NULL;
175 }
176
177 void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
178 {
179 switch (chan->type) {
180 case LTTNG_UST_CHANNEL_TYPE_BUFFER:
181 {
182 struct lttng_ust_channel_buffer *chan_buf;
183
184 chan_buf = (struct lttng_ust_channel_buffer *)chan->child;
185 free(chan_buf->parent);
186 free(chan_buf->priv);
187 free(chan_buf);
188 break;
189 }
190 default:
191 abort();
192 }
193 }
This page took 0.033807 seconds and 5 git commands to generate.