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