lib: compile liblttng-ctl as C++
[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
55c9e7ca 16#include <lttng/constant.h>
4bd69c5f 17#include <lttng/lttng-export.h>
55c9e7ca 18
55c9e7ca 19struct lttng_handle;
b178f53e 20struct lttng_session_descriptor;
3e3665b8 21struct lttng_destruction_handle;
b178f53e 22
1239a312
DG
23/*
24 * Basic session information.
25 *
26 * The "enabled" field is only used when listing the sessions which indicate if
27 * it's started or not.
28 *
29 * The structures should be initialized to zero before use.
30 */
e9af56b3 31#define LTTNG_SESSION_PADDING1 8
1239a312 32struct lttng_session {
36d2e35d 33 char name[LTTNG_NAME_MAX];
beede00c
JG
34 /*
35 * Human-readable representation of the trace's destination.
36 * In the case of a local tracing session, a path is provided:
37 * /path/to/the/output
38 *
39 * In the case of a remote (network) tracing session, the string has
40 * the following format:
41 * net://hostname/path:ctrl_port [data: data_port]
42 */
1239a312
DG
43 char path[PATH_MAX];
44 uint32_t enabled; /* enabled/started: 1, disabled/stopped: 0 */
45 uint32_t snapshot_mode;
46 unsigned int live_timer_interval; /* usec */
47
e9af56b3
JG
48 /*
49 * End of public attributes.
50 * The remaining fields are used to deal with ABI management concerns.
51 */
52
53 /*
54 * 32-bit architectures are already naturally aligned on 4 bytes after
55 * 'live_timer_interval'. However, the offset does not result in a
56 * natural alignment on 64-bit architectures. Adding 4 bytes of
57 * padding here results in an aligned offset after 'alignement_padding'
58 * for both bitnesses.
59 *
60 * This was added since not all compilers appear to align unions in the
61 * same way. Some (e.g. MSVC) do not seem to impose an alignement
62 * constraint while others (e.g. gcc, clang, icc) seem to align it to
63 * ensure 'ptr' is naturally aligned.
64 */
65 char alignment_padding[4];
b178f53e 66 union {
e9af56b3
JG
67 /*
68 * Ensure the 'extended' union has the same size for both
69 * 32-bit and 64-bit builds.
70 */
b178f53e
JG
71 char padding[LTTNG_SESSION_PADDING1];
72 void *ptr;
73 } extended;
1239a312
DG
74};
75
b178f53e
JG
76/*
77 * Create a session on the session daemon from a session descriptor.
78 *
79 * See the session descriptor API description in session-descriptor.h
80 *
81 * Note that unspecified session descriptor parameters, such as a session's
82 * name, are updated in the session descriptor if the creation of the session
83 * succeeds. This allows users to query the session's auto-generated name
84 * after its creation. Note that other attributes can be queried using the
85 * session listing API.
86 *
87 * Returns LTTNG_OK on success. See lttng-error.h for the meaning of the other
88 * return codes.
89 */
4bd69c5f 90LTTNG_EXPORT extern enum lttng_error_code lttng_create_session_ext(
b178f53e
JG
91 struct lttng_session_descriptor *session_descriptor);
92
1239a312
DG
93/*
94 * Create a tracing session using a name and an optional URL.
95 *
96 * If _url_ is NULL, no consumer is created for the session. The name can't be
97 * NULL here.
98 *
99 * Return 0 on success else a negative LTTng error code.
100 */
4bd69c5f 101LTTNG_EXPORT extern int lttng_create_session(const char *name, const char *url);
1239a312
DG
102
103/*
104 * Create a tracing session that will exclusively be used for snapshot meaning
105 * the session will be in no output mode and every channel enabled for that
106 * session will be set in overwrite mode and in mmap output since splice is not
107 * supported.
108 *
109 * Name can't be NULL. If an url is given, it will be used to create a default
110 * snapshot output using it as a destination. If NULL, no output will be
111 * defined and an add-output call will be needed.
112 *
113 * Return 0 on success else a negative LTTng error code.
114 */
4bd69c5f 115LTTNG_EXPORT extern int lttng_create_session_snapshot(const char *name,
1239a312
DG
116 const char *snapshot_url);
117
118/*
119 * Create a session exclusively used for live reading.
120 *
121 * In this mode, the switch-timer parameter is forced for each UST channel, a
122 * live-switch-timer is enabled for kernel channels, manually setting
123 * switch-timer is forbidden. Synchronization beacons are sent to the relayd,
124 * indexes are sent and metadata is checked for each packet.
125 *
126 * Name can't be NULL. If no URL is given, the default is to send the data to
1aacaae2 127 * net://127.0.0.1. The timer_interval is in usec.
1239a312
DG
128 *
129 * Return 0 on success else a negative LTTng error code.
130 */
4bd69c5f 131LTTNG_EXPORT extern int lttng_create_session_live(const char *name, const char *url,
1239a312
DG
132 unsigned int timer_interval);
133
134/*
135 * Destroy a tracing session.
136 *
137 * The session will not be usable, tracing will be stopped thus buffers will be
138 * flushed.
139 *
e20ee7c2
JD
140 * This call will wait for data availability for each domain of the session,
141 * which can take an arbitrary amount of time. However, when returning the
142 * tracing data is guaranteed to be ready to be read and analyzed.
143 *
144 * lttng_destroy_session_no_wait() may be used if such a guarantee is not
145 * needed.
146 *
1239a312
DG
147 * The name can't be NULL here.
148 *
780d4bb8 149 * Return 0 on success else a negative LTTng error code.
1239a312 150 */
4bd69c5f 151LTTNG_EXPORT extern int lttng_destroy_session(const char *name);
1239a312 152
3e3665b8
JG
153/*
154 * Destroy a tracing session.
155 *
156 * Performs the same function as lttng_destroy_session(), but provides
157 * an lttng_destruction_handle which can be used to wait for the completion
158 * of the session's destruction. The lttng_destroy_handle can also be used
159 * obtain the status and archive location of any implicit session
83ed9e90 160 * rotation that may have occurred during the session's destruction.
3e3665b8
JG
161 *
162 * Returns LTTNG_OK on success. The returned handle is owned by the caller
163 * and must be free'd using lttng_destruction_handle_destroy().
164 */
4bd69c5f 165LTTNG_EXPORT extern enum lttng_error_code lttng_destroy_session_ext(const char *session_name,
3e3665b8
JG
166 struct lttng_destruction_handle **handle);
167
e20ee7c2
JD
168/*
169 * Behaves exactly like lttng_destroy_session but does not wait for data
170 * availability.
171 */
4bd69c5f 172LTTNG_EXPORT extern int lttng_destroy_session_no_wait(const char *name);
e20ee7c2 173
1239a312
DG
174/*
175 * List all the tracing sessions.
176 *
b178f53e
JG
177 * Return the number of entries of the "lttng_session" array. The caller
178 * must free the returned sessions array directly using free().
179 *
180 * On error, a negative LTTng error code is returned.
1239a312 181 */
4bd69c5f 182LTTNG_EXPORT extern int lttng_list_sessions(struct lttng_session **sessions);
1239a312 183
b178f53e
JG
184/*
185 * Get the creation time of an lttng_session object on the session daemon.
186 *
187 * This function must only be used with lttng_session objects returned
188 * by lttng_list_sessions() or lttng_session_create().
189 *
190 * The creation time returned is a UNIX timestamp; the number of seconds since
191 * Epoch (1970-01-01 00:00:00 +0000 (UTC)).
192 *
193 * Returns LTTNG_OK on success. See lttng-error.h for the meaning of the other
194 * return codes.
195 */
4bd69c5f 196LTTNG_EXPORT extern enum lttng_error_code lttng_session_get_creation_time(
b178f53e
JG
197 const struct lttng_session *session, uint64_t *creation_time);
198
d7ba1388
MD
199/*
200 * Set the shared memory path for a session.
201 *
202 * Sets the (optional) file system path where shared memory buffers will
203 * be created for the session. This is useful for buffer extraction on
204 * crash, when used with filesystems like pramfs.
205 *
206 * Return 0 on success else a negative LTTng error code.
207 */
4bd69c5f 208LTTNG_EXPORT extern int lttng_set_session_shm_path(const char *session_name,
d7ba1388
MD
209 const char *shm_path);
210
1239a312
DG
211#ifdef __cplusplus
212}
213#endif
214
215#endif /* LTTNG_SESSION_H */
This page took 0.04417 seconds and 4 git commands to generate.