- Create an instrumentation header following the tracepoint examples.
See lttng/tracepoint.h, and examples.
- - Either compile the Tracepoint probes with the application:
+
+ There are 2 ways to compile the Tracepoint Provider with the
+ application: either statically or dynamically. Please follow
+ carefully:
+
+ 1.1) Compile the Tracepoint provider with the application, either
+ directly or through a static library (.a):
+ - Into exactly one object of your application: define
+ "TRACEPOINT_DEFINE" and include the tracepoint provider.
- Use "-I." for the compilation unit containing the tracepoint
provider include (e.g. tp.c).
- Link application with "-ldl -llttng-ust".
+ - Include the tracepoint provider header into all C files using
+ the provider.
- Example:
tests/hello/ hello.c tp.c ust_tests_hello.h Makefile.example
- - Or compile the Tracepoint probes separately from the application,
- using dynamic linking:
+
+ 2) Compile the Tracepoint Provider separately from the application,
+ using dynamic linking:
+ - Into exactly one object of your application: define
+ "TRACEPOINT_DEFINE" _and_ also define
+ "TRACEPOINT_PROBE_DYNAMIC_LINKAGE", then include the tracepoint
+ provider header.
+ - Include the tracepoint provider header into all instrumented C
+ files that use the provider.
- Compile the tracepoint provider with "-I.".
- Link the tracepoint provider with "-llttng-ust".
- Link application with "-ldl".
needed.
- Example:
- tests/demo/ demo.c tp*.c ust_tests_demo*.h demo-trace
+
- Note about dlopen() usage: due to locking side-effects due to the
way libc lazily resolves Thread-Local Storage (TLS) symbols when a
library is dlopen'd, linking the tracepoint probe or liblttng-ust
const char *name;
int state;
struct tracepoint_probe *probes;
+ int *tracepoint_provider_ref;
};
#endif /* _LTTNG_TRACEPOINT_TYPES_H */
#ifdef TRACEPOINT_DEFINE
+/*
+ * When TRACEPOINT_PROBE_DYNAMIC_LINKAGE is defined, we do not emit a
+ * unresolved symbol that requires the provider to be linked in. When
+ * TRACEPOINT_PROBE_DYNAMIC_LINKAGE is not defined, we emit an
+ * unresolved symbol that depends on having the provider linked in,
+ * otherwise the linker complains. This deals with use of static
+ * libraries, ensuring that the linker does not remove the provider
+ * object from the executable.
+ */
+#ifdef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
+#define _TRACEPOINT_UNDEFINED_REF(provider)
+#else /* TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
+#define _TRACEPOINT_UNDEFINED_REF(provider) \
+ &__tracepoint_provider_##provider,
+#endif /* TRACEPOINT_PROBE_DYNAMIC_LINKAGE */
+
/*
* Note: to allow PIC code, we need to allow the linker to update the pointers
* in the __tracepoints_ptrs section.
* Therefore, this section is _not_ const (read-only).
*/
#define _DEFINE_TRACEPOINT(provider, name) \
+ extern int __tracepoint_provider_##provider; \
static const char __tp_strtab_##provider##___##name[] \
__attribute__((section("__tracepoints_strings"))) = \
#provider ":" #name; \
struct tracepoint __tracepoint_##provider##___##name \
__attribute__((section("__tracepoints"))) = \
- { __tp_strtab_##provider##___##name, 0, NULL }; \
+ { __tp_strtab_##provider##___##name, 0, NULL, _TRACEPOINT_UNDEFINED_REF(provider) }; \
static struct tracepoint * __tracepoint_ptr_##provider##___##name \
__attribute__((used, section("__tracepoints_ptrs"))) = \
&__tracepoint_##provider##___##name;
* Stage 9 of tracepoint event generation.
*
* Register/unregister probes at module load/unload.
+ *
+ * Generate the constructor as an externally visible symbol for use when
+ * linking the probe statically.
*/
/* Reset all macros within TRACEPOINT_EVENT */
#include <lttng/ust-tracepoint-event-reset.h>
-
static void __attribute__((constructor))
_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
{
{
ltt_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
}
+
+int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
#include <stdlib.h>
#define TRACEPOINT_DEFINE
+#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#include "ust_tests_demo.h"
#include "ust_tests_demo2.h"
#include "ust_tests_demo3.h"