Move the ringbuffer and counter clients to 'src/common/'
[lttng-ust.git] / src / common / core.c
CommitLineData
5e96a467 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
5e96a467
MD
3 *
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5e96a467
MD
5 */
6
3fbec7dc 7#define _LGPL_SOURCE
fb31eb73 8#include <stdint.h>
b4051ad8 9#include <stddef.h>
5e96a467 10#include <stdlib.h>
bb7ad29d 11
8cd08025
MJ
12#include <lttng/ust-ringbuffer-context.h>
13
9d315d6d 14#include "common/logging.h"
8cd08025 15#include "common/tracer.h"
e58e5ad5 16#include "common/jhash.h"
5e96a467 17
8cd08025
MJ
18
19/*
20 * Each library using the transports will have its local lists.
21 */
7dd08bec 22static CDS_LIST_HEAD(lttng_transport_list);
ebabbf58 23static CDS_LIST_HEAD(lttng_counter_transport_list);
c1fca457 24
65c48d6a 25struct lttng_transport *lttng_ust_transport_find(const char *name)
c1fca457 26{
7dd08bec 27 struct lttng_transport *transport;
c1fca457 28
7dd08bec 29 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
c1fca457
MD
30 if (!strcmp(transport->name, name))
31 return transport;
32 }
33 return NULL;
34}
35
ebabbf58
MD
36struct 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
c1fca457 47/**
7dd08bec 48 * lttng_transport_register - LTT transport registration
c1fca457
MD
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 */
7dd08bec 54void lttng_transport_register(struct lttng_transport *transport)
c1fca457 55{
7dd08bec 56 cds_list_add_tail(&transport->node, &lttng_transport_list);
c1fca457
MD
57}
58
59/**
7dd08bec 60 * lttng_transport_unregister - LTT transport unregistration
c1fca457
MD
61 * @transport: transport structure
62 * Called with ust_lock held.
63 */
7dd08bec 64void lttng_transport_unregister(struct lttng_transport *transport)
c1fca457
MD
65{
66 cds_list_del(&transport->node);
67}
c785c634 68
ebabbf58
MD
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 */
76void 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 */
86void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
87{
88 cds_list_del(&transport->node);
89}
90
4e48b5d2 91size_t lttng_ust_dummy_get_size(void *priv __attribute__((unused)),
b2e37d27 92 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
2208d8b5 93 size_t offset)
797b05f6
MD
94{
95 size_t size = 0;
96
b5457df5 97 size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(char));
797b05f6
MD
98 size += sizeof(char); /* tag */
99 return size;
100}
101
4e48b5d2 102void lttng_ust_dummy_record(void *priv __attribute__((unused)),
b2e37d27
MD
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)
797b05f6
MD
106{
107 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
108
8936b6c0 109 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char));
797b05f6
MD
110}
111
4e48b5d2 112void lttng_ust_dummy_get_value(void *priv __attribute__((unused)),
b2e37d27 113 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
daacdbfc 114 struct lttng_ust_ctx_value *value)
797b05f6
MD
115{
116 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
117}
ce47f5d8
MD
118
119int lttng_context_is_app(const char *name)
120{
121 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
122 return 0;
123 }
124 return 1;
125}
e7bc0ef6
MD
126
127struct 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
154lttng_chan_buf_priv_error:
155 free(lttng_chan_common);
156lttng_chan_common_error:
157 free(lttng_chan_buf);
158lttng_chan_buf_error:
159 return NULL;
160}
161
162void 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}
f27f1026 179
This page took 0.04493 seconds and 4 git commands to generate.