2 * Copyright (C) 2014 - David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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
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
19 #ifndef LTTNG_SESSION_H
20 #define LTTNG_SESSION_H
26 enum lttng_tracker_type
{
27 LTTNG_TRACKER_PID
= 0,
28 LTTNG_TRACKER_VPID
= 1,
29 LTTNG_TRACKER_UID
= 2,
30 LTTNG_TRACKER_GID
= 3,
31 LTTNG_TRACKER_VUID
= 4,
32 LTTNG_TRACKER_VGID
= 5,
35 enum lttng_tracker_id_type
{
36 LTTNG_ID_UNKNOWN
= -1,
42 struct lttng_tracker_id
{
43 enum lttng_tracker_id_type type
;
48 struct lttng_session_descriptor
;
49 struct lttng_destruction_handle
;
52 * Basic session information.
54 * The "enabled" field is only used when listing the sessions which indicate if
55 * it's started or not.
57 * The structures should be initialized to zero before use.
59 #define LTTNG_SESSION_PADDING1 8
60 struct lttng_session
{
61 char name
[LTTNG_NAME_MAX
];
63 * Human-readable representation of the trace's destination.
64 * In the case of a local tracing session, a path is provided:
67 * In the case of a remote (network) tracing session, the string has
68 * the following format:
69 * net://hostname/path:ctrl_port [data: data_port]
72 uint32_t enabled
; /* enabled/started: 1, disabled/stopped: 0 */
73 uint32_t snapshot_mode
;
74 unsigned int live_timer_interval
; /* usec */
77 * End of public attributes.
78 * The remaining fields are used to deal with ABI management concerns.
82 * 32-bit architectures are already naturally aligned on 4 bytes after
83 * 'live_timer_interval'. However, the offset does not result in a
84 * natural alignment on 64-bit architectures. Adding 4 bytes of
85 * padding here results in an aligned offset after 'alignement_padding'
88 * This was added since not all compilers appear to align unions in the
89 * same way. Some (e.g. MSVC) do not seem to impose an alignement
90 * constraint while others (e.g. gcc, clang, icc) seem to align it to
91 * ensure 'ptr' is naturally aligned.
93 char alignment_padding
[4];
96 * Ensure the 'extended' union has the same size for both
97 * 32-bit and 64-bit builds.
99 char padding
[LTTNG_SESSION_PADDING1
];
105 * Create a session on the session daemon from a session descriptor.
107 * See the session descriptor API description in session-descriptor.h
109 * Note that unspecified session descriptor parameters, such as a session's
110 * name, are updated in the session descriptor if the creation of the session
111 * succeeds. This allows users to query the session's auto-generated name
112 * after its creation. Note that other attributes can be queried using the
113 * session listing API.
115 * Returns LTTNG_OK on success. See lttng-error.h for the meaning of the other
118 extern enum lttng_error_code
lttng_create_session_ext(
119 struct lttng_session_descriptor
*session_descriptor
);
122 * Create a tracing session using a name and an optional URL.
124 * If _url_ is NULL, no consumer is created for the session. The name can't be
127 * Return 0 on success else a negative LTTng error code.
129 extern int lttng_create_session(const char *name
, const char *url
);
132 * Create a tracing session that will exclusively be used for snapshot meaning
133 * the session will be in no output mode and every channel enabled for that
134 * session will be set in overwrite mode and in mmap output since splice is not
137 * Name can't be NULL. If an url is given, it will be used to create a default
138 * snapshot output using it as a destination. If NULL, no output will be
139 * defined and an add-output call will be needed.
141 * Return 0 on success else a negative LTTng error code.
143 extern int lttng_create_session_snapshot(const char *name
,
144 const char *snapshot_url
);
147 * Create a session exclusively used for live reading.
149 * In this mode, the switch-timer parameter is forced for each UST channel, a
150 * live-switch-timer is enabled for kernel channels, manually setting
151 * switch-timer is forbidden. Synchronization beacons are sent to the relayd,
152 * indexes are sent and metadata is checked for each packet.
154 * Name can't be NULL. If no URL is given, the default is to send the data to
155 * net://127.0.0.1. The timer_interval is in usec.
157 * Return 0 on success else a negative LTTng error code.
159 extern int lttng_create_session_live(const char *name
, const char *url
,
160 unsigned int timer_interval
);
163 * Destroy a tracing session.
165 * The session will not be usable, tracing will be stopped thus buffers will be
168 * This call will wait for data availability for each domain of the session,
169 * which can take an arbitrary amount of time. However, when returning the
170 * tracing data is guaranteed to be ready to be read and analyzed.
172 * lttng_destroy_session_no_wait() may be used if such a guarantee is not
175 * The name can't be NULL here.
177 * Return 0 on success else a negative LTTng error code.
179 extern int lttng_destroy_session(const char *name
);
182 * Destroy a tracing session.
184 * Performs the same function as lttng_destroy_session(), but provides
185 * an lttng_destruction_handle which can be used to wait for the completion
186 * of the session's destruction. The lttng_destroy_handle can also be used
187 * obtain the status and archive location of any implicit session
188 * rotation that may have occurred during the session's destruction.
190 * Returns LTTNG_OK on success. The returned handle is owned by the caller
191 * and must be free'd using lttng_destruction_handle_destroy().
193 extern enum lttng_error_code
lttng_destroy_session_ext(const char *session_name
,
194 struct lttng_destruction_handle
**handle
);
197 * Behaves exactly like lttng_destroy_session but does not wait for data
200 extern int lttng_destroy_session_no_wait(const char *name
);
203 * List all the tracing sessions.
205 * Return the number of entries of the "lttng_session" array. The caller
206 * must free the returned sessions array directly using free().
208 * On error, a negative LTTng error code is returned.
210 extern int lttng_list_sessions(struct lttng_session
**sessions
);
213 * Get the creation time of an lttng_session object on the session daemon.
215 * This function must only be used with lttng_session objects returned
216 * by lttng_list_sessions() or lttng_session_create().
218 * The creation time returned is a UNIX timestamp; the number of seconds since
219 * Epoch (1970-01-01 00:00:00 +0000 (UTC)).
221 * Returns LTTNG_OK on success. See lttng-error.h for the meaning of the other
224 extern enum lttng_error_code
lttng_session_get_creation_time(
225 const struct lttng_session
*session
, uint64_t *creation_time
);
228 * Set the shared memory path for a session.
230 * Sets the (optional) file system path where shared memory buffers will
231 * be created for the session. This is useful for buffer extraction on
232 * crash, when used with filesystems like pramfs.
234 * Return 0 on success else a negative LTTng error code.
236 extern int lttng_set_session_shm_path(const char *session_name
,
237 const char *shm_path
);
240 * Add PID to session tracker.
242 * A pid argument >= 0 adds the PID to the session tracker.
243 * A pid argument of -1 means "track all PIDs".
245 * Return 0 on success else a negative LTTng error code.
247 extern int lttng_track_pid(struct lttng_handle
*handle
, int pid
);
250 * Remove PID from session tracker.
252 * A pid argument >= 0 removes the PID from the session tracker.
253 * A pid argument of -1 means "untrack all PIDs".
255 * Return 0 on success else a negative LTTng error code.
257 extern int lttng_untrack_pid(struct lttng_handle
*handle
, int pid
);
260 * List PIDs in the tracker.
262 * enabled is set to whether the PID tracker is enabled.
263 * pids is set to an allocated array of PIDs currently tracked. On
264 * success, pids must be freed by the caller.
265 * nr_pids is set to the number of entries contained by the pids array.
267 * Returns 0 on success, else a negative LTTng error code.
269 extern int lttng_list_tracker_pids(struct lttng_handle
*handle
,
270 int *enabled
, int32_t **pids
, size_t *nr_pids
);
276 #endif /* LTTNG_SESSION_H */