Move the ringbuffer and counter clients to 'src/common/'
[lttng-ust.git] / src / common / 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 <lttng/ust-ringbuffer-context.h>
13
14 #include "common/logging.h"
15 #include "common/tracer.h"
16 #include "common/jhash.h"
17
18
19 /*
20 * Each library using the transports will have its local lists.
21 */
22 static CDS_LIST_HEAD(lttng_transport_list);
23 static CDS_LIST_HEAD(lttng_counter_transport_list);
24
25 struct lttng_transport *lttng_ust_transport_find(const char *name)
26 {
27 struct lttng_transport *transport;
28
29 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
30 if (!strcmp(transport->name, name))
31 return transport;
32 }
33 return NULL;
34 }
35
36 struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
37 {
38 struct lttng_counter_transport *transport;
39
40 cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
41 if (!strcmp(transport->name, name))
42 return transport;
43 }
44 return NULL;
45 }
46
47 /**
48 * lttng_transport_register - LTT transport registration
49 * @transport: transport structure
50 *
51 * Registers a transport which can be used as output to extract the data out of
52 * LTTng. Called with ust_lock held.
53 */
54 void lttng_transport_register(struct lttng_transport *transport)
55 {
56 cds_list_add_tail(&transport->node, &lttng_transport_list);
57 }
58
59 /**
60 * lttng_transport_unregister - LTT transport unregistration
61 * @transport: transport structure
62 * Called with ust_lock held.
63 */
64 void lttng_transport_unregister(struct lttng_transport *transport)
65 {
66 cds_list_del(&transport->node);
67 }
68
69 /**
70 * lttng_counter_transport_register - LTTng counter transport registration
71 * @transport: transport structure
72 *
73 * Registers a counter transport which can be used as output to extract
74 * the data out of LTTng. Called with ust_lock held.
75 */
76 void lttng_counter_transport_register(struct lttng_counter_transport *transport)
77 {
78 cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
79 }
80
81 /**
82 * lttng_counter_transport_unregister - LTTng counter transport unregistration
83 * @transport: transport structure
84 * Called with ust_lock held.
85 */
86 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
87 {
88 cds_list_del(&transport->node);
89 }
90
91 size_t lttng_ust_dummy_get_size(void *priv __attribute__((unused)),
92 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
93 size_t offset)
94 {
95 size_t size = 0;
96
97 size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(char));
98 size += sizeof(char); /* tag */
99 return size;
100 }
101
102 void lttng_ust_dummy_record(void *priv __attribute__((unused)),
103 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
104 struct lttng_ust_ring_buffer_ctx *ctx,
105 struct lttng_ust_channel_buffer *chan)
106 {
107 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
108
109 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char));
110 }
111
112 void lttng_ust_dummy_get_value(void *priv __attribute__((unused)),
113 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
114 struct lttng_ust_ctx_value *value)
115 {
116 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
117 }
118
119 int lttng_context_is_app(const char *name)
120 {
121 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
122 return 0;
123 }
124 return 1;
125 }
126
127 struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
128 {
129 struct lttng_ust_channel_buffer *lttng_chan_buf;
130 struct lttng_ust_channel_common *lttng_chan_common;
131 struct lttng_ust_channel_buffer_private *lttng_chan_buf_priv;
132
133 lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer));
134 if (!lttng_chan_buf)
135 goto lttng_chan_buf_error;
136 lttng_chan_buf->struct_size = sizeof(struct lttng_ust_channel_buffer);
137 lttng_chan_common = zmalloc(sizeof(struct lttng_ust_channel_common));
138 if (!lttng_chan_common)
139 goto lttng_chan_common_error;
140 lttng_chan_common->struct_size = sizeof(struct lttng_ust_channel_common);
141 lttng_chan_buf_priv = zmalloc(sizeof(struct lttng_ust_channel_buffer_private));
142 if (!lttng_chan_buf_priv)
143 goto lttng_chan_buf_priv_error;
144 lttng_chan_buf->parent = lttng_chan_common;
145 lttng_chan_common->type = LTTNG_UST_CHANNEL_TYPE_BUFFER;
146 lttng_chan_common->child = lttng_chan_buf;
147 lttng_chan_buf->priv = lttng_chan_buf_priv;
148 lttng_chan_common->priv = &lttng_chan_buf_priv->parent;
149 lttng_chan_buf_priv->pub = lttng_chan_buf;
150 lttng_chan_buf_priv->parent.pub = lttng_chan_common;
151
152 return lttng_chan_buf;
153
154 lttng_chan_buf_priv_error:
155 free(lttng_chan_common);
156 lttng_chan_common_error:
157 free(lttng_chan_buf);
158 lttng_chan_buf_error:
159 return NULL;
160 }
161
162 void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
163 {
164 switch (chan->type) {
165 case LTTNG_UST_CHANNEL_TYPE_BUFFER:
166 {
167 struct lttng_ust_channel_buffer *chan_buf;
168
169 chan_buf = (struct lttng_ust_channel_buffer *)chan->child;
170 free(chan_buf->parent);
171 free(chan_buf->priv);
172 free(chan_buf);
173 break;
174 }
175 default:
176 abort();
177 }
178 }
179
This page took 0.043632 seconds and 4 git commands to generate.