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