Move to kernel style SPDX license identifiers
[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 #include <lttng/ust-events.h>
12 #include <usterr-signal-safe.h>
13 #include "lttng-tracer-core.h"
14 #include "jhash.h"
15
16 static CDS_LIST_HEAD(lttng_transport_list);
17 static CDS_LIST_HEAD(lttng_counter_transport_list);
18
19 struct lttng_transport *lttng_transport_find(const char *name)
20 {
21 struct lttng_transport *transport;
22
23 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
24 if (!strcmp(transport->name, name))
25 return transport;
26 }
27 return NULL;
28 }
29
30 struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
31 {
32 struct lttng_counter_transport *transport;
33
34 cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
35 if (!strcmp(transport->name, name))
36 return transport;
37 }
38 return NULL;
39 }
40
41 /**
42 * lttng_transport_register - LTT transport registration
43 * @transport: transport structure
44 *
45 * Registers a transport which can be used as output to extract the data out of
46 * LTTng. Called with ust_lock held.
47 */
48 void lttng_transport_register(struct lttng_transport *transport)
49 {
50 cds_list_add_tail(&transport->node, &lttng_transport_list);
51 }
52
53 /**
54 * lttng_transport_unregister - LTT transport unregistration
55 * @transport: transport structure
56 * Called with ust_lock held.
57 */
58 void lttng_transport_unregister(struct lttng_transport *transport)
59 {
60 cds_list_del(&transport->node);
61 }
62
63 /**
64 * lttng_counter_transport_register - LTTng counter transport registration
65 * @transport: transport structure
66 *
67 * Registers a counter transport which can be used as output to extract
68 * the data out of LTTng. Called with ust_lock held.
69 */
70 void lttng_counter_transport_register(struct lttng_counter_transport *transport)
71 {
72 cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
73 }
74
75 /**
76 * lttng_counter_transport_unregister - LTTng counter transport unregistration
77 * @transport: transport structure
78 * Called with ust_lock held.
79 */
80 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
81 {
82 cds_list_del(&transport->node);
83 }
84
85 /*
86 * Needed by comm layer.
87 */
88 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
89 const struct lttng_enum_desc *enum_desc)
90 {
91 struct lttng_enum *_enum;
92 struct cds_hlist_head *head;
93 struct cds_hlist_node *node;
94 size_t name_len = strlen(enum_desc->name);
95 uint32_t hash;
96
97 hash = jhash(enum_desc->name, name_len, 0);
98 head = &session->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
99 cds_hlist_for_each_entry(_enum, node, head, hlist) {
100 assert(_enum->desc);
101 if (_enum->desc == enum_desc)
102 return _enum;
103 }
104 return NULL;
105 }
106
107 size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset)
108 {
109 size_t size = 0;
110
111 size += lib_ring_buffer_align(offset, lttng_alignof(char));
112 size += sizeof(char); /* tag */
113 return size;
114 }
115
116 void lttng_ust_dummy_record(struct lttng_ctx_field *field,
117 struct lttng_ust_lib_ring_buffer_ctx *ctx,
118 struct lttng_channel *chan)
119 {
120 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
121
122 lib_ring_buffer_align_ctx(ctx, lttng_alignof(sel_char));
123 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char));
124 }
125
126 void lttng_ust_dummy_get_value(struct lttng_ctx_field *field,
127 struct lttng_ctx_value *value)
128 {
129 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
130 }
131
132 int lttng_context_is_app(const char *name)
133 {
134 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
135 return 0;
136 }
137 return 1;
138 }
This page took 0.031118 seconds and 4 git commands to generate.