docs: Add supported versions and fix-backport policy
[lttng-tools.git] / include / lttng / session.h
CommitLineData
1239a312 1/*
ab5be9fa
MJ
2 * Copyright (C) 2014 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
1239a312 4 *
ab5be9fa 5 * SPDX-License-Identifier: LGPL-2.1-only
1239a312 6 *
1239a312
DG
7 */
8
9#ifndef LTTNG_SESSION_H
10#define LTTNG_SESSION_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
4bd69c5f 16#include <lttng/lttng-export.h>
55c9e7ca 17
048f01ef
PP
18/*!
19@addtogroup api_session
20@{
21*/
22
23#include <lttng/constant.h>
24
55c9e7ca 25struct lttng_handle;
b178f53e 26struct lttng_session_descriptor;
3e3665b8 27struct lttng_destruction_handle;
b178f53e 28
28f23191 29#define LTTNG_SESSION_PADDING1 8
048f01ef
PP
30
31/*!
32@brief
33 Recording session summary.
34
35The purpose of such a structure is to provide information about a
36\lt_obj_session itself, but not about its \lt_obj_domains
37and \lt_obj_channels (use lttng_list_domains() and lttng_list_channels()
38for this).
39
40lttng_list_sessions() sets a pointer to an array of all the available
41recording session summaries.
42*/
1239a312 43struct lttng_session {
048f01ef 44 /// Name.
36d2e35d 45 char name[LTTNG_NAME_MAX];
048f01ef
PP
46
47 /*!
48 @brief
49 <em>Human-readable</em> representation of the output (local
50 or remote).
51 */
1239a312 52 char path[PATH_MAX];
048f01ef
PP
53
54 /*!
55 @brief
56 1 if this recording session is active (started), or 0
57 otherwise.
58
59 @sa lttng_start_tracing() --
60 Starts a recording session.
61 @sa lttng_stop_tracing() --
62 Stops a recording session.
63 */
28f23191 64 uint32_t enabled; /* enabled/started: 1, disabled/stopped: 0 */
048f01ef
PP
65
66 /*!
67 @brief
68 1 if this recording session was created in
69 \ref api-session-snapshot-mode "snapshot mode",
70 or 0 otherwise.
71
72 @note
73 If this member is 1, then the
74 lttng_session::live_timer_interval member is 0.
75 */
1239a312 76 uint32_t snapshot_mode;
048f01ef
PP
77
78 /*!
79 @brief
80 Period (µs) of the \ref api-channel-live-timer "live timers"
81 of the channels of this recording session, or 0 if this
82 recording session wasn't created in
83 \ref api-session-live-mode "live mode".
84
85 @note
86 If this member is \em not 0, then the
87 lttng_session::snapshot_mode member is 0.
88 */
28f23191 89 unsigned int live_timer_interval; /* usec */
1239a312 90
e9af56b3
JG
91 /*
92 * End of public attributes.
93 * The remaining fields are used to deal with ABI management concerns.
94 */
95
96 /*
97 * 32-bit architectures are already naturally aligned on 4 bytes after
98 * 'live_timer_interval'. However, the offset does not result in a
99 * natural alignment on 64-bit architectures. Adding 4 bytes of
100 * padding here results in an aligned offset after 'alignement_padding'
101 * for both bitnesses.
102 *
103 * This was added since not all compilers appear to align unions in the
104 * same way. Some (e.g. MSVC) do not seem to impose an alignement
105 * constraint while others (e.g. gcc, clang, icc) seem to align it to
106 * ensure 'ptr' is naturally aligned.
107 */
108 char alignment_padding[4];
b178f53e 109 union {
e9af56b3
JG
110 /*
111 * Ensure the 'extended' union has the same size for both
112 * 32-bit and 64-bit builds.
113 */
b178f53e
JG
114 char padding[LTTNG_SESSION_PADDING1];
115 void *ptr;
116 } extended;
1239a312
DG
117};
118
048f01ef
PP
119/*!
120@brief
121 Creates a recording session from the recording session descriptor
122 \lt_p{session_descriptor}.
123
124See \ref api_session_descr to learn how to create a recording session
125descriptor.
126
127On success, if the name property of \lt_p{session_descriptor} isn't set,
128this function sets it to the automatically generated name of the
129recording session. Get the recording session name with
130lttng_session_descriptor_get_session_name().
131
132@param[in] session_descriptor
133 Descriptor from which to create a recording session.
134
135@returns
136 #LTTNG_OK on success, or a \em negative enumerator otherwise.
137
138@lt_pre_conn
139@lt_pre_not_null{session_descriptor}
140@pre
141 If the name property of \lt_p{session_descriptor} is set, then no
142 available recording session has this name.
143
144@sa \ref api_session_descr.
145@sa \lt_man{lttng-create,1}
146*/
28f23191
JG
147LTTNG_EXPORT extern enum lttng_error_code
148lttng_create_session_ext(struct lttng_session_descriptor *session_descriptor);
b178f53e 149
048f01ef
PP
150/*!
151@brief
152 Creates a recording session named \lt_p{session_name} in
153 \ref api-session-local-mode "local"
154 or \ref api-session-net-mode "network streaming" mode, optionally
155 setting its output URL to \lt_p{output_url}.
1239a312 156
048f01ef
PP
157@deprecated
158 Use lttng_create_session_ext() with a dedicated
159 local or network streaming
160 \ref api_session_descr "recording session descriptor".
1239a312 161
048f01ef
PP
162@param[in] session_name
163 Name of the new recording session.
164@param[in] output_url
165 @parblock
166 \ref api-session-url "Output URL" of the recording session to
167 create.
1239a312 168
048f01ef
PP
169 If it's a \ref api-session-one-port-url "single-port output URL",
170 then the trace data port is \lt_def_net_data_port.
1239a312 171
048f01ef
PP
172 If \c NULL, LTTng doesn't write any trace data for this recording
173 session.
174 @endparblock
175
176@returns
177 0 on success, or a \em negative #lttng_error_code enumerator
178 otherwise.
179
180@lt_pre_conn
181@lt_pre_not_null{session_name}
182@lt_pre_sess_name_not_auto{session_name}
183@pre
184 No available recording session is named \lt_p{session_name}.
185@pre
186 <strong>If not \c NULL</strong>, \lt_p{output_url} is a valid
187 \ref api-session-url "output URL".
188
189@sa lttng_create_session_snapshot() --
190 Creates a recording session in snapshot mode.
191@sa lttng_create_session_live() --
192 Creates a recording session in live mode.
193@sa \lt_man{lttng-create,1}
194*/
195LTTNG_EXPORT extern int lttng_create_session(const char *session_name, const char *output_url);
196
197/*!
198@brief
199 Creates a recording session named \lt_p{session_name} in
200 \ref api-session-snapshot-mode "snapshot" mode, optionally setting
201 the URL of its initial snapshot output to \lt_p{output_url}.
202
203@deprecated
204 Use lttng_create_session_ext() with a dedicated snapshot
205 \ref api_session_descr "recording session descriptor".
206
207@param[in] session_name
208 Name of the new recording session.
209@param[in] output_url
210 @parblock
211 \ref api-session-url "URL" of an initial snapshot output
212 which LTTng adds to this recording session.
213
214 If it's a \ref api-session-one-port-url "single-port output URL",
215 then the trace data port is \lt_def_net_data_port.
216
217 This initial snapshot output is named <code>snapshot-0</code>.
218
219 If \c NULL, then the created recording session has no initial
220 snapshot output: you need to either add one with
221 lttng_snapshot_add_output() or provide one when you take a snapshot
222 with lttng_snapshot_record().
223 @endparblock
224
225@returns
226 0 on success, or a \em negative #lttng_error_code enumerator
227 otherwise.
228
229@lt_pre_conn
230@lt_pre_not_null{session_name}
231@lt_pre_sess_name_not_auto{session_name}
232@pre
233 No available recording session is named \lt_p{session_name}.
234@pre
235 <strong>If not \c NULL</strong>, \lt_p{output_url} is a valid
236 \ref api-session-url "output URL".
237
238@sa lttng_create_session() --
239 Creates a recording session in local or network streaming mode.
240@sa lttng_create_session_live() --
241 Creates a recording session in live mode.
242@sa \lt_man{lttng-create,1}
243*/
244LTTNG_EXPORT extern int lttng_create_session_snapshot(const char *session_name,
245 const char *output_url);
246
247/*!
248@brief
249 Creates a recording session named \lt_p{session_name} in
250 \ref api-session-live-mode "live" mode, optionally setting its
251 URL to \lt_p{output_url}.
252
253@deprecated
254 Use lttng_create_session_ext() with a dedicated live
255 \ref api_session_descr "recording session descriptor".
256
257@param[in] session_name
258 Name of the new recording session.
259@param[in] output_url
260 @parblock
261 \ref api-session-url "Output URL" of the recording session to
262 create: \ref api-session-one-port-url "single-port" or
263 \ref api-session-two-port-url "two-port".
264
265 If it's a \ref api-session-one-port-url "single-port output URL",
266 then the trace data port is \lt_def_net_data_port.
267
268 If \c NULL, this function uses \lt_def_net_url.
269 @endparblock
270@param[in] live_timer_period
271 Period (µs) of the \ref api-channel-live-timer "live timers" of all
272 the channels of the created recording session.
273
274@returns
275 0 on success, or a \em negative #lttng_error_code enumerator
276 otherwise.
277
278@lt_pre_conn
279@lt_pre_not_null{session_name}
280@lt_pre_sess_name_not_auto{session_name}
281@pre
282 No available recording session is named \lt_p{session_name}.
283@pre
284 <strong>If not \c NULL</strong>, \lt_p{output_url} is a valid
285 \ref api-session-one-port-url "single-port output URL" or
286 \ref api-session-two-port-url "two-port output URL".
287@pre
288 \lt_p{live_timer_period}&nbsp;≥&nbsp;1
289
290@sa lttng_create_session() --
291 Creates a recording session in local or network streaming mode.
292@sa lttng_create_session_snapshot() --
293 Creates a recording session in snapshot mode.
294@sa \lt_man{lttng-create,1}
295*/
296LTTNG_EXPORT extern int lttng_create_session_live(const char *session_name,
297 const char *output_url,
298 unsigned int live_timer_period);
299
300/*!
301@brief
302 Destroys the recording session named \lt_p{session_name}, blocking
303 until the operation completes.
304
305@deprecated
306 Use lttng_destroy_session_ext().
307
308"Destroying" a recording session means freeing the resources which the
309LTTng daemons and tracers acquired for it, also making sure to flush all
310the recorded trace data to either the local file system or the connected
311LTTng relay daemon (see \lt_man{lttng-relayd,8}), depending on the
312\ref api-session-modes "recording session mode".
313
314This function stops any recording activity within the recording session
315named \lt_p{session_name}.
316
317This function implicitly calls lttng_stop_tracing(), blocking until the
318trace data of the recording session becomes valid. Use
319lttng_destroy_session_no_wait() to avoid a blocking call.
320
321@param[in] session_name
322 Name of the recording session to destroy.
323
324@returns
325 0 on success, or a \em negative #lttng_error_code enumerator
326 otherwise.
327
328@lt_pre_conn
329@lt_pre_not_null{session_name}
330@lt_pre_sess_exists{session_name}
331
332@sa lttng_destroy_session_no_wait() --
333 Initiates the destruction operation of a recording session,
334 returning immediately.
335@sa \lt_man{lttng-destroy,1}
336*/
337LTTNG_EXPORT extern int lttng_destroy_session(const char *session_name);
338
339/*!
340@brief
341 Initiates the destruction operation of the recording session named
342 \lt_p{session_name}.
343
344@deprecated
345 Use lttng_destroy_session_ext().
346
347"Destroying" a recording session means freeing the resources which the
348LTTng daemons and tracers acquired for it, also making sure to flush all
349the recorded trace data to either the local file system or the connected
350LTTng relay daemon (see \lt_man{lttng-relayd,8}), depending on the
351\ref api-session-modes "recording session mode".
352
353Unlike lttng_destroy_session(), this function does \em not block until
354the destruction operation is complete: it returns immediately. This
355means the trace(s) of the recording session might not be valid when
356this function returns, and there's no way to know when it/they become
357valid.
358
359@param[in] session_name
360 Name of the recording session to destroy.
361
362@returns
363 0 on success, or a \em negative #lttng_error_code enumerator
364 otherwise.
365
366@lt_pre_conn
367@lt_pre_not_null{session_name}
368@lt_pre_sess_exists{session_name}
369@pre
370 No destruction operation is in progress for the recording session
371 named \lt_p{session_name}.
372
373@sa lttng_destroy_session() --
374 Destroys a recording session, blocking until the operation
375 completes.
376@sa \lt_man{lttng-destroy,1}
377*/
378LTTNG_EXPORT extern int lttng_destroy_session_no_wait(const char *session_name);
379
380/*!
381@brief
382 Initiates a destruction operation of the recording session
383 named \lt_p{session_name}.
384
385"Destroying" a recording session means freeing the resources which the
386LTTng daemons and tracers acquired for it, also making sure to flush all
387the recorded trace data to either the local file system or the connected
388LTTng relay daemon (see \lt_man{lttng-relayd,8}), depending on the
389\ref api-session-modes "recording session mode".
390
391This function doesn't block until the destruction operation completes:
392it only initiates the operation.
393Use \lt_p{*handle} to wait for the operation to complete.
394
395@param[in] session_name
396 Name of the recording session to destroy.
397@param[out] handle
398 @parblock
399 <strong>On success</strong>, this function sets \lt_p{*handle} to
400 a handle which identifies this recording session destruction
401 operation.
402
403 May be \c NULL.
404
405 Wait for the completion of this destruction operation with
406 lttng_destruction_handle_wait_for_completion().
407
408 Destroy \lt_p{*handle} with lttng_destruction_handle_destroy().
409 @endparblock
410
411@returns
412 #LTTNG_OK on success, or a \em negative enumerator otherwise.
413
414@lt_pre_conn
415@lt_pre_not_null{session_name}
416@lt_pre_sess_exists{session_name}
417@pre
418 No destruction operation is in progress for the recording session
419 named \lt_p{session_name}.
420
421@sa \lt_man{lttng-destroy,1}
422*/
28f23191
JG
423LTTNG_EXPORT extern enum lttng_error_code
424lttng_destroy_session_ext(const char *session_name, struct lttng_destruction_handle **handle);
3e3665b8 425
048f01ef
PP
426/*!
427@brief
428 Sets \lt_p{*sessions} to the summaries of all the available
429 recording sessions.
e20ee7c2 430
048f01ef
PP
431@param[out] sessions
432 @parblock
433 <strong>On success</strong>, this function sets \lt_p{*sessions} to
434 the summaries of the available recording sessions.
435
436 Free \lt_p{*sessions} with <code>free()</code>.
437 @endparblock
438
439@returns
440 The number of items in \lt_p{*sessions} on success, or a \em
441 negative #lttng_error_code enumerator otherwise.
442
443@lt_pre_conn
444@lt_pre_not_null{sessions}
445
446@sa \lt_man{lttng-list,1}
447*/
4bd69c5f 448LTTNG_EXPORT extern int lttng_list_sessions(struct lttng_session **sessions);
1239a312 449
048f01ef
PP
450/*!
451@brief
452 Sets \lt_p{*creation_timestamp} to the timestamp of the creation of
453 the recording session summarized by \lt_p{session}.
454
455@param[in] session
456 Summary of the recording session of which to get the creation
457 timestamp, as obtained with lttng_list_sessions().
458@param[out] creation_timestamp
459 <strong>On success</strong>, this function sets
460 \lt_p{*creation_timestamp} to the Unix timestamp of the creation of
461 \lt_p{session}.
462
463@returns
464 #LTTNG_OK on success, or a \em negative enumerator otherwise.
465
466@lt_pre_conn
467@lt_pre_not_null{session}
468@pre
469 The recording session summarized by \lt_p{session} is accessible
470 within the connected session daemon.
471@lt_pre_not_null{creation_timestamp}
472*/
28f23191 473LTTNG_EXPORT extern enum lttng_error_code
048f01ef 474lttng_session_get_creation_time(const struct lttng_session *session, uint64_t *creation_timestamp);
b178f53e 475
048f01ef
PP
476/*!
477@brief
478 Sets the path of the directory containing the shared memory files
479 holding the channel ring buffers of the recording session named
480 \lt_p{session_name} on the local file sytem to \lt_p{shm_dir}.
481
482Specifying a location on an
483<a href="https://en.wikipedia.org/wiki/Non-volatile_random-access_memory">NVRAM</a>
484file system makes it possible to recover the latest recorded trace data
485when the system reboots after a crash with the \lt_man{lttng-crash,1}
486utility.
487
488@param[in] session_name
489 Name of the recording session of which to set the shared memory
490 file directory path.
491@param[in] shm_dir
492 Path of the directory containing the shared memory files of the
493 recording session named \lt_p{session_name}.
494
495@returns
496 0 on success, or a \em negative #lttng_error_code enumerator
497 otherwise.
498
499@lt_pre_conn
500@lt_pre_not_null{session_name}
501@lt_pre_sess_exists{session_name}
502@lt_pre_sess_never_active{session_name}
503@lt_pre_not_null{shm_dir}
504@pre
505 \lt_p{shm_dir} is a writable directory.
506*/
507LTTNG_EXPORT extern int lttng_set_session_shm_path(const char *session_name, const char *shm_dir);
508
509/// @}
d7ba1388 510
1239a312
DG
511#ifdef __cplusplus
512}
513#endif
514
515#endif /* LTTNG_SESSION_H */
This page took 0.071599 seconds and 4 git commands to generate.