Create the tracepoint provider object file:
[role="term"]
---------------
-cc -c -I. tp.c
---------------
+----
+$ cc -c -I. tp.c
+----
NOTE: Although an application instrumented with LTTng-UST tracepoints
can be compiled with a C++ compiler, tracepoint probes should be
tracepoint provider object files, as a static library:
[role="term"]
----------------
-ar rc tp.a tp.o
----------------
+----
+$ ar rc tp.a tp.o
+----
Using a static library does have the advantage of centralising the
tracepoint providers objects so they can be shared between multiple
(`libc` on a BSD system):
[role="term"]
--------------------------------------
-cc -o app tp.o app.o -llttng-ust -ldl
--------------------------------------
+----
+$ cc -o app tp.o app.o -llttng-ust -ldl
+----
[[build-dynamic]]
nloption:-fpic option:
[role="term"]
---------------------
-cc -c -fpic -I. tp.c
---------------------
+----
+$ cc -c -fpic -I. tp.c
+----
It is then linked as a shared library like this:
[role="term"]
--------------------------------------------------------
-cc -shared -Wl,--no-as-needed -o tp.so tp.o -llttng-ust
--------------------------------------------------------
+----
+$ cc -shared -Wl,--no-as-needed -o tp.so tp.o -llttng-ust
+----
This tracepoint provider shared object isn't linked with the user
application: it must be loaded manually. This is why the application is
libdl:
[role="term"]
---------------------------------
-cc -o app app.o tp-define.o -ldl
---------------------------------
+----
+$ cc -o app app.o tp-define.o -ldl
+----
There are two ways to dynamically load the tracepoint provider shared
object:
+
This event has no fields.
-`lttng_ust_statedump:soinfo`::
- Emitted when information about a currently loaded shared object is
- found.
+`lttng_ust_statedump:bin_info`::
+ Emitted when information about a currently loaded executable or
+ shared object is found.
+
Fields:
+
[options="header"]
-|==============================================================
+|==================================================================
| Field name | Description
-| `baddr` | Base address of loaded library
-| `memsz` | Size of loaded library in memory
-| `sopath` | Path to loaded library file
-|==============================================================
+| `baddr` | Base address of loaded executable
+| `memsz` | Size of loaded executable in memory
+| `path` | Path to loaded executable file
+| `is_pic` | Whether the executable is
+ position-independent code
+|==================================================================
`lttng_ust_statedump:build_id`::
Emitted when a build ID is found in a currently loaded shared
sections. The <<build-static,static linking>> method is chosen here
to link the application with the tracepoint provider.
-Let's start with the tracepoint provider header file (`tp.h`):
+You can compile the source files and link them together statically
+like this:
+
+[role="term"]
+----
+$ cc -c -I. tp.c
+$ cc -c app.c
+$ cc -o app tp.o app.o -llttng-ust -ldl
+----
+
+Using the man:lttng(1) tool, create an LTTng tracing session, enable
+all the events of this tracepoint provider, and start tracing:
+
+[role="term"]
+----
+$ lttng create my-session
+$ lttng enable-event --userspace 'my_provider:*'
+$ lttng start
+----
+
+You may also enable specific events:
+
+[role="term"]
+----
+$ lttng enable-event --userspace my_provider:big_event
+$ lttng enable-event --userspace my_provider:event_instance2
+----
+
+Run the application:
+
+[role="term"]
+----
+$ ./app some arguments
+----
+
+Stop the current tracing session and inspect the recorded events:
+
+[role="term"]
+----
+$ lttng stop
+$ lttng view
+----
+
+
+Tracepoint provider header file
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+`tp.h`:
------------------------------------------------------------------------
#undef TRACEPOINT_PROVIDER
#include <lttng/tracepoint-event.h>
------------------------------------------------------------------------
-The tracepoint provider source file looks like this (`tp.c`):
+
+Tracepoint provider source file
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+`tp.c`:
------------------------------------------------------------------------
#define TRACEPOINT_CREATE_PROBES
#include "tp.h"
------------------------------------------------------------------------
-The included `app.h`, where the application structure resides, is:
+
+Application header file
+~~~~~~~~~~~~~~~~~~~~~~~
+`app.h`:
------------------------------------------------------------------------
#ifndef _APP_H
#endif /* _APP_H */
------------------------------------------------------------------------
-Finally, the application itself, `app.c`, using the defined tracepoints:
+
+Application source file
+~~~~~~~~~~~~~~~~~~~~~~~
+`app.c`:
------------------------------------------------------------------------
#include <stdlib.h>
}
------------------------------------------------------------------------
-Here are the steps to compile the source files and link them together
-statically:
-
-[role="term"]
--------------------------------------
-cc -c -I. tp.c
-cc -c app.c
-cc -o app tp.o app.o -llttng-ust -ldl
--------------------------------------
-
ENVIRONMENT VARIABLES
---------------------
-`LTTNG_UST_DEBUG`::
- Activate `liblttng-ust` debug and error output.
-
-`LTTNG_UST_REGISTER_TIMEOUT`::
- Specify how long the applications should wait for the
- _registration done_ session daemon command before proceeding to
- execute the main program (milliseconds).
+`LTTNG_HOME`::
+ Alternative user's home directory. This variable is useful when the
+ user running the instrumented application has a non-writable home
+ directory.
+
-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.
+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_WITHOUT_BADDR_STATEDUMP`::
- Prevent `liblttng-ust` from performing a base address state dump
- (see the <<state-dump,LTTng-UST state dump>> section above).
+`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
+ https://github.com/lttng/lttng-ust/tree/master/doc/examples/clock-override[`examples/clock-override`].
+
+`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
documentation under
https://github.com/lttng/lttng-ust/tree/master/doc/examples/getcpu-override[`examples/getcpu-override`].
-`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
- https://github.com/lttng/lttng-ust/tree/master/doc/examples/clock-override[`examples/clock-override`].
+`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: {lttng_ust_register_timeout}.
+
+`LTTNG_UST_WITHOUT_BADDR_STATEDUMP`::
+ If set, prevents `liblttng-ust` from performing a base address state
+ dump (see the <<state-dump,LTTng-UST state dump>> section above).
include::common-footer.txt[]