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