consumerd: send a buffer static sample on flush command
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.hpp
1 /*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef LTTNG_UST_REGISTRY_H
10 #define LTTNG_UST_REGISTRY_H
11
12 #include "event-class.hpp"
13 #include "field.hpp"
14 #include "lttng-ust-ctl.hpp"
15 #include "session.hpp"
16 #include "stream-class.hpp"
17 #include "trace-class.hpp"
18 #include "ust-clock-class.hpp"
19 #include "ust-registry-channel.hpp"
20 #include "ust-registry-event.hpp"
21
22 #include <common/format.hpp>
23 #include <common/hashtable/hashtable.hpp>
24 #include <common/locked-reference.hpp>
25 #include <common/urcu.hpp>
26 #include <common/uuid.hpp>
27
28 #include <lttng/domain.h>
29
30 #include <ctime>
31 #include <memory>
32 #include <pthread.h>
33 #include <stdint.h>
34 #include <string>
35 #include <type_traits>
36
37 #define CTF_SPEC_MAJOR 1
38 #define CTF_SPEC_MINOR 8
39
40 struct ust_app;
41
42 namespace lttng {
43 namespace sessiond {
44 namespace ust {
45
46 class registry_session;
47
48 namespace details {
49
50 template <class MappingIntegerType>
51 typename trace::typed_enumeration_type<MappingIntegerType>::mapping mapping_from_ust_ctl_entry(
52 const lttng_ust_ctl_enum_entry& entry)
53 {
54 if (entry.u.extra.options & LTTNG_UST_CTL_UST_ENUM_ENTRY_OPTION_IS_AUTO) {
55 return {entry.string};
56
57 } else {
58 return {entry.string,
59 {(MappingIntegerType) entry.start.value,
60 (MappingIntegerType) entry.end.value}};
61 }
62 }
63
64 template <class MappingIntegerType>
65 typename trace::typed_enumeration_type<MappingIntegerType>::mappings mappings_from_ust_ctl_entries(
66 const lttng_ust_ctl_enum_entry *in_entries, size_t in_entry_count)
67 {
68 typename trace::typed_enumeration_type<MappingIntegerType>::mappings mappings;
69
70 for (size_t entry_idx = 0; entry_idx < in_entry_count; entry_idx++) {
71 const auto& entry = in_entries[entry_idx];
72
73 mappings.emplace_back(mapping_from_ust_ctl_entry<MappingIntegerType>(entry));
74 }
75
76 return mappings;
77 }
78 } /* namespace details */
79
80 class registry_enum {
81 public:
82 using const_rcu_protected_reference = lttng::locked_reference<const registry_enum, lttng::urcu::unique_read_lock>;
83
84 registry_enum(std::string name, enum lttng::sessiond::trace::integer_type::signedness signedness);
85 virtual ~registry_enum() = default;
86
87 std::string name;
88 enum lttng::sessiond::trace::integer_type::signedness signedness;
89 /* enum id in session */
90 uint64_t id = -1ULL;
91 /* Enumeration node in session hash table. */
92 struct lttng_ht_node_str node;
93 /* For delayed reclaim. */
94 struct rcu_head rcu_head;
95
96 friend bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept;
97 protected:
98 virtual bool _is_equal(const registry_enum& other) const noexcept = 0;
99 };
100
101 bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept;
102
103 template <class MappingIntegerType>
104 class registry_typed_enum : public registry_enum {
105 public:
106 registry_typed_enum(const char *in_name,
107 const lttng_ust_ctl_enum_entry *entries,
108 size_t entry_count) :
109 registry_enum(in_name,
110 std::is_signed<MappingIntegerType>::value ?
111 lttng::sessiond::trace::integer_type::signedness::SIGNED :
112 lttng::sessiond::trace::integer_type::signedness::UNSIGNED),
113 _mappings{std::make_shared<
114 typename trace::typed_enumeration_type<MappingIntegerType>::mappings>(
115 details::mappings_from_ust_ctl_entries<MappingIntegerType>(
116 entries, entry_count))}
117 {
118 }
119
120 const typename std::shared_ptr<const typename lttng::sessiond::trace::typed_enumeration_type<
121 MappingIntegerType>::mappings>
122 _mappings;
123
124 protected:
125 virtual bool _is_equal(const registry_enum& base_other) const noexcept
126 {
127 const auto &other = static_cast<decltype(*this)&>(base_other);
128
129 /* Don't compare IDs as some comparisons are performed before an id is assigned. */
130 return this->name == other.name && *this->_mappings == *other._mappings;
131 }
132 };
133
134 using registry_signed_enum = registry_typed_enum<int64_t>;
135 using registry_unsigned_enum = registry_typed_enum<uint64_t>;
136
137 } /* namespace ust */
138 } /* namespace sessiond */
139 } /* namespace lttng */
140
141 #ifdef HAVE_LIBLTTNG_UST_CTL
142
143 /*
144 * Create per-uid registry with default values.
145 *
146 * Return new instance on success, nullptr on error.
147 */
148 lttng::sessiond::ust::registry_session *ust_registry_session_per_uid_create(
149 const lttng::sessiond::trace::abi& abi,
150 uint32_t major,
151 uint32_t minor,
152 const char *root_shm_path,
153 const char *shm_path,
154 uid_t euid,
155 gid_t egid,
156 uint64_t tracing_id,
157 uid_t tracing_uid);
158
159 /*
160 * Create per-pid registry with default values.
161 *
162 * Return new instance on success, nullptr on error.
163 */
164 lttng::sessiond::ust::registry_session *ust_registry_session_per_pid_create(struct ust_app *app,
165 const lttng::sessiond::trace::abi& abi,
166 uint32_t major,
167 uint32_t minor,
168 const char *root_shm_path,
169 const char *shm_path,
170 uid_t euid,
171 gid_t egid,
172 uint64_t tracing_id);
173 void ust_registry_session_destroy(lttng::sessiond::ust::registry_session *session);
174
175 void ust_registry_channel_destroy_event(lttng::sessiond::ust::registry_channel *chan,
176 lttng::sessiond::ust::registry_event *event);
177
178 #else /* HAVE_LIBLTTNG_UST_CTL */
179
180 static inline
181 lttng::sessiond::ust::registry_session *ust_registry_session_per_uid_create(
182 uint32_t bits_per_long __attribute__((unused)),
183 uint32_t uint8_t_alignment __attribute__((unused)),
184 uint32_t uint16_t_alignment __attribute__((unused)),
185 uint32_t uint32_t_alignment __attribute__((unused)),
186 uint32_t uint64_t_alignment __attribute__((unused)),
187 uint32_t long_alignment __attribute__((unused)),
188 int byte_order __attribute__((unused)),
189 uint32_t major __attribute__((unused)),
190 uint32_t minor __attribute__((unused)),
191 const char *root_shm_path __attribute__((unused)),
192 const char *shm_path __attribute__((unused)),
193 uid_t euid __attribute__((unused)),
194 gid_t egid __attribute__((unused)),
195 uint64_t tracing_id __attribute__((unused)),
196 uid_t tracing_uid __attribute__((unused)))
197 {
198 return nullptr;
199 }
200
201 static inline
202 lttng::sessiond::ust::registry_session *ust_registry_session_per_pid_create(
203 struct ust_app *app __attribute__((unused)),
204 uint32_t bits_per_long __attribute__((unused)),
205 uint32_t uint8_t_alignment __attribute__((unused)),
206 uint32_t uint16_t_alignment __attribute__((unused)),
207 uint32_t uint32_t_alignment __attribute__((unused)),
208 uint32_t uint64_t_alignment __attribute__((unused)),
209 uint32_t long_alignment __attribute__((unused)),
210 int byte_order __attribute__((unused)),
211 uint32_t major __attribute__((unused)),
212 uint32_t minor __attribute__((unused)),
213 const char *root_shm_path __attribute__((unused)),
214 const char *shm_path __attribute__((unused)),
215 uid_t euid __attribute__((unused)),
216 gid_t egid __attribute__((unused)),
217 uint64_t tracing_id __attribute__((unused)))
218 {
219 return nullptr;
220 }
221
222 static inline
223 void ust_registry_session_destroy(
224 lttng::sessiond::ust::registry_session *session __attribute__((unused)))
225 {}
226
227 static inline
228 void ust_registry_destroy_event(
229 lttng::sessiond::ust::registry_channel *chan __attribute__((unused)),
230 lttng::sessiond::ust::registry_event *event __attribute__((unused)))
231 {}
232
233 /* The app object can be NULL for registry shared across applications. */
234 static inline
235 int ust_metadata_session_statedump(
236 lttng::sessiond::ust::registry_session *session __attribute__((unused)))
237 {
238 return 0;
239 }
240
241 static inline
242 int ust_metadata_channel_statedump(
243 lttng::sessiond::ust::registry_session *session __attribute__((unused)),
244 lttng::sessiond::ust::registry_channel *chan __attribute__((unused)))
245 {
246 return 0;
247 }
248
249 static inline
250 int ust_metadata_event_statedump(
251 lttng::sessiond::ust::registry_session *session __attribute__((unused)),
252 lttng::sessiond::ust::registry_channel *chan __attribute__((unused)),
253 lttng::sessiond::ust::registry_event *event __attribute__((unused)))
254 {
255 return 0;
256 }
257
258 #endif /* HAVE_LIBLTTNG_UST_CTL */
259
260 #endif /* LTTNG_UST_REGISTRY_H */
This page took 0.035907 seconds and 4 git commands to generate.