NAME
lttng-ust - LTTng user space tracingSYNOPSIS
#include <lttng/tracepoint.h>
#define LTTNG_UST_TP_ARGS(args...) #define LTTNG_UST_TP_ENUM_VALUES(values...) #define LTTNG_UST_TP_FIELDS(fields...) #define LTTNG_UST_TRACEPOINT_ENUM(prov_name, enum_name, mappings) #define LTTNG_UST_TRACEPOINT_EVENT(prov_name, t_name, args, fields) #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(cls_prov_name, cls_name, args, fields) #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(cls_prov_name, cls_name, inst_prov_name, t_name, args) #define LTTNG_UST_TRACEPOINT_LOGLEVEL(prov_name, t_name, level) #define lttng_ust_do_tracepoint(prov_name, t_name, ...) #define lttng_ust_field_array(int_type, field_name, expr, count) #define lttng_ust_field_array_nowrite(int_type, field_name, expr, count) #define lttng_ust_field_array_hex(int_type, field_name, expr, count) #define lttng_ust_field_array_nowrite_hex(int_type, field_name, expr, count) #define lttng_ust_field_array_network(int_type, field_name, expr, count) #define lttng_ust_field_array_network_nowrite(int_type, field_name, expr, count) #define lttng_ust_field_array_network_hex(int_type, field_name, expr, count) #define lttng_ust_field_array_network_nowrite_hex(int_type, field_name, expr, count) #define lttng_ust_field_array_text(char, field_name, expr, count) #define lttng_ust_field_array_text_nowrite(char, field_name, expr, count) #define lttng_ust_field_enum(prov_name, enum_name, int_type, field_name, expr) #define lttng_ust_field_enum_nowrite(prov_name, enum_name, int_type, field_name, expr) #define lttng_ust_field_enum_value(label, value) #define lttng_ust_field_enum_range(label, start, end) #define lttng_ust_field_float(float_type, field_name, expr) #define lttng_ust_field_float_nowrite(float_type, field_name, expr) #define lttng_ust_field_integer(int_type, field_name, expr) #define lttng_ust_field_integer_hex(int_type, field_name, expr) #define lttng_ust_field_integer_network(int_type, field_name, expr) #define lttng_ust_field_integer_network_hex(int_type, field_name, expr) #define lttng_ust_field_integer_nowrite(int_type, field_name, expr) #define lttng_ust_field_sequence(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_nowrite(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_hex(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_nowrite_hex(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_network(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_network_nowrite(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_network_hex(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_network_nowrite_hex(int_type, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_text(char, field_name, expr, len_type, len_expr) #define lttng_ust_field_sequence_text_nowrite(char, field_name, expr, len_type, len_expr) #define lttng_ust_field_string(field_name, expr) #define lttng_ust_field_string_nowrite(field_name, expr) #define lttng_ust_tracepoint(prov_name, t_name, ...) #define lttng_ust_tracepoint_enabled(prov_name, t_name)
•-llttng-ust -ldl
•If you define _LGPL_SOURCE
before including <lttng/tracepoint.h> (directly or indirectly):
-llttng-ust-common
DESCRIPTION
The Linux Trace Toolkit: next generation <http://lttng.org/> is an open source software package used for correlated tracing of the Linux kernel, user applications, and user libraries.•Using the lttng_ust_tracef(3)
API, which is similar to printf(3).
•Using the lttng_ust_tracelog(3)
API, which is lttng_ust_tracef(3) with a log level parameter.
•Defining your own tracepoints. See the
Creating a tracepoint provider section below.
Compatibility with previous APIs
Since LTTng-UST 2.13, the LTTNG_UST_COMPAT_API_VERSION definition controls which LTTng-UST APIs are available (compiled): UndefinedAll APIs are available.
N (0 or positive integer)
API version N, and all the
following existing APIs, are available. Previous APIs are not available (not
compiled).
LTTng-UST version | Available API versions |
2.0 to 2.12 | 0 |
2.13 | 0 and 1 |
Creating a tracepoint provider
Creating a tracepoint provider is the first step of using liblttng-ust. The next steps are:•Instrumenting your application with
lttng_ust_tracepoint() calls
•Building your application with
LTTng-UST support, either statically or dynamically.
#undef LTTNG_UST_TRACEPOINT_PROVIDER #define LTTNG_UST_TRACEPOINT_PROVIDER my_provider #undef LTTNG_UST_TRACEPOINT_INCLUDE #define LTTNG_UST_TRACEPOINT_INCLUDE "./tp.h" #if !defined(_TP_H) || \ defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ) #define _TP_H #include <lttng/tracepoint.h> /* * LTTNG_UST_TRACEPOINT_EVENT(), LTTNG_UST_TRACEPOINT_EVENT_CLASS(), * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(), * LTTNG_UST_TRACEPOINT_LOGLEVEL(), and `LTTNG_UST_TRACEPOINT_ENUM()` * are used here. */ #endif /* _TP_H */ #include <lttng/tracepoint-event.h>
#define LTTNG_UST_TRACEPOINT_CREATE_PROBES #include "tp.h"
LTTNG_UST_TRACEPOINT_EVENT() usage
The LTTNG_UST_TRACEPOINT_EVENT() macro is used in a template provider header file (see the Creating a tracepoint provider section above) to define LTTng-UST tracepoints.LTTNG_UST_TRACEPOINT_EVENT( /* Tracepoint provider name */ my_provider, /* Tracepoint/event name */ my_tracepoint, /* List of tracepoint arguments (input) */ LTTNG_UST_TP_ARGS( ... ), /* List of fields of eventual event (output) */ LTTNG_UST_TP_FIELDS( ... ) )
LTTNG_UST_TP_ARGS( int, my_int, const char *, my_string, FILE *, my_file, double, my_float, struct my_data *, my_data )
Available field macros
This section documents the available lttng_ust_field_*() macros that can be inserted in the LTTNG_UST_TP_FIELDS() macro of the LTTNG_UST_TRACEPOINT_EVENT() macro.lttng_ust_field_integer(int_type, field_name, expr) lttng_ust_field_integer_nowrite(int_type, field_name, expr)
lttng_ust_field_integer_hex(int_type, field_name, expr)
lttng_ust_field_integer_network(int_type, field_name, expr)
lttng_ust_field_integer_network_hex(int_type, field_name, expr)
lttng_ust_field_float(float_type, field_name, expr) lttng_ust_field_float_nowrite(float_type, field_name, expr)
lttng_ust_field_string(field_name, expr) lttng_ust_field_string_nowrite(field_name, expr)
lttng_ust_field_array(int_type, field_name, expr, count) lttng_ust_field_array_nowrite(int_type, field_name, expr, count) lttng_ust_field_array_hex(int_type, field_name, expr, count) lttng_ust_field_array_nowrite_hex(int_type, field_name, expr, count) lttng_ust_field_array_network(int_type, field_name, expr, count) lttng_ust_field_array_network_nowrite(int_type, field_name, expr, count) lttng_ust_field_array_network_hex(int_type, field_name, expr, count) lttng_ust_field_array_network_nowrite_hex(int_type, field_name, expr, count)
lttng_ust_field_array_text(char, field_name, expr, count) lttng_ust_field_array_text_nowrite(char, field_name, expr, count)
lttng_ust_field_sequence(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_nowrite(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_hex(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_nowrite_hex(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_network(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_network_nowrite(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_network_hex(int_type, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_network_nowrite_hex(int_type, field_name, expr, len_type, len_expr)
lttng_ust_field_sequence_text(char, field_name, expr, len_type, len_expr) lttng_ust_field_sequence_text_nowrite(char, field_name, expr, len_type, len_expr)
lttng_ust_field_enum(prov_name, enum_name, int_type, field_name, expr) lttng_ust_field_enum_nowrite(prov_name, enum_name, int_type, field_name, expr)
Number of elements in array/sequence. This
must be known at compile time.
enum_name
Name of an enumeration field previously
defined with the LTTNG_UST_TRACEPOINT_ENUM() macro. See the
LTTNG_UST_TRACEPOINT_ENUM() usage section for more
information.
expr
C expression resulting in the field’s
value. This expression can use one or more arguments passed to the tracepoint.
The arguments of a given tracepoint are defined in the
LTTNG_UST_TP_ARGS() macro (see the Creating a tracepoint
provider section above).
field_name
Event field name (C identifier syntax, NOT a
literal string).
float_type
Float C type (float or double).
The size of this type determines the size of the floating point number
field.
int_type
Integer C type. The size of this type
determines the size of the integer/enumeration field.
len_expr
C expression resulting in the
sequence’s length. This expression can use one or more arguments passed
to the tracepoint.
len_type
Unsigned integer C type of sequence’s
length.
prov_name
Tracepoint provider name. This must be the
same as the tracepoint provider name used in a previous field
definition.
LTTNG_UST_TRACEPOINT_ENUM() usage
An enumeration field is a list of mappings between an integers, or a range of integers, and strings (sometimes called labels or enumerators). Enumeration fields can be used to have a more compact trace when the possible values for a field are limited.LTTNG_UST_TRACEPOINT_ENUM( /* Tracepoint provider name */ my_provider, /* Enumeration name (unique in the whole tracepoint provider) */ my_enum, /* Enumeration mappings */ LTTNG_UST_TP_ENUM_VALUES( ... ) )
lttng_ust_field_enum_value(label, value)
lttng_ust_field_enum_range(label, start, end)
LTTNG_UST_TRACEPOINT_EVENT_CLASS() usage
A tracepoint class is a class of tracepoints sharing the same field types and names. A tracepoint instance is one instance of such a declared tracepoint class, with its own event name.#define LTTNG_UST_TRACEPOINT_PROVIDER my_provider /* ... */ LTTNG_UST_TRACEPOINT_EVENT_CLASS( /* Tracepoint class provider name */ my_provider, /* Tracepoint class name */ my_tracepoint_class, /* List of tracepoint arguments (input) */ LTTNG_UST_TP_ARGS( ... ), /* List of fields of eventual event (output) */ LTTNG_UST_TP_FIELDS( ... ) )
#define LTTNG_UST_TRACEPOINT_PROVIDER natality /* ... */ LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( /* Name of the tracepoint class provider */ my_provider, /* Tracepoint class name */ my_tracepoint_class, /* Name of the local (instance) tracepoint provider */ natality, /* Tracepoint/event name */ my_tracepoint, /* List of tracepoint arguments (input) */ LTTNG_UST_TP_ARGS( ... ) )
•The name of the tracepoint class
provider ( my_provider in the example above).
This is the same as the first argument of the
LTTNG_UST_TRACEPOINT_EVENT_CLASS() expansion to refer to.
•The name of the local, or instance,
provider ( natality in the example above).
This is the provider name which becomes the prefix part of the name of the
events which such a tracepoint creates.
LTTNG_UST_TRACEPOINT_LOGLEVEL() usage
Optionally, a log level can be assigned to a defined tracepoint. Assigning different levels of severity to tracepoints can be useful: when controlling tracing sessions, you can choose to only enable events falling into a specific log level range using the --loglevel and --loglevel-only options of the lttng-enable-event(1) command.LTTNG_UST_TRACEPOINT_LOGLEVEL( /* Tracepoint provider name */ my_provider, /* Tracepoint/event name */ my_tracepoint, /* Log level */ LTTNG_UST_TRACEPOINT_LOGLEVEL_INFO )
System is unusable.
LTTNG_UST_TRACEPOINT_LOGLEVEL_ALERT
Action must be taken immediately.
LTTNG_UST_TRACEPOINT_LOGLEVEL_CRIT
Critical conditions.
LTTNG_UST_TRACEPOINT_LOGLEVEL_ERR
Error conditions.
LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING
Warning conditions.
LTTNG_UST_TRACEPOINT_LOGLEVEL_NOTICE
Normal, but significant, condition.
LTTNG_UST_TRACEPOINT_LOGLEVEL_INFO
Informational message.
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_SYSTEM
Debug information with system-level scope (set
of programs).
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROGRAM
Debug information with program-level scope
(set of processes).
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROCESS
Debug information with process-level scope
(set of modules).
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_MODULE
Debug information with module
(executable/library) scope (set of units).
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT
Debug information with compilation unit scope
(set of functions).
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_FUNCTION
Debug information with function-level
scope.
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_LINE
Debug information with line-level scope
(default log level).
LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG
Debug-level message.
Instrumenting your application
Once the tracepoint provider is created (see the Creating a tracepoint provider section above), you can instrument your application with the defined tracepoints thanks to the lttng_ust_tracepoint() macro:#define lttng_ust_tracepoint(prov_name, t_name, ...)
Tracepoint provider name.
t_name
Tracepoint/event name.
...
Tracepoint arguments, if any.
#define lttng_ust_tracepoint_enabled(prov_name, t_name) #define lttng_ust_do_tracepoint(prov_name, t_name, ...)
if (lttng_ust_tracepoint_enabled(my_provider, my_tracepoint)) { stuff = prepare_stuff(); } lttng_ust_tracepoint(my_provider, my_tracepoint, stuff);
Statically linking the tracepoint provider
With the static linking method, compiled tracepoint providers are copied into the target application.#define LTTNG_UST_TRACEPOINT_CREATE_PROBES #define LTTNG_UST_TRACEPOINT_DEFINE #include "tp.h"
$ cc -c -I. tp.c
$ ar rc tp.a tp.o
$ cc -o app tp.o app.o -llttng-ust -ldl
Dynamically loading the tracepoint provider
The second approach to package the tracepoint provider is to use the dynamic loader: the library and its member functions are explicitly sought, loaded at run time.•Since the tracepoint provider is not
part of the application, LTTNG_UST_TRACEPOINT_DEFINE must be defined,
for each tracepoint provider, in exactly one source file of the
application
•LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE
must be defined next to LTTNG_UST_TRACEPOINT_DEFINE
#define LTTNG_UST_TRACEPOINT_DEFINE #define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE #include "tp.h"
$ cc -c -fpic -I. tp.c
$ cc -shared -Wl,--no-as-needed -o tp.so tp.o -llttng-ust
$ cc -o app app.o tp-define.o -ldl
•Load it manually from the application
using dlopen(3)
•Make the dynamic loader load it with
the LD_PRELOAD environment variable (see ld.so(8))
•Statically link the tracepoint
provider to the application, or
•Build the tracepoint provider as a
shared object (following the procedure shown in this section), and preload it
when tracing is needed using the LD_PRELOAD environment variable.
Using LTTng-UST with daemons
Some extra care is needed when using liblttng-ust with daemon applications that call fork(2), clone(2), or BSD’s rfork(2) without a following exec(3) family system call. The library liblttng-ust-fork.so needs to be preloaded before starting the application with the LD_PRELOAD environment variable (see ld.so(8)).Context information
Context information can be prepended by the LTTng-UST tracer before each event, or before specific events.
cpu_id
Process context fields
CPU ID.
Note
This context field is always enabled, and it cannot be added with
lttng-add-context(1). Its main purpose is to be used for dynamic event
filtering. See lttng-enable-event(1) for more information about event
filtering.
ip
Instruction pointer: enables recording the
exact address from which an event was emitted. This context field can be used
to reverse-lookup the source location that caused the event to be
emitted.
pthread_id
POSIX thread identifier.
Can be used on architectures where pthread_t maps nicely to an
unsigned long type.
procname
perf context fields
Thread name, as set by exec(3) or
prctl(2). It is recommended that programs set their thread name with
prctl(2) before hitting the first tracepoint for that thread.
vpid
Virtual process ID: process ID as seen from
the point of view of the current process ID namespace (see
pid_namespaces(7)).
vtid
Virtual thread ID: thread ID as seen from the
point of view of the current process ID namespace (see
pid_namespaces(7)).
perf:thread:COUNTER
Namespace context fields (see namespaces(7))
perf counter named COUNTER. Use
lttng add-context --list to list the available perf counters.
Only available on IA-32 and x86-64 architectures.
perf:thread:raw:rN:NAME
perf counter with raw ID N and custom
name NAME. See lttng-add-context(1) for more details.
cgroup_ns
Credential context fields (see credentials(7))
Inode number of the current control group
namespace (see cgroup_namespaces(7)) in the proc file system.
ipc_ns
Inode number of the current IPC namespace (see
ipc_namespaces(7)) in the proc file system.
mnt_ns
Inode number of the current mount point
namespace (see mount_namespaces(7)) in the proc file system.
net_ns
Inode number of the current network namespace
(see network_namespaces(7)) in the proc file system.
pid_ns
Inode number of the current process ID
namespace (see pid_namespaces(7)) in the proc file system.
time_ns
Inode number of the current clock namespace
(see time_namespaces(7)) in the proc file system.
user_ns
Inode number of the current user namespace
(see user_namespaces(7)) in the proc file system.
uts_ns
Inode number of the current UTS namespace (see
uts_namespaces(7)) in the proc file system.
vuid
Virtual real user ID: real user ID as seen
from the point of view of the current user namespace (see
user_namespaces(7)).
vgid
Virtual real group ID: real group ID as seen
from the point of view of the current user namespace (see
user_namespaces(7)).
veuid
Virtual effective user ID: effective user ID
as seen from the point of view of the current user namespace (see
user_namespaces(7)).
vegid
Virtual effective group ID: effective group ID
as seen from the point of view of the current user namespace (see
user_namespaces(7)).
vsuid
Virtual saved set-user ID: saved set-user ID
as seen from the point of view of the current user namespace (see
user_namespaces(7)).
vsgid
Virtual saved set-group ID: saved set-group ID
as seen from the point of view of the current user namespace (see
user_namespaces(7)).
LTTng-UST state dump
If an application that uses liblttng-ust becomes part of a tracing session, information about its currently loaded shared objects, their build IDs, and their debug link information are emitted as events by the tracer.Emitted when the state dump begins.
This event has no fields.
lttng_ust_statedump:end
Emitted when the state dump ends. Once this
event is emitted, it is guaranteed that, for a given process, the state dump
is complete.
This event has no fields.
lttng_ust_statedump:bin_info
Emitted when information about a currently
loaded executable or shared object is found.
Fields:
lttng_ust_statedump:build_id
Field name | Description |
baddr | Base address of loaded executable. |
memsz | Size of loaded executable in memory. |
path | Path to loaded executable file. |
is_pic | Whether or not the executable is position-independent code. |
has_build_id | Whether or not the executable has a build ID. If this field is 1, you can expect that an lttng_ust_statedump:build_id event record follows this one (not necessarily immediately after). |
has_debug_link | Whether or not the executable has debug link information. If this field is 1, you can expect that an lttng_ust_statedump:debug_link event record follows this one (not necessarily immediately after). |
Emitted when a build ID is found in a
currently loaded shared library. See Debugging Information in Separate Files
<https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html>
for more information about build IDs.
Fields:
lttng_ust_statedump:debug_link
Field name | Description |
baddr | Base address of loaded library. |
build_id | Build ID. |
Emitted when debug link information is found
in a currently loaded shared library. See Debugging Information in Separate
Files
<https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html>
for more information about debug links.
Fields:
lttng_ust_statedump:procname
Field name | Description |
baddr | Base address of loaded library. |
crc | Debug link file’s CRC. |
filename | Debug link file name. |
The process procname at process start.
Fields:
Field name | Description |
procname | The process name. |
Shared library load/unload tracking
The LTTng-UST state dump and the LTTng-UST helper library to instrument the dynamic linker (see liblttng-ust-dl(3)) can emit shared library load/unload tracking events.Emitted when a shared library (shared object)
is loaded.
Fields:
lttng_ust_lib:unload
Field name | Description |
baddr | Base address of loaded library. |
memsz | Size of loaded library in memory. |
path | Path to loaded library file. |
has_build_id | Whether or not the library has a build ID. If this field is 1, you can expect that an lttng_ust_lib:build_id event record follows this one (not necessarily immediately after). |
has_debug_link | Whether or not the library has debug link information. If this field is 1, you can expect that an lttng_ust_lib:debug_link event record follows this one (not necessarily immediately after). |
Emitted when a shared library (shared object)
is unloaded.
Fields:
lttng_ust_lib:build_id
Field name | Description |
baddr | Base address of unloaded library. |
Emitted when a build ID is found in a loaded
shared library (shared object). See Debugging Information in Separate Files
<https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html>
for more information about build IDs.
Fields:
lttng_ust_lib:debug_link
Field name | Description |
baddr | Base address of loaded library. |
build_id | Build ID. |
Emitted when debug link information is found
in a loaded shared library (shared object). See Debugging Information in
Separate Files
<https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html>
for more information about debug links.
Fields:
Field name | Description |
baddr | Base address of loaded library. |
crc | Debug link file’s CRC. |
filename | Debug link file name. |
Detect if LTTng-UST is loaded
To detect if liblttng-ust is loaded from an application: 1.Define the lttng_ust_loaded weak
symbol globally:
This weak symbol is set by the constructor of liblttng-ust.
int lttng_ust_loaded __attribute__((weak));
2.Test lttng_ust_loaded where needed:
/* ... */ if (lttng_ust_loaded) { /* LTTng-UST is loaded */ } else { /* LTTng-UST is NOT loaded */ } /* ... */
EXAMPLE
$ cc -c -I. tp.c $ cc -c app.c $ cc -o app tp.o app.o -llttng-ust -ldl
$ lttng create my-session $ lttng enable-event --userspace 'my_provider:*' $ lttng start
$ lttng enable-event --userspace my_provider:big_event $ lttng enable-event --userspace my_provider:event_instance2
$ ./app some arguments
$ lttng stop $ lttng view
Tracepoint provider header file
tp.h:#undef LTTNG_UST_TRACEPOINT_PROVIDER #define LTTNG_UST_TRACEPOINT_PROVIDER my_provider #undef LTTNG_USTTRACEPOINT_INCLUDE #define LTTNG_USTTRACEPOINT_INCLUDE "./tp.h" #if !defined(_TP_H) || \ defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ) #define _TP_H #include <lttng/tracepoint.h> #include <stdio.h> #include "app.h" LTTNG_UST_TRACEPOINT_EVENT( my_provider, simple_event, LTTNG_UST_TP_ARGS( int, my_integer_arg, const char *, my_string_arg ), LTTNG_UST_TP_FIELDS( lttng_ust_field_string(argc, my_string_arg) lttng_ust_field_integer(int, argv, my_integer_arg) ) ) LTTNG_UST_TRACEPOINT_ENUM( my_provider, my_enum, LTTNG_UST_TP_ENUM_VALUES( lttng_ust_field_enum_value("ZERO", 0) lttng_ust_field_enum_value("ONE", 1) lttng_ust_field_enum_value("TWO", 2) lttng_ust_field_enum_range("A RANGE", 52, 125) lttng_ust_field_enum_value("ONE THOUSAND", 1000) ) ) LTTNG_UST_TRACEPOINT_EVENT( my_provider, big_event, LTTNG_UST_TP_ARGS( int, my_integer_arg, const char *, my_string_arg, FILE *, stream, double, flt_arg, int *, array_arg ), LTTNG_UST_TP_FIELDS( lttng_ust_field_integer(int, int_field1, my_integer_arg * 2) lttng_ust_field_integer_hex(long int, stream_pos, ftell(stream)) lttng_ust_field_float(double, float_field, flt_arg) lttng_ust_field_string(string_field, my_string_arg) lttng_ust_field_array(int, array_field, array_arg, 7) lttng_ust_field_array_text(char, array_text_field, array_arg, 5) lttng_ust_field_sequence(int, seq_field, array_arg, int, my_integer_arg / 10) lttng_ust_field_sequence_text(char, seq_text_field, array_arg, int, my_integer_arg / 5) lttng_ust_field_enum(my_provider, my_enum, int, enum_field, array_arg[1]) ) ) LTTNG_UST_TRACEPOINT_LOGLEVEL(my_provider, big_event, LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING) LTTNG_UST_TRACEPOINT_EVENT_CLASS( my_provider, my_tracepoint_class, LTTNG_UST_TP_ARGS( int, my_integer_arg, struct app_struct *, app_struct_arg ), LTTNG_UST_TP_FIELDS( lttng_ust_field_integer(int, a, my_integer_arg) lttng_ust_field_integer(unsigned long, b, app_struct_arg->b) lttng_ust_field_string(c, app_struct_arg->c) ) ) LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( my_provider, my_tracepoint_class, my_provider, event_instance1, LTTNG_UST_TP_ARGS( int, my_integer_arg, struct app_struct *, app_struct_arg ) ) LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( my_provider, my_tracepoint_class, my_provider, event_instance2, LTTNG_UST_TP_ARGS( int, my_integer_arg, struct app_struct *, app_struct_arg ) ) LTTNG_UST_TRACEPOINT_LOGLEVEL(my_provider, event_instance2, LTTNG_UST_TRACEPOINT_LOGLEVEL_INFO) LTTNG_UST_TRACEPOINT_EVENT_INSTANCE( my_provider, my_tracepoint_class, my_provider, event_instance3, LTTNG_UST_TP_ARGS( int, my_integer_arg, struct app_struct *, app_struct_arg ) ) #endif /* _TP_H */ #include <lttng/tracepoint-event.h>
Tracepoint provider source file
tp.c:#define LTTNG_UST_TRACEPOINT_CREATE_PROBES #define LTTNG_UST_TRACEPOINT_DEFINE #include "tp.h"
Application header file
app.h:#ifndef _APP_H #define _APP_H struct app_struct { unsigned long b; const char *c; double d; }; #endif /* _APP_H */
Application source file
app.c:#include <stdlib.h> #include <stdio.h> #include "tp.h" #include "app.h" static int array_of_ints[] = { 100, -35, 1, 23, 14, -6, 28, 1001, -3000, }; int main(int argc, char* argv[]) { FILE *stream; struct app_struct app_struct; lttng_ust_tracepoint(my_provider, simple_event, argc, argv[0]); stream = fopen("/tmp/app.txt", "w"); if (!stream) { fprintf(stderr, "Error: Cannot open /tmp/app.txt for writing\n"); return EXIT_FAILURE; } if (fprintf(stream, "0123456789") != 10) { fclose(stream); fprintf(stderr, "Error: Cannot write to /tmp/app.txt\n"); return EXIT_FAILURE; } lttng_ust_tracepoint(my_provider, big_event, 35, "hello tracepoint", stream, -3.14, array_of_ints); fclose(stream); app_struct.b = argc; app_struct.c = "[the string]"; lttng_ust_tracepoint(my_provider, event_instance1, 23, &app_struct); app_struct.b = argc * 5; app_struct.c = "[other string]"; lttng_ust_tracepoint(my_provider, event_instance2, 17, &app_struct); app_struct.b = 23; app_struct.c = "nothing"; lttng_ust_tracepoint(my_provider, event_instance3, -52, &app_struct); return EXIT_SUCCESS; }
ENVIRONMENT VARIABLES
LTTNG_HOMEAlternative user’s home directory. This
variable is useful when the user running the instrumented application has a
non-writable home directory.
Unix sockets used for the communication between liblttng-ust and the
LTTng session and consumer daemons (part of the LTTng-tools project) are
located in a specific directory under $LTTNG_HOME (or $HOME if
$LTTNG_HOME is not set).
LTTNG_UST_ALLOW_BLOCKING
If set, allow the application to retry event
tracing when there’s no space left for the event record in the
sub-buffer, therefore effectively blocking the application until space is made
available or the configured timeout is reached.
To allow an application to block during tracing, you also need to specify a
blocking timeout when you create a channel with the --blocking-timeout
option of the lttng-enable-channel(1) command.
This option can be useful in workloads generating very large trace data
throughput, where blocking the application is an acceptable trade-off to
prevent discarding event records.
Warning
Setting this environment variable may significantly affect application timings.
LTTNG_UST_ABORT_ON_CRITICAL
If set, abort the instrumented application on
a critical error message.
LTTNG_UST_CLOCK_PLUGIN
Path to the shared object which acts as the
clock override plugin. An example of such a plugin can be found in the
LTTng-UST documentation under
LTTNG_UST_DEBUG
If set, enable liblttng-ust's debug and
error output.
LTTNG_UST_GETCPU_PLUGIN
Path to the shared object which acts as the
getcpu() override plugin. An example of such a plugin can be found in
the LTTng-UST documentation under
LTTNG_UST_REGISTER_TIMEOUT
Waiting time for the registration done
session daemon command before proceeding to execute the main program
(milliseconds).
The value 0 means do not wait. The value -1 means wait
forever. Setting this environment variable to 0 is recommended for
applications with time constraints on the process startup time.
Default: 3000.
LTTNG_UST_WITHOUT_BADDR_STATEDUMP
If set, prevents liblttng-ust from
performing a base address state dump (see the LTTng-UST state dump
section above).
LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP
If set, prevents liblttng-ust from
performing a procname state dump (see the LTTng-UST state dump section
above).
BUGS
If you encounter any issue or usability problem, please report it on the LTTng bug tracker <https://bugs.lttng.org/projects/lttng-ust>.RESOURCES
•LTTng project website
<http://lttng.org>
•LTTng documentation
<http://lttng.org/docs>
•Git repositories
<http://git.lttng.org>
•GitHub organization
<http://github.com/lttng>
•Continuous integration
<http://ci.lttng.org/>
•Mailing list
<http://lists.lttng.org> for support and development:
[email protected]
•IRC channel
<irc://irc.oftc.net/lttng>: #lttng on irc.oftc.net
COPYRIGHTS
This library is part of the LTTng-UST project.THANKS
Thanks to Ericsson for funding this work, providing real-life use cases, and testing.AUTHORS
LTTng-UST was originally written by Mathieu Desnoyers, with additional contributions from various other people. It is currently maintained by Mathieu Desnoyers <mailto:[email protected]>.SEE ALSO
lttng_ust_tracef(3), lttng_ust_tracelog(3), lttng-gen-tp(1), lttng-ust-dl(3), lttng-ust-cyg-profile(3), lttng(1), lttng-enable-event(1), lttng-list(1), lttng-add-context(1), babeltrace(1), dlopen(3), ld.so(8)09/30/2022 | LTTng 2.13.5 |