Commit | Line | Data |
---|---|---|
14f28187 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
14f28187 FD |
3 | * |
4 | * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com> | |
5 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
6 | * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
7 | * | |
0235b0db | 8 | * BabelTrace - LTTng-live client Component |
14f28187 FD |
9 | */ |
10 | ||
0235b0db MJ |
11 | #ifndef BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H |
12 | #define BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H | |
13 | ||
c802cacb | 14 | #include <glib.h> |
3c22a242 FD |
15 | #include <stdint.h> |
16 | ||
3fadfbc0 | 17 | #include <babeltrace2/babeltrace.h> |
14f28187 | 18 | |
5656cea5 PP |
19 | #include "../common/src/metadata/tsdl/decoder.hpp" |
20 | #include "../common/src/msg-iter/msg-iter.hpp" | |
087cd0f5 | 21 | #include "viewer-connection.hpp" |
14f28187 | 22 | |
4164020e SM |
23 | enum lttng_live_stream_state |
24 | { | |
25 | /* This stream won't have data until some known time in the future. */ | |
26 | LTTNG_LIVE_STREAM_QUIESCENT, | |
27 | /* | |
28 | * This stream won't have data until some known time in the future and | |
29 | * the message iterator inactivity message was already sent downstream. | |
30 | */ | |
31 | LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA, /* */ | |
32 | /* This stream has data ready to be consumed. */ | |
33 | LTTNG_LIVE_STREAM_ACTIVE_DATA, | |
34 | /* | |
35 | * This stream has no data left to consume. We should asked the relay | |
36 | * for more. | |
37 | */ | |
38 | LTTNG_LIVE_STREAM_ACTIVE_NO_DATA, | |
39 | /* This stream won't have anymore data, ever. */ | |
40 | LTTNG_LIVE_STREAM_EOF, | |
14f28187 FD |
41 | }; |
42 | ||
43 | /* Iterator over a live stream. */ | |
4164020e SM |
44 | struct lttng_live_stream_iterator |
45 | { | |
46 | bt_logging_level log_level; | |
47 | bt_self_component *self_comp; | |
48 | ||
49 | /* Owned by this. */ | |
50 | bt_stream *stream; | |
51 | ||
52 | /* Weak reference. */ | |
53 | struct lttng_live_trace *trace; | |
54 | ||
55 | /* | |
56 | * Since only a single iterator per viewer connection, we have | |
57 | * only a single message iterator per stream. | |
58 | */ | |
59 | struct ctf_msg_iter *msg_iter; | |
60 | ||
61 | uint64_t viewer_stream_id; | |
62 | ||
63 | struct | |
64 | { | |
65 | bool is_set; | |
66 | uint64_t value; | |
67 | } ctf_stream_class_id; | |
68 | ||
69 | /* base offset in current index. */ | |
70 | uint64_t base_offset; | |
71 | /* len to read in current index. */ | |
72 | uint64_t len; | |
73 | /* offset in current index. */ | |
74 | uint64_t offset; | |
75 | ||
76 | /* | |
77 | * Clock Snapshot value of the last message iterator inactivity message | |
78 | * sent downstream. | |
79 | */ | |
80 | struct | |
81 | { | |
82 | bool is_set; | |
83 | uint64_t value; | |
84 | } last_inactivity_ts; | |
85 | ||
86 | /* | |
87 | * Clock Snapshot value of the current message iterator inactivity | |
88 | * message we might want to send downstream. | |
89 | */ | |
90 | uint64_t current_inactivity_ts; | |
91 | ||
92 | enum lttng_live_stream_state state; | |
93 | ||
94 | /* | |
95 | * The current message produced by this live stream iterator. Owned by | |
96 | * this. | |
97 | */ | |
98 | const bt_message *current_msg; | |
99 | ||
100 | /* Timestamp in nanoseconds of the current message (current_msg). */ | |
101 | int64_t current_msg_ts_ns; | |
102 | ||
103 | /* Owned by this. */ | |
104 | uint8_t *buf; | |
105 | size_t buflen; | |
106 | ||
107 | /* Owned by this. */ | |
108 | GString *name; | |
109 | ||
110 | bool has_stream_hung_up; | |
14f28187 FD |
111 | }; |
112 | ||
4164020e SM |
113 | struct lttng_live_metadata |
114 | { | |
115 | bt_logging_level log_level; | |
116 | bt_self_component *self_comp; | |
c01594de | 117 | |
4164020e SM |
118 | uint64_t stream_id; |
119 | /* Weak reference. */ | |
120 | struct ctf_metadata_decoder *decoder; | |
14f28187 FD |
121 | }; |
122 | ||
4164020e SM |
123 | enum lttng_live_metadata_stream_state |
124 | { | |
125 | /* | |
126 | * The metadata needs to be updated. This is either because we just | |
127 | * created the trace and haven't asked yet, or the relay specifically | |
128 | * told us that new metadata is available. | |
129 | */ | |
130 | LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED, | |
131 | /* | |
132 | * The metadata was updated and the relay has not told us we need to | |
133 | * update it yet. | |
134 | */ | |
135 | LTTNG_LIVE_METADATA_STREAM_STATE_NOT_NEEDED, | |
136 | /* | |
137 | * The relay has closed this metadata stream. We set this in reaction | |
138 | * to a LTTNG_VIEWER_METADATA_ERR reply to a LTTNG_VIEWER_GET_METADATA | |
139 | * command to the relay. If this field is set, we have received all the | |
140 | * metadata that we are ever going to get for that metadata stream. | |
141 | */ | |
142 | LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED, | |
76bbaebc FD |
143 | }; |
144 | ||
4164020e SM |
145 | struct lttng_live_trace |
146 | { | |
147 | bt_logging_level log_level; | |
148 | bt_self_component *self_comp; | |
c01594de | 149 | |
4164020e SM |
150 | /* Back reference to session. */ |
151 | struct lttng_live_session *session; | |
14f28187 | 152 | |
4164020e SM |
153 | /* ctf trace ID within the session. */ |
154 | uint64_t id; | |
14f28187 | 155 | |
4164020e SM |
156 | /* Owned by this. */ |
157 | bt_trace *trace; | |
14f28187 | 158 | |
4164020e SM |
159 | /* Weak reference. */ |
160 | bt_trace_class *trace_class; | |
14f28187 | 161 | |
4164020e | 162 | struct lttng_live_metadata *metadata; |
14f28187 | 163 | |
4164020e | 164 | const bt_clock_class *clock_class; |
14f28187 | 165 | |
4164020e SM |
166 | /* Array of pointers to struct lttng_live_stream_iterator. */ |
167 | /* Owned by this. */ | |
168 | GPtrArray *stream_iterators; | |
14f28187 | 169 | |
4164020e | 170 | enum lttng_live_metadata_stream_state metadata_stream_state; |
14f28187 FD |
171 | }; |
172 | ||
4164020e SM |
173 | struct lttng_live_session |
174 | { | |
175 | bt_logging_level log_level; | |
176 | bt_self_component *self_comp; | |
c01594de | 177 | |
4164020e SM |
178 | /* Weak reference. */ |
179 | struct lttng_live_msg_iter *lttng_live_msg_iter; | |
14f28187 | 180 | |
4164020e SM |
181 | /* Owned by this. */ |
182 | GString *hostname; | |
14f28187 | 183 | |
4164020e SM |
184 | /* Owned by this. */ |
185 | GString *session_name; | |
14f28187 | 186 | |
4164020e | 187 | uint64_t id; |
14f28187 | 188 | |
4164020e SM |
189 | /* Array of pointers to struct lttng_live_trace. */ |
190 | GPtrArray *traces; | |
14f28187 | 191 | |
4164020e SM |
192 | bool attached; |
193 | bool new_streams_needed; | |
194 | bool lazy_stream_msg_init; | |
195 | bool closed; | |
14f28187 FD |
196 | }; |
197 | ||
4164020e SM |
198 | enum session_not_found_action |
199 | { | |
200 | SESSION_NOT_FOUND_ACTION_CONTINUE, | |
201 | SESSION_NOT_FOUND_ACTION_FAIL, | |
202 | SESSION_NOT_FOUND_ACTION_END, | |
14f28187 FD |
203 | }; |
204 | ||
205 | /* | |
206 | * A component instance is an iterator on a single session. | |
207 | */ | |
4164020e SM |
208 | struct lttng_live_component |
209 | { | |
210 | bt_logging_level log_level; | |
211 | ||
212 | /* Weak reference. */ | |
213 | bt_self_component *self_comp; | |
214 | ||
215 | struct | |
216 | { | |
217 | GString *url; | |
218 | enum session_not_found_action sess_not_found_act; | |
219 | } params; | |
220 | ||
221 | size_t max_query_size; | |
222 | ||
223 | /* | |
224 | * Keeps track of whether the downstream component already has a | |
225 | * message iterator on this component. | |
226 | */ | |
227 | bool has_msg_iter; | |
14f28187 FD |
228 | }; |
229 | ||
4164020e SM |
230 | struct lttng_live_msg_iter |
231 | { | |
232 | bt_logging_level log_level; | |
233 | bt_self_component *self_comp; | |
c01594de | 234 | |
4164020e SM |
235 | /* Weak reference. */ |
236 | struct lttng_live_component *lttng_live_comp; | |
14f28187 | 237 | |
4164020e SM |
238 | /* Weak reference. */ |
239 | bt_self_message_iterator *self_msg_iter; | |
14f28187 | 240 | |
4164020e SM |
241 | /* Owned by this. */ |
242 | struct live_viewer_connection *viewer_connection; | |
14f28187 | 243 | |
4164020e SM |
244 | /* Array of pointers to struct lttng_live_session. */ |
245 | GPtrArray *sessions; | |
14f28187 | 246 | |
4164020e SM |
247 | /* Number of live stream iterator this message iterator has.*/ |
248 | uint64_t active_stream_iter; | |
14f28187 | 249 | |
4164020e SM |
250 | /* Timestamp in nanosecond of the last message sent downstream. */ |
251 | int64_t last_msg_ts_ns; | |
f79c2d7a | 252 | |
4164020e SM |
253 | /* True if the iterator was interrupted. */ |
254 | bool was_interrupted; | |
14f28187 FD |
255 | }; |
256 | ||
4164020e SM |
257 | enum lttng_live_iterator_status |
258 | { | |
259 | /** Iterator state has progressed. Continue iteration immediately. */ | |
260 | LTTNG_LIVE_ITERATOR_STATUS_CONTINUE = 3, | |
261 | /** No message available for now. Try again later. */ | |
262 | LTTNG_LIVE_ITERATOR_STATUS_AGAIN = 2, | |
263 | /** No more CTF_LTTNG_LIVEs to be delivered. */ | |
264 | LTTNG_LIVE_ITERATOR_STATUS_END = 1, | |
265 | /** No error, okay. */ | |
266 | LTTNG_LIVE_ITERATOR_STATUS_OK = 0, | |
267 | /** Invalid arguments. */ | |
268 | LTTNG_LIVE_ITERATOR_STATUS_INVAL = -1, | |
269 | /** General error. */ | |
270 | LTTNG_LIVE_ITERATOR_STATUS_ERROR = -2, | |
271 | /** Out of memory. */ | |
272 | LTTNG_LIVE_ITERATOR_STATUS_NOMEM = -3, | |
273 | /** Unsupported iterator feature. */ | |
274 | LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED = -4, | |
14f28187 FD |
275 | }; |
276 | ||
4164020e SM |
277 | bt_component_class_initialize_method_status |
278 | lttng_live_component_init(bt_self_component_source *self_comp, | |
279 | bt_self_component_source_configuration *config, const bt_value *params, | |
280 | void *init_method_data); | |
14f28187 | 281 | |
4164020e SM |
282 | bt_component_class_query_method_status lttng_live_query(bt_self_component_class_source *comp_class, |
283 | bt_private_query_executor *priv_query_exec, | |
284 | const char *object, const bt_value *params, | |
285 | void *method_data, const bt_value **result); | |
14f28187 FD |
286 | |
287 | void lttng_live_component_finalize(bt_self_component_source *component); | |
288 | ||
4164020e SM |
289 | bt_message_iterator_class_next_method_status |
290 | lttng_live_msg_iter_next(bt_self_message_iterator *iterator, bt_message_array_const msgs, | |
291 | uint64_t capacity, uint64_t *count); | |
14f28187 | 292 | |
4164020e SM |
293 | bt_message_iterator_class_initialize_method_status |
294 | lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it, | |
295 | bt_self_message_iterator_configuration *config, | |
296 | bt_self_component_port_output *self_port); | |
14f28187 FD |
297 | |
298 | void lttng_live_msg_iter_finalize(bt_self_message_iterator *it); | |
299 | ||
4164020e SM |
300 | enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_session *session, |
301 | bt_self_message_iterator *self_msg_iter); | |
eee8e741 | 302 | |
4164020e | 303 | enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_session *session); |
f79c2d7a | 304 | |
4164020e SM |
305 | enum lttng_live_iterator_status |
306 | lttng_live_session_get_new_streams(struct lttng_live_session *session, | |
307 | bt_self_message_iterator *self_msg_iter); | |
14f28187 | 308 | |
4164020e SM |
309 | struct lttng_live_trace * |
310 | lttng_live_session_borrow_or_create_trace_by_id(struct lttng_live_session *session, | |
311 | uint64_t trace_id); | |
36e94ad6 | 312 | |
4164020e SM |
313 | int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, uint64_t session_id, |
314 | const char *hostname, const char *session_name); | |
14f28187 | 315 | |
c28512ab FD |
316 | /* |
317 | * lttng_live_get_one_metadata_packet() asks the Relay Daemon for new metadata. | |
318 | * If new metadata is received, the function writes it to the provided file | |
319 | * handle and updates the reply_len output parameter. This function should be | |
320 | * called in loop until _END status is received to ensure all metadata is | |
321 | * written to the file. | |
322 | */ | |
4164020e SM |
323 | enum lttng_live_get_one_metadata_status |
324 | lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, size_t *reply_len); | |
c28512ab | 325 | |
4164020e SM |
326 | enum lttng_live_iterator_status |
327 | lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter, | |
328 | struct lttng_live_stream_iterator *stream, struct packet_index *index); | |
14f28187 | 329 | |
4164020e SM |
330 | enum ctf_msg_iter_medium_status |
331 | lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter, | |
332 | struct lttng_live_stream_iterator *stream, uint8_t *buf, | |
333 | uint64_t offset, uint64_t req_len, uint64_t *recv_len); | |
14f28187 | 334 | |
9b4f9b42 | 335 | bool lttng_live_graph_is_canceled(struct lttng_live_msg_iter *msg_iter); |
14f28187 | 336 | |
4164020e SM |
337 | void lttng_live_stream_iterator_set_state(struct lttng_live_stream_iterator *stream_iter, |
338 | enum lttng_live_stream_state new_state); | |
34533ae0 | 339 | |
14f28187 | 340 | #endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H */ |