X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=include%2Flttng%2Ftracepoint.h;h=0b77d5512e24fe14fbda11d196a880d78855f223;hb=8041f6416269020f2213ff6be584610c53986c32;hp=268271c48c933fe8be2f1df6f5c4a8d5b8d81c91;hpb=4849bc7a9e250ce47d7a3deb0d2327cc4b50422f;p=lttng-ust.git diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h index 268271c4..0b77d551 100644 --- a/include/lttng/tracepoint.h +++ b/include/lttng/tracepoint.h @@ -4,17 +4,22 @@ * Copyright (C) 2011-2012 Mathieu Desnoyers */ -#ifndef _LTTNG_TRACEPOINT_H -#define _LTTNG_TRACEPOINT_H +#ifndef _LTTNG_UST_TRACEPOINT_H +#define _LTTNG_UST_TRACEPOINT_H #include #include #include #include +#include +#include +#include + #include #include #include /* for dlopen */ #include /* for memset */ +#include #include /* for sdt */ #include @@ -182,7 +187,8 @@ extern "C" { * address. */ #define LTTNG_UST__DECLARE_TRACEPOINT(_provider, _name, ...) \ -extern struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name; \ +extern struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name \ + LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY; \ static inline \ void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__VA_ARGS__)) \ __attribute__((always_inline, unused)) lttng_ust_notrace; \ @@ -191,10 +197,10 @@ void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__ { \ struct lttng_ust_tracepoint_probe *__tp_probe; \ \ - if (caa_unlikely(!TP_RCU_LINK_TEST())) \ + if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \ return; \ - tp_rcu_read_lock(); \ - __tp_probe = tp_rcu_dereference(lttng_ust_tracepoint_##_provider##___##_name.probes); \ + lttng_ust_tp_rcu_read_lock(); \ + __tp_probe = lttng_ust_tp_rcu_dereference(lttng_ust_tracepoint_##_provider##___##_name.probes); \ if (caa_unlikely(!__tp_probe)) \ goto end; \ do { \ @@ -205,7 +211,7 @@ void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__ (LTTNG_UST__TP_ARGS_DATA_VAR(__VA_ARGS__)); \ } while ((++__tp_probe)->func); \ end: \ - tp_rcu_read_unlock(); \ + lttng_ust_tp_rcu_read_unlock(); \ } \ static inline \ void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \ @@ -215,7 +221,7 @@ static inline \ void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \ void (*func)(void), void *data) \ { \ - lttng_ust_tracepoint_probe_register(provider_name, event_name, func, data, \ + lttng_ust_tracepoint_provider_register(provider_name, event_name, func, data, \ lttng_ust_tracepoint_##_provider##___##_name.signature); \ } \ static inline \ @@ -226,14 +232,27 @@ static inline \ void lttng_ust_tracepoint_unregister_##_provider##___##_name(char *provider_name, char *event_name, \ void (*func)(void), void *data) \ { \ - lttng_ust_tracepoint_probe_unregister(provider_name, event_name, func, data); \ + lttng_ust_tracepoint_provider_unregister(provider_name, event_name, func, data); \ } -extern int lttng_ust_tracepoint_probe_register(const char *provider_name, const char *event_name, +/* + * Registration of tracepoint provider probe functions with + * lttng_ust_tracepoint_provider_register, unregistration with + * lttng_ust_tracepoint_provider_unregister. + */ +int lttng_ust_tracepoint_provider_register(const char *provider_name, const char *event_name, void (*func)(void), void *data, const char *signature); -extern int lttng_ust_tracepoint_probe_unregister(const char *provider_name, const char *event_name, +int lttng_ust_tracepoint_provider_unregister(const char *provider_name, const char *event_name, void (*func)(void), void *data); +/* + * Registration of tracepoint instrumentation modules with lttng_ust_tracepoint_module_register, + * unregistration with lttng_ust_tracepoint_module_unregister. + */ +int lttng_ust_tracepoint_module_register(struct lttng_ust_tracepoint * const *tracepoints_start, + int tracepoints_count); +int lttng_ust_tracepoint_module_unregister(struct lttng_ust_tracepoint * const *tracepoints_start); + /* * tracepoint dynamic linkage handling (callbacks). Hidden visibility: * shared across objects in a module/main executable. @@ -251,9 +270,9 @@ struct lttng_ust_tracepoint_dlopen { void *liblttngust_handle; - int (*lttng_ust_tracepoint_register_lib)(struct lttng_ust_tracepoint * const *tracepoints_start, + int (*lttng_ust_tracepoint_module_register)(struct lttng_ust_tracepoint * const *tracepoints_start, int tracepoints_count); - int (*lttng_ust_tracepoint_unregister_lib)(struct lttng_ust_tracepoint * const *tracepoints_start); + int (*lttng_ust_tracepoint_module_unregister)(struct lttng_ust_tracepoint * const *tracepoints_start); void (*rcu_read_lock_sym)(void); void (*rcu_read_unlock_sym)(void); void *(*rcu_dereference_sym)(void *p); @@ -350,17 +369,17 @@ lttng_ust_tracepoint__init_urcu_sym(void) lttng_ust_tracepoint_dlopen_ptr->rcu_read_lock_sym = URCU_FORCE_CAST(void (*)(void), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "tp_rcu_read_lock")); + "lttng_ust_tp_rcu_read_lock")); if (!lttng_ust_tracepoint_dlopen_ptr->rcu_read_unlock_sym) lttng_ust_tracepoint_dlopen_ptr->rcu_read_unlock_sym = URCU_FORCE_CAST(void (*)(void), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "tp_rcu_read_unlock")); + "lttng_ust_tp_rcu_read_unlock")); if (!lttng_ust_tracepoint_dlopen_ptr->rcu_dereference_sym) lttng_ust_tracepoint_dlopen_ptr->rcu_dereference_sym = URCU_FORCE_CAST(void *(*)(void *p), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "tp_rcu_dereference_sym")); + "lttng_ust_tp_rcu_dereference_sym")); } #else static inline void @@ -372,6 +391,40 @@ lttng_ust_tracepoint__init_urcu_sym(void) } #endif +/* + * Use getenv() directly and bypass lttng-ust helper functions + * because we may not have access to lttng-ust shared libraries. + */ +#ifdef LTTNG_UST_DEBUG +static inline +bool lttng_ust_tracepoint_logging_debug_enabled(void) +{ + return true; +} +#else /* #ifdef LTTNG_UST_DEBUG */ +static inline +bool lttng_ust_tracepoint_logging_debug_enabled(void) +{ + return getenv("LTTNG_UST_DEBUG"); +} +#endif /* #ifdef LTTNG_UST_DEBUG */ + +#define LTTNG_UST_TRACEPOINT_THIS_IP \ + ({ __label__ here; here: &&here; }) + +static void +lttng_ust_tracepoints_print_disabled_message(void) +{ + if (!lttng_ust_tracepoint_logging_debug_enabled()) + return; + fprintf(stderr, "lttng-ust-tracepoint [%ld]: dlopen() failed to find '%s', tracepoints in this binary won't be registered. " + "(at addr=%p in %s() at " __FILE__ ":" lttng_ust_stringify(__LINE__) ")\n", + (long) getpid(), + LTTNG_UST_TRACEPOINT_LIB_SONAME, + LTTNG_UST_TRACEPOINT_THIS_IP, + __func__); +} + static void lttng_ust__tracepoints__init(void) lttng_ust_notrace __attribute__((constructor)); @@ -390,8 +443,10 @@ lttng_ust__tracepoints__init(void) if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle = dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL); - if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) + if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) { + lttng_ust_tracepoints_print_disabled_message(); return; + } lttng_ust_tracepoint__init_urcu_sym(); } @@ -482,7 +537,8 @@ extern struct lttng_ust_tracepoint * const __stop_lttng_ust_tracepoints_ptrs[] #define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args) \ lttng_ust_tracepoint_validate_name_len(_provider, _name); \ - extern int lttng_ust_tracepoint_provider_##_provider; \ + extern int lttng_ust_tracepoint_provider_##_provider \ + LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY; \ static const char lttng_ust_tp_provider_strtab_##_provider##___##_name[] \ __attribute__((section("lttng_ust_tracepoints_strings"))) = \ #_provider; \ @@ -490,7 +546,8 @@ extern struct lttng_ust_tracepoint * const __stop_lttng_ust_tracepoints_ptrs[] __attribute__((section("lttng_ust_tracepoints_strings"))) = \ #_name; \ struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name \ - __attribute__((section("lttng_ust_tracepoints"))) = { \ + __attribute__((section("lttng_ust_tracepoints"))) \ + LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY = { \ sizeof(struct lttng_ust_tracepoint), \ lttng_ust_tp_provider_strtab_##_provider##___##_name, \ lttng_ust_tp_name_strtab_##_provider##___##_name, \ @@ -518,18 +575,20 @@ lttng_ust__tracepoints__ptrs_init(void) if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle = dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL); - if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) + if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) { + lttng_ust_tracepoints_print_disabled_message(); return; + } if (!lttng_ust_tracepoint_destructors_syms_ptr) lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_register_lib = + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register = URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *, int), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "lttng_ust_tracepoint_register_lib")); - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_unregister_lib = + "lttng_ust_tracepoint_module_register")); + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister = URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "lttng_ust_tracepoint_unregister_lib")); + "lttng_ust_tracepoint_module_unregister")); lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors = URCU_FORCE_CAST(void (*)(void), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, @@ -539,8 +598,8 @@ lttng_ust__tracepoints__ptrs_init(void) dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, "lttng_ust_tp_get_destructors_state")); lttng_ust_tracepoint__init_urcu_sym(); - if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_register_lib) { - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_register_lib(__start_lttng_ust_tracepoints_ptrs, + if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register) { + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register(__start_lttng_ust_tracepoints_ptrs, __stop_lttng_ust_tracepoints_ptrs - __start_lttng_ust_tracepoints_ptrs); } @@ -560,8 +619,8 @@ lttng_ust__tracepoints__ptrs_destroy(void) lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; if (!lttng_ust_tracepoint_destructors_syms_ptr) lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; - if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_unregister_lib) - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_unregister_lib(__start_lttng_ust_tracepoints_ptrs); + if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister) + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister(__start_lttng_ust_tracepoints_ptrs); if (lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state() @@ -586,17 +645,49 @@ lttng_ust__tracepoints__ptrs_destroy(void) #define do_tracepoint lttng_ust_do_tracepoint #define tracepoint_enabled lttng_ust_tracepoint_enabled #define TP_ARGS LTTNG_UST_TP_ARGS -#define TP_FIELDS LTTNG_UST_TP_FIELDS #endif /* #if LTTNG_UST_COMPAT_API(0) */ #ifdef __cplusplus } #endif -#endif /* _LTTNG_TRACEPOINT_H */ +#endif /* _LTTNG_UST_TRACEPOINT_H */ /* The following declarations must be outside re-inclusion protection. */ +/* + * LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION: Define this before including + * a tracepoint instrumentation header to hide symbols associated with + * tracepoint module instrumentation. This is useful if all compile + * units using the lttng_ust_tracepoint(), + * lttng_ust_tracepoint_enabled() and lttng_ust_do_tracepoint() macros + * is within the same module as the compile unit including the + * tracepoint header after defining LTTNG_UST_TRACEPOINT_DEFINE. + */ + +#undef LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY +#ifdef LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION +#define LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY __attribute__((visibility("hidden"))) +#else +#define LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY __attribute__((visibility("default"))) +#endif + +/* + * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before + * including a tracepoint instrumentation header to hide symbols + * associated with the tracepoint provider. This is useful if the + * tracepoint definition (including the header after defining + * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider + * (including the header after defining + * LTTNG_UST_TRACEPOINT_CREATE_PROBES). + */ +#undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY +#ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION +#define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden"))) +#else +#define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default"))) +#endif + #ifndef LTTNG_UST_TRACEPOINT_ENUM /* @@ -610,18 +701,18 @@ lttng_ust__tracepoints__ptrs_destroy(void) * * LTTNG_UST_TRACEPOINT_ENUM(someproject_component, enumname, * LTTNG_UST_TP_ENUM_VALUES( - * ctf_enum_value("even", 0) - * ctf_enum_value("uneven", 1) - * ctf_enum_range("twoto4", 2, 4) - * ctf_enum_value("five", 5) + * lttng_ust_field_enum_value("even", 0) + * lttng_ust_field_enum_value("uneven", 1) + * lttng_ust_field_enum_range("twoto4", 2, 4) + * lttng_ust_field_enum_value("five", 5) * ) * ) * * Where "someproject_component" is the name of the component this enumeration * belongs to and "enumname" identifies this enumeration. Inside the * LTTNG_UST_TP_ENUM_VALUES macro is the actual mapping. Each string value can map - * to either a single value with ctf_enum_value or a range of values - * with ctf_enum_range. + * to either a single value with lttng_ust_field_enum_value or a range of values + * with lttng_ust_field_enum_range. * * Enumeration ranges may overlap, but the behavior is implementation-defined, * each trace reader will handle overlapping as it wishes. @@ -629,7 +720,7 @@ lttng_ust__tracepoints__ptrs_destroy(void) * That enumeration can then be used in a field inside the TP_FIELD macro using * the following line: * - * ctf_enum(someproject_component, enumname, enumtype, enumfield, enumval) + * lttng_ust_field_enum(someproject_component, enumname, enumtype, enumfield, enumval) * * Where "someproject_component" and "enumname" match those in the * LTTNG_UST_TRACEPOINT_ENUM, "enumtype" is a signed or unsigned integer type @@ -663,24 +754,24 @@ lttng_ust__tracepoints__ptrs_destroy(void) * * LTTNG_UST_TP_FIELDS( * * Integer, printed in base 10 * - * ctf_integer(int, field_a, arg0) + * lttng_ust_field_integer(int, field_a, arg0) * * * Integer, printed with 0x base 16 * - * ctf_integer_hex(unsigned long, field_d, arg1) + * lttng_ust_field_integer_hex(unsigned long, field_d, arg1) * * * Enumeration * - * ctf_enum(someproject_component, enum_name, int, field_e, arg0) + * lttng_ust_field_enum(someproject_component, enum_name, int, field_e, arg0) * * * Array Sequence, printed as UTF8-encoded array of bytes * - * ctf_array_text(char, field_b, string, FIXED_LEN) - * ctf_sequence_text(char, field_c, string, size_t, strlen) + * lttng_ust_field_array_text(char, field_b, string, FIXED_LEN) + * lttng_ust_field_sequence_text(char, field_c, string, size_t, strlen) * * * String, printed as UTF8-encoded string * - * ctf_string(field_e, string) + * lttng_ust_field_string(field_e, string) * * * Array sequence of signed integer values * - * ctf_array(long, field_f, arg4, FIXED_LEN4) - * ctf_sequence(long, field_g, arg4, size_t, arg4_len) + * lttng_ust_field_array(long, field_f, arg4, FIXED_LEN4) + * lttng_ust_field_sequence(long, field_g, arg4, size_t, arg4_len) * ) * ) * @@ -735,14 +826,17 @@ lttng_ust__tracepoints__ptrs_destroy(void) #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(provider, name, args, fields) -#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(provider, _template, name, args) \ +#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(template_provider, template_name, provider, name, args) \ LTTNG_UST__DECLARE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) \ LTTNG_UST__DEFINE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) #if LTTNG_UST_COMPAT_API(0) #define TRACEPOINT_EVENT LTTNG_UST_TRACEPOINT_EVENT #define TRACEPOINT_EVENT_CLASS LTTNG_UST_TRACEPOINT_EVENT_CLASS -#define TRACEPOINT_EVENT_INSTANCE LTTNG_UST_TRACEPOINT_EVENT_INSTANCE +#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, args) \ + LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, \ + _provider, _name, LTTNG_UST__TP_PARAMS(args)) + #endif /* #if LTTNG_UST_COMPAT_API(0) */ #endif /* #ifndef LTTNG_UST_TRACEPOINT_EVENT */