![]() |
LTTng control library C API
|

Data Structures | |
| struct | lttng_handle |
| Recording session handle. More... | |
| struct | lttng_session |
| Recording session summary. More... | |
Functions | |
| struct lttng_handle * | lttng_create_handle (const char *session_name, const struct lttng_domain *domain) |
Creates and returns a recording session handle from the recording session name session_name and the optional tracing domain summary domain. | |
| int | lttng_create_session (const char *session_name, const char *output_url) |
Creates a recording session named session_name in local or network streaming mode, optionally setting its output URL to output_url. | |
| enum lttng_error_code | lttng_create_session_ext (struct lttng_session_descriptor *session_descriptor) |
Creates a recording session from the recording session descriptor session_descriptor. | |
| int | lttng_create_session_live (const char *session_name, const char *output_url, unsigned int live_timer_period) |
Creates a recording session named session_name in live mode, optionally setting its URL to output_url. | |
| int | lttng_create_session_snapshot (const char *session_name, const char *output_url) |
Creates a recording session named session_name in snapshot mode, optionally setting the URL of its initial snapshot output to output_url. | |
| int | lttng_data_pending (const char *session_name) |
Returns whether or not you may read the traces of the recording session named session_name. | |
| void | lttng_destroy_handle (struct lttng_handle *handle) |
Destroys the recording session handle handle. | |
| int | lttng_destroy_session (const char *session_name) |
Destroys the recording session named session_name, blocking until the operation completes. | |
| enum lttng_error_code | lttng_destroy_session_ext (const char *session_name, struct lttng_destruction_handle **handle) |
Initiates a destruction operation of the recording session named session_name. | |
| int | lttng_destroy_session_no_wait (const char *session_name) |
Initiates the destruction operation of the recording session named session_name. | |
| enum lttng_get_session_shm_path_status | lttng_get_session_shm_path_override (const struct lttng_session *session, const char **shm_dir) |
Sets *shm_dir to the path of the custom directory on the local file system containing the shared memory files holding the event record channel ring buffers of the recording session summarized by session. | |
| enum lttng_get_session_trace_format_status | lttng_get_session_trace_format (const struct lttng_session *session, enum lttng_trace_format *format) |
Sets *format to the trace format of the recording session summarized by session. | |
| int | lttng_list_channels (const struct lttng_handle *handle, struct lttng_channel **channels) |
Sets *channels to the summaries of the event record channels of the recording session handle handle. | |
| int | lttng_list_domains (const char *session_name, struct lttng_domain **domains) |
Sets *domains to the summaries of the tracing domains which contain at least one event record channel within the recording session named session_name. | |
| int | lttng_list_sessions (struct lttng_session **sessions) |
Sets *sessions to the summaries of all the available recording sessions. | |
| int | lttng_metadata_regenerate (const char *session_name) |
Regenerates the metadata streams of the recording session named session_name. | |
| int | lttng_regenerate_metadata (const char *session_name) |
Regenerates the metadata streams of the recording session named session_name. | |
| int | lttng_regenerate_statedump (const char *session_name) |
Regenerates the state dump event records of the recording session named session_name. | |
| enum lttng_error_code | lttng_session_add_map_channel (const char *session_name, const struct lttng_map_channel_descriptor *descriptor) |
Adds the map channel described by descriptor to the recording session named session_name. | |
| enum lttng_error_code | lttng_session_get_creation_time (const struct lttng_session *session, uint64_t *creation_timestamp) |
Sets *creation_timestamp to the timestamp of the creation of the recording session summarized by session. | |
| enum lttng_error_code | lttng_session_get_map_channel_by_name (const char *session_name, enum lttng_map_channel_type type, const char *name, struct lttng_map_channel **channel) |
Sets *channel to the map channel of the recording session named session_name having the type type and the name name. | |
| enum lttng_error_code | lttng_session_list_map_channels (const char *session_name, enum lttng_map_channel_type type, struct lttng_map_channel_set **channels) |
Sets *channels to the map channels of the type type of the recording session named session_name. | |
| int | lttng_set_session_shm_path (const char *session_name, const char *shm_dir) |
Sets the path of the directory containing the shared memory files holding the event record channel ring buffers of the recording session named session_name on the local file system to shm_dir. | |
| int | lttng_start_tracing (const char *session_name) |
Makes the recording session named session_name active, starting all the tracers for its event record channels. | |
| int | lttng_stop_tracing (const char *session_name) |
Makes the recording session named session_name inactive, stopping all the tracers for its event record channels, blocking until the operation completes. | |
| int | lttng_stop_tracing_no_wait (const char *session_name) |
Makes the recording session named session_name inactive, stopping all the tracers for its event record channels without waiting for the operation to complete. | |
A recording session is a stateful dialogue between an application and a session daemon for everything related to event recording.
Everything that you do when you control LTTng tracers to record events happens within a recording session. In particular, a recording session:
Has its own state of activity (started or stopped).
An active recording session is an implicit recording event rule condition.
Similarly, LTTng only increments the values of the map channels of a recording session through “increment map value” trigger actions while the recording session is active.
Those attributes and objects are completely isolated between different recording sessions.
A recording session is like an ATM session: the operations you do on the banking system through the ATM don't alter the data of other users of the same system. In the case of the ATM, a session lasts as long as your bank card is inside. In the case of LTTng, a recording session lasts from a call to lttng_create_session_ext() to the completion of its destruction operation (which you can initiate with lttng_destroy_session_ext()).
A recording session belongs to a session daemon (see lttng-sessiond(8) and Session daemon connection). For a given session daemon, each Unix user has its own, private recording sessions. Note, however, that the root Unix user may operate on or destroy another user's recording session.
lttng-concepts(7).The recording session operations are:
| Operation | Means |
|---|---|
| Creation |
|
| Destruction |
|
| Basic property access | See: |
| Tracing domain access |
|
| Event record channel access |
|
| Activity control | See: The “start recording session” and “stop recording session” trigger actions can also activate and deactivate a recording session. |
| Listing |
|
| Process filter access | See Process filter API. |
| Clearing | See Recording session clearing API. |
| Snapshot recording | See Recording session snapshot API. The “take recording session snapshot” trigger action can also take a recording session snapshot. |
| Rotation | See Recording session rotation API. The “rotate recording session” trigger action can also rotate a recording session. |
| Saving and loading | See Recording session saving and loading API. |
| Trace data regeneration | See:
|
LTTng offers four recording session modes:
| Mode | Description | Descriptor creation function(s) |
|---|---|---|
| Local | Write the trace data to the local file system, or do not write any trace data. | |
| Network streaming | Send the trace data over the network to a listening relay daemon (see lttng-relayd(8)). | lttng_session_descriptor_network_create() |
| Snapshot | Only write the trace data to the local file system or send it to a listening relay daemon when LTTng takes a snapshot. LTTng takes a snapshot of such a recording session when:
LTTng forces the event record loss mode of all the event record channels of such a recording session to be “overwrite”. | |
| Live | Send the trace data over the network to a listening relay daemon for live reading. An LTTng live reader (for example, Babeltrace 2) can connect to the same relay daemon to receive trace data while the recording session is active. | lttng_session_descriptor_live_network_create() |
lttng-concepts(7).Some functions of the LTTng control library C API require an output URL.
An output URL is a C string which specifies where to send trace data and, when LTTng connects to a relay daemon (see lttng-relayd(8)), control commands.
There are three available output URL formats:
| Type | Description | Format |
|---|---|---|
| Local | Send trace data to the local file system, without connecting to a relay daemon. Accepted by:
|
|
| Remote: single port | Send trace data and/or control commands to a specific relay daemon with a specific TCP port. Accepted by:
|
|
| Remote: control and data ports | Send trace data and control commands to a specific relay daemon with specific TCP ports. This form is usually a shorthand for two single-port output URLs with specified ports. Accepted by:
|
|
Return type of lttng_get_session_shm_path_override().
Return type of lttng_get_session_trace_format().
| Enumerator | |
|---|---|
| LTTNG_GET_SESSION_TRACE_FORMAT_STATUS_OK | Success. |
| LTTNG_GET_SESSION_TRACE_FORMAT_STATUS_INVALID | Unsatisfied precondition. |
|
extern |
Creates and returns a recording session handle from the recording session name session_name and the optional tracing domain summary domain.
| [in] | session_name | Recording session name part of the recording session handle to create. May be |
| [in] | domain | Tracing domain summary part of the recording session handle to create. May be |
New recording session handle.
Destroy the returned handle with lttng_destroy_handle().
|
extern |
Creates a recording session named session_name in local or network streaming mode, optionally setting its output URL to output_url.
| [in] | session_name | Name of the new recording session. |
| [in] | output_url | Output URL of the recording session to create (copied). If it's a single-port output URL, then the trace data port is 5343. If |
Success
session_name is not NULL.session_name is not auto.session_name.NULL, output_url is a valid output URL.lttng-create(1)
|
extern |
Creates a recording session from the recording session descriptor session_descriptor.
See Recording session descriptor API to learn how to create a recording session descriptor.
On success, if the name property of session_descriptor isn't set, this function sets it to the automatically generated name of the recording session. Get the recording session name with lttng_session_descriptor_get_session_name().
| [in] | session_descriptor | Descriptor from which to create a recording session. |
Success
session_descriptor is not NULL.session_descriptor is set, then no available recording session has this name.
|
extern |
Creates a recording session named session_name in live mode, optionally setting its URL to output_url.
| [in] | session_name | Name of the new recording session. |
| [in] | output_url | Output URL of the recording session to create: single-port or two-port (copied). If it's a single-port output URL, then the trace data port is 5343. If |
| [in] | live_timer_period | Period (µs) of the live timers of all the event record channels of the created recording session. |
Success
session_name is not NULL.session_name is not auto.session_name.NULL, output_url is a valid single-port output URL or two-port output URL.live_timer_period ≥ 1lttng-create(1)
|
extern |
Creates a recording session named session_name in snapshot mode, optionally setting the URL of its initial snapshot output to output_url.
| [in] | session_name | Name of the new recording session. |
| [in] | output_url | URL of an initial snapshot output which LTTng adds to this recording session (copied). If it's a single-port output URL, then the trace data port is 5343. This initial snapshot output is named If |
Success
session_name is not NULL.session_name is not auto.session_name.NULL, output_url is a valid output URL.lttng-create(1)
|
extern |
Returns whether or not you may read the traces of the recording session named session_name.
It's not safe to read the traces of a recording session while LTTng is still consuming data from the tracers for its event record channels.
This function makes it possible to know when LTTng is done consuming trace data from tracers for the event record channels of the recording session named session_name.
| [in] | session_name | Name of the recording session of which get whether or not you may read its traces. |
One of:
You may read the traces of the recording session named session_name.
This remains true as long as the recording session remains inactive (stopped).
You may not read the traces of the recording session named session_name.
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name names an inactive (stopped) recording session.
|
extern |
Destroys the recording session handle handle.
This function doesn't destroy the recording session named handle->session_name, but only the handle itself.
Use lttng_destroy_session_ext() to destroy a recording session.
| [in] | handle | Recording session handle to destroy. May be |
|
extern |
Destroys the recording session named session_name, blocking until the operation completes.
“Destroying” a recording session means freeing the resources which the LTTng daemons and tracers acquired for it, also making sure to flush all the recorded trace data to either the local file system or the connected LTTng relay daemon (see lttng-relayd(8)), depending on the recording session mode.
This function stops any recording activity within the recording session named session_name.
This function implicitly calls lttng_stop_tracing(), blocking until the trace data of the recording session becomes valid. Use lttng_destroy_session_no_wait() to avoid a blocking call.
| [in] | session_name | Name of the recording session to destroy. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.lttng-destroy(1)
|
extern |
Initiates a destruction operation of the recording session named session_name.
“Destroying” a recording session means freeing the resources which the LTTng daemons and tracers acquired for it, also making sure to flush all the recorded trace data to either the local file system or the connected LTTng relay daemon (see lttng-relayd(8)), depending on the recording session mode.
This function doesn't block until the destruction operation completes: it only initiates the operation. Use *handle to wait for the operation to complete.
| [in] | session_name | Name of the recording session to destroy. |
| [out] | handle | On success, this function sets May be Wait for the completion of this destruction operation with lttng_destruction_handle_wait_for_completion(). Destroy |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name.lttng-destroy(1)
|
extern |
Initiates the destruction operation of the recording session named session_name.
“Destroying” a recording session means freeing the resources which the LTTng daemons and tracers acquired for it, also making sure to flush all the recorded trace data to either the local file system or the connected LTTng relay daemon (see lttng-relayd(8)), depending on the recording session mode.
Unlike lttng_destroy_session(), this function does not block until the destruction operation is complete: it returns immediately. This means the trace(s) of the recording session might not be valid when this function returns, and there's no way to know when it/they become valid.
| [in] | session_name | Name of the recording session to destroy. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name.lttng-destroy(1)
|
extern |
Sets *shm_dir to the path of the custom directory on the local file system containing the shared memory files holding the event record channel ring buffers of the recording session summarized by session.
This function only succeeds if the recording session summarized by session has a custom shared memory directory, as set with lttng_set_session_shm_path(); it returns LTTNG_GET_SESSION_SHM_PATH_STATUS_UNSET otherwise.
| [in] | session | Summary of the recording session, as obtained with lttng_list_sessions(), of which to get the shared memory directory path. |
| [out] | shm_dir | On success, this function sets
|
| LTTNG_GET_SESSION_SHM_PATH_STATUS_OK | Success. |
| LTTNG_GET_SESSION_SHM_PATH_STATUS_UNSET | = 1, Shared memory path isn't set. |
| LTTNG_GET_SESSION_SHM_PATH_STATUS_INVALID_PARAMETER | = -1, Unsatisfied precondition. |
session is not NULL.session is accessible within the connected session daemon.shm_path is not NULL.
|
extern |
Sets *format to the trace format of the recording session summarized by session.
| [in] | session | Summary of the recording session, as obtained with lttng_list_sessions(), of which to get the trace format. |
| [out] | format | On success, this function sets *format to the trace format of session. |
| LTTNG_GET_SESSION_TRACE_FORMAT_STATUS_OK | Success. |
| LTTNG_GET_SESSION_TRACE_FORMAT_STATUS_INVALID | Unsatisfied precondition. |
session is not NULL.format is not NULL.
|
extern |
Sets *channels to the summaries of the event record channels of the recording session handle handle.
| [in] | handle | Recording session handle which contains the name of the recording session and the summary of the tracing domain which own the event record channels of which to get the summaries. |
| [out] | channels | On success, this function sets Free |
*channels on success, or a negative lttng_error_code enumerator otherwise.handle is not NULL.handle->session_name is a valid (null-terminated) C string.handle->session_name names an accessible recording session within the connected session daemon.handle->domain is valid as per the documentation of lttng_domain.channels is not NULL.
|
extern |
Sets *domains to the summaries of the tracing domains which contain at least one event record channel within the recording session named session_name.
| [in] | session_name | Name of the recording session for which to get the tracing domain summaries. |
| [out] | domains | On success, this function sets Free |
*domains on success, or a negative lttng_error_code enumerator otherwise.session_name is not NULL.session_name names an accessible recording session within the connected session daemon.domains is not NULL.
|
extern |
Sets *sessions to the summaries of all the available recording sessions.
| [out] | sessions | On success, this function sets Free |
*sessions on success, or a negative lttng_error_code enumerator otherwise.sessions is not NULL.lttng-list(1)
|
extern |
Regenerates the metadata streams of the recording session named session_name.
| [in] | session_name | Name of the recording session of which to regenerate the metadata streams. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.
|
extern |
Regenerates the metadata streams of the recording session named session_name.
Use this function to resample the offset between the monotonic clock and the wall time of the system, and then regenerate (overwrite) all the metadata stream files (local or remote) of the recording session named session_name.
More specifically, you may want to resample the wall time following a major NTP correction. As such, LTTng can trace a system booting with an incorrect wall time before its wall time is NTP-corrected. Regenerating the metadata of a recording session ensures that trace readers can accurately determine the event record timestamps relative to the Unix epoch.
Note that if you plan to rotate the recording session named session_name, this function only regenerates the metadata stream files of the current and next trace chunks.
See the preconditions of this function which show important limitations.
| [in] | session_name | Name of the recording session of which to regenerate the metadata streams. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name was not created in live mode.session_name use a user buffering ownership model.lttng-regenerate(1)
|
extern |
Regenerates the state dump event records of the recording session named session_name.
Use this function to collect up-to-date state dump information and append corresponding event records to the sub-buffers of the recording session named session_name.
This is particularly useful if you created the recording session in snapshot mode or if LTTng rotates trace files for one of its event record channels: in both cases, the state dump information may be lost.
| [in] | session_name | Name of the recording session of which to regenerate the state dump event records. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.lttng-regenerate(1)
|
extern |
Adds the map channel described by descriptor to the recording session named session_name.
The session daemon copies the contents of descriptor: you may destroy it with lttng_map_channel_descriptor_destroy() as soon as this function returns.
When the name property of descriptor isn't set, the session daemon automatically generates a name for the resulting map channel. The generated name is a property of the map channel itself, not of descriptor: retrieve it through lttng_map_channel_get_name() with a map channel obtained with lttng_session_list_map_channels().
Within a recording session, a map channel is uniquely identified by the (type, name) pair carried by descriptor: two map channels may share the same name provided their types differ.
| [in] | session_name | Name of the recording session to which to add the map channel. |
| [in] | descriptor | Descriptor of the map channel to add to the recording session named session_name. |
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.descriptor is not NULL. descriptor already exists within the recording session named session_name.
|
extern |
Sets *creation_timestamp to the timestamp of the creation of the recording session summarized by session.
| [in] | session | Summary of the recording session of which to get the creation timestamp, as obtained with lttng_list_sessions(). |
| [out] | creation_timestamp | On success, this function sets *creation_timestamp to the Unix timestamp of the creation of session. |
| LTTNG_OK | Success. |
| LTTNG_ERR_INVALID | Unsatisfied precondition. |
| LTTNG_ERR_SESSION_NOT_EXIST | The recording session summarized by session isn't accessible within the connected session daemon. |
Success
session is not NULL.session is accessible within the connected session daemon.creation_timestamp is not NULL.
|
extern |
Sets *channel to the map channel of the recording session named session_name having the type type and the name name.
Within a recording session, a map channel is uniquely identified by the (type, name) pair: two map channels may share the same name provided their types differ.
*channel is a "snapshot" taken at call time; LTTng doesn't update it as the recording session evolves.
*channel is a client-side handle on a map channel object which lives in the session daemon: it doesn't hold map values itself. Sample the values of the maps of a given map group with lttng_map_group_get_values(), having reached the group through lttng_map_channel_get_groups().
| [in] | session_name | Name of the recording session in which to look up the map channel. |
| [in] | type | Type of the map channel to look up. |
| [in] | name | Name of the map channel to look up within the recording session named session_name and having the type type. |
| [out] | channel | On success, this function sets Destroy |
session_name is not NULL.session_name names an accessible recording session within the connected session daemon. type is a valid lttng_map_channel_type enumerator.name is not NULL. type and the name name exists within the recording session named session_name.channel is not NULL.
|
extern |
Sets *channels to the map channels of the type type of the recording session named session_name.
*channels is a "snapshot" taken at call time: LTTng doesn't update it as map channels are added to or removed from the recording session afterwards.
If type is LTTNG_MAP_CHANNEL_TYPE_KERNEL and the Linux kernel tracer is unavailable (the session daemon isn't running as the root user, or kernel tracing is disabled), then this function sets *channels to an empty set and succeeds: a recording session can't have any kernel map channel without an available kernel tracer.
The returned map channel objects are client-side handles on map channel objects which live in the session daemon: they don't hold map values themselves. Sample the values of the maps of a given map group with lttng_map_group_get_values(), having reached the group through lttng_map_channel_get_groups().
| [in] | session_name | Name of the recording session of which to get the map channels. |
| [in] | type | Type of the map channels to get. |
| [out] | channels | On success, this function sets Destroy |
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.channels is not NULL.
|
extern |
Sets the path of the directory containing the shared memory files holding the event record channel ring buffers of the recording session named session_name on the local file system to shm_dir.
Specifying a location on an NVRAM file system makes it possible to recover the latest recorded trace data when the system reboots after a crash with the lttng-crash(1) utility.
| [in] | session_name | Name of the recording session of which to set the shared memory file directory path. |
| [in] | shm_dir | Path of the directory containing the shared memory files of the recording session named session_name (copied). |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name names a recording session which never became active (started) since its creation.shm_dir is not NULL.shm_dir is a writable directory.
|
extern |
Makes the recording session named session_name active, starting all the tracers for its event record channels.
| [in] | session_name | Name of the recording session to activate/start. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name names an inactive (stopped) recording session.lttng-start(1)
|
extern |
Makes the recording session named session_name inactive, stopping all the tracers for its event record channels, blocking until the operation completes.
This function blocks until the trace data of the recording session named session_name is valid. Use lttng_stop_tracing_no_wait() to avoid a blocking call.
If LTTng archived the current trace chunk of the recording session named session_name at least once during its lifetime, then this function renames the current trace chunk subdirectory. Although it's safe to read the content of this renamed subdirectory while the recording session remains inactive, it's not a trace chunk archive: you need to destroy the recording session or a rotation needs to occur to archive it.
| [in] | session_name | Name of the recording session to deactivate/stop. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name names an active (started) recording session.lttng-stop(1)
|
extern |
Makes the recording session named session_name inactive, stopping all the tracers for its event record channels without waiting for the operation to complete.
Unlike lttng_stop_tracing(), this function does not block until the operation is complete: it returns immediately. This means the traces(s) of the recording session might not be valid when this function returns, and there's no way to know when it/they become valid.
| [in] | session_name | Name of the recording session to deactivate/stop. |
Success
session_name is not NULL.session_name names an accessible recording session within the connected session daemon.session_name names an active (started) recording session.session_name.lttng-stop(1)