From 0a42beb627df1b9ea5cce4b1908e8a9cefaa1631 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 27 Jul 2011 14:10:36 -0400 Subject: [PATCH] TRACEPOINT_EVENT API Signed-off-by: Mathieu Desnoyers --- include/Makefile.am | 6 +- .../ust/lttng-events.h | 16 +- include/ust/lttng-tracepoint-event-reset.h | 37 ++ include/ust/lttng-tracepoint-event.h | 440 ++++++++++++++++++ include/ust/lttng-ust-abi.h | 2 + include/ust/probe.h | 96 ---- ...{tracepoint_event.h => tracepoint-event.h} | 2 +- include/ust/tracepoint.h | 102 ++-- 8 files changed, 539 insertions(+), 162 deletions(-) rename libust/ltt-events.h => include/ust/lttng-events.h (96%) create mode 100644 include/ust/lttng-tracepoint-event-reset.h create mode 100644 include/ust/lttng-tracepoint-event.h delete mode 100644 include/ust/probe.h rename include/ust/{tracepoint_event.h => tracepoint-event.h} (98%) diff --git a/include/Makefile.am b/include/Makefile.am index 1bd30320..93853642 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,8 +1,10 @@ nobase_include_HEADERS = \ ust/marker.h \ ust/tracepoint.h \ - ust/tracepoint_event.h \ - ust/probe.h \ + ust/tracepoint-event.h \ + ust/lttng-tracepoint-event.h \ + ust/lttng-tracepoint-event-reset.h \ + ust/lttng-events.h \ ust/version.h \ ust/lttng-ust-abi.h \ ust/ringbuffer-abi.h diff --git a/libust/ltt-events.h b/include/ust/lttng-events.h similarity index 96% rename from libust/ltt-events.h rename to include/ust/lttng-events.h index a66f5840..743ff161 100644 --- a/libust/ltt-events.h +++ b/include/ust/lttng-events.h @@ -1,8 +1,8 @@ -#ifndef _LTT_EVENTS_H -#define _LTT_EVENTS_H +#ifndef _UST_LTTNG_EVENTS_H +#define _UST_LTTNG_EVENTS_H /* - * ltt-events.h + * ust/lttng-events.h * * Copyright 2010 (c) - Mathieu Desnoyers * @@ -201,18 +201,19 @@ struct ltt_channel { struct lttng_ctx *ctx; /* Event ID management */ struct ltt_session *session; - struct file *file; /* File associated to channel */ + int objd; /* Object associated to channel */ unsigned int free_event_id; /* Next event ID to allocate */ struct cds_list_head list; /* Channel list */ struct ltt_channel_ops *ops; int header_type; /* 0: unset, 1: compact, 2: large */ + int shmid; /* shared memory ID */ int metadata_dumped:1; }; struct ltt_session { int active; /* Is trace session active ? */ int been_active; /* Has trace session been active ? */ - struct file *file; /* File associated to session */ + int objd; /* Object associated to session */ struct ltt_channel *metadata; /* Metadata channel */ struct cds_list_head chan; /* Channel list head */ struct cds_list_head events; /* Event list head */ @@ -238,8 +239,7 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval, - int *shmid); + unsigned int read_timer_interval); struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, int overwrite, void *buf_addr, size_t subbuf_size, size_t num_subbuf, @@ -276,4 +276,4 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); //extern const struct file_operations lttng_tracepoint_list_fops; -#endif /* _LTT_EVENTS_H */ +#endif /* _UST_LTTNG_EVENTS_H */ diff --git a/include/ust/lttng-tracepoint-event-reset.h b/include/ust/lttng-tracepoint-event-reset.h new file mode 100644 index 00000000..b42a794a --- /dev/null +++ b/include/ust/lttng-tracepoint-event-reset.h @@ -0,0 +1,37 @@ +/* + * lttng-tracepoint-events-reset.h + * + * Copyright (C) 2010-2011 Mathieu Desnoyers + * + * Dual LGPL v2.1/GPL v2 license. + */ + +/* Reset macros used within TRACE_EVENT to "nothing" */ + +#undef ctf_integer_ext +#define ctf_integer_ext(_type, _item, _src, _byte_order, _base) + +#undef ctf_array_encoded +#define ctf_array_encoded(_type, _item, _src, _length, _encoding) + +#undef ctf_sequence_encoded +#define ctf_sequence_encoded(_type, _item, _src, _length_type, \ + _src_length, _encoding) + +#undef ctf_string +#define ctf_string(_item, _src) + +#undef TP_PROTO +#define TP_PROTO(args...) + +#undef TP_ARGS +#define TP_ARGS(args...) + +#undef TP_FIELDS +#define TP_FIELDS(args...) + +#undef TRACEPOINT_EVENT_CLASS +#define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) + +#undef TRACEPOINT_EVENT_INSTANCE +#define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) diff --git a/include/ust/lttng-tracepoint-event.h b/include/ust/lttng-tracepoint-event.h new file mode 100644 index 00000000..10b2d23f --- /dev/null +++ b/include/ust/lttng-tracepoint-event.h @@ -0,0 +1,440 @@ +/* + * Copyright (C) 2009 Steven Rostedt + * Copyright (C) 2011 Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +/* + * Macro declarations used for all stages. + */ + +#undef ctf_integer +#define ctf_integer(_type, _item, _src) \ + ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10) + +#undef ctf_integer_hex +#define ctf_integer_hex(_type, _item, _src) \ + ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 16) + +#undef ctf_integer_network +#define ctf_integer_network(_type, _item, _src) \ + ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 10) + +#undef ctf_integer_network_hex +#define ctf_integer_network_hex(_type, _item, _src) \ + ctf_integer_ext(_type, _item, _src, BIG_ENDIAN, 16) + +#undef ctf_array +#define ctf_array(_type, _item, _src, _length) \ + ctf_array_encoded(_type, _item, _src, _length, none) + +#undef ctf_array_text +#define ctf_array_text(_type, _item, _src, _length) \ + ctf_array_encoded(_type, _item, _src, _length, UTF8) + +#undef ctf_sequence +#define ctf_sequence(_type, _item, _src, _length_type, _src_length) \ + ctf_sequence_encoded(_type, _item, _src, \ + _length_type, _src_length, none) + +#undef ctf_sequence_text +#define ctf_sequence_text(_type, _item, _src, _length_type, _src_length) \ + ctf_sequence_encoded(_type, _item, _src, \ + _length_type, _src_length, UTF8) + +/* ctf_string is redefined at each step */ + +/* + * TRACEPOINT_EVENT_CLASS can be used to add a generic function handlers + * for events. That is, if all events have the same parameters and just + * have distinct trace points. Each tracepoint can be defined with + * TRACEPOINT_EVENT_INSTANCE and that will map the + * TRACEPOINT_EVENT_CLASS to the tracepoint. + * + * TRACEPOINT_EVENT is a one to one mapping between tracepoint and + * template. + */ + +#undef TRACEPOINT_EVENT +#define TRACEPOINT_EVENT(name, proto, args, fields) \ + TRACEPOINT_EVENT_CLASS(name, \ + TP_PARAMS(proto), \ + TP_PARAMS(args), \ + TP_PARAMS(fields)) \ + TRACEPOINT_EVENT_INSTANCE(name, name, TP_PARAMS(proto), TP_PARAMS(args)) + +/* + * Stage 1 of the trace events. + * + * Create event field type metadata section. + * Each event produce an array of fields. + */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +/* Named field types must be defined in lttng-types.h */ + +#undef ctf_integer_ext +#define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \ + { \ + .name = #_item, \ + .type = __type_integer(_type, _byte_order, _base, none),\ + }, + +#undef ctf_array_encoded +#define ctf_array_encoded(_type, _item, _src, _length, _encoding) \ + { \ + .name = #_item, \ + .type = \ + { \ + .atype = atype_array, \ + .u.array = \ + { \ + .length = _length, \ + .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ + }, \ + }, \ + }, + +#undef ctf_sequence_encoded +#define ctf_sequence_encoded(_type, _item, _src, \ + _length_type, _src_length, _encoding) \ + { \ + .name = #_item, \ + .type = \ + { \ + .atype = atype_sequence, \ + .u.sequence = \ + { \ + .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \ + .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ + }, \ + }, \ + }, + +#undef ctf_string +#define ctf_string(_item, _src) \ + { \ + .name = #_item, \ + .type = \ + { \ + .atype = atype_string, \ + .u.basic.string.encoding = lttng_encode_UTF8, \ + }, \ + }, + +#undef TP_FIELDS +#define TP_FIELDS(args...) args /* Only one used in this phase */ + +#undef TRACEPOINT_EVENT_CLASS +#define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ + static const struct lttng_event_field __event_fields___##_name[] = { \ + _fields \ + }; + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + +/* + * Stage 2 of the trace events. + * + * Create probe callback prototypes. + */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +#undef TP_PROTO +#define TP_PROTO(args...) args + +#undef TRACEPOINT_EVENT_CLASS +#define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ +static void __event_probe__##_name(void *__data, _proto); + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + +/* + * Stage 3 of the trace events. + * + * Create an array of events. + */ + +/* Named field types must be defined in lttng-types.h */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +#undef TRACEPOINT_EVENT_INSTANCE +#define TRACEPOINT_EVENT_INSTANCE(_template, _name, _proto, _args) \ + { \ + .fields = __event_fields___##_template, \ + .name = #_name, \ + .probe_callback = (void *) &__event_probe__##_template,\ + .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ + }, + +#define TP_ID1(_token, _system) _token##_system +#define TP_ID(_token, _system) TP_ID1(_token, _system) + +static const struct lttng_event_desc TP_ID(__event_desc___, TRACE_SYSTEM)[] = { +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) +}; + +#undef TP_ID1 +#undef TP_ID + + +/* + * Stage 4 of the trace events. + * + * Create a toplevel descriptor for the whole probe. + */ + +#define TP_ID1(_token, _system) _token##_system +#define TP_ID(_token, _system) TP_ID1(_token, _system) + +/* non-const because list head will be modified when registered. */ +static struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { + .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM), + .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)), +}; + +#undef TP_ID1 +#undef TP_ID + +/* + * Stage 5 of the trace events. + * + * Create static inline function that calculates event size. + */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +/* Named field types must be defined in lttng-types.h */ + +#undef ctf_integer_ext +#define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \ + __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ + __event_len += sizeof(_type); + +#undef ctf_array_encoded +#define ctf_array_encoded(_type, _item, _src, _length) \ + __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ + __event_len += sizeof(_type) * (_length); + +#undef ctf_sequence_encoded +#define ctf_sequence_encoded(_type, _item, _src, _length_type, \ + _src_length, _encoding) \ + __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_length_type)); \ + __event_len += sizeof(_length_type); \ + __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ + __dynamic_len[__dynamic_len_idx] = (_length); \ + __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ + __dynamic_len_idx++; + +#undef ctf_string +#define ctf_string(_item, _src) \ + __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; + +#undef TP_PROTO +#define TP_PROTO(args...) args + +#undef TP_FIELDS +#define TP_FIELDS(args...) args + +#undef TRACEPOINT_EVENT_CLASS +#define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ +static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ +{ \ + size_t __event_len = 0; \ + unsigned int __dynamic_len_idx = 0; \ + \ + if (0) \ + (void) __dynamic_len_idx; /* don't warn if unused */ \ + _fields \ + return __event_len; \ +} + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + +/* + * Stage 6 of the trace events. + * + * Create static inline function that calculates event payload alignment. + */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +/* Named field types must be defined in lttng-types.h */ + +#undef ctf_integer_ext +#define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \ + __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); + +#undef ctf_array_encoded +#define ctf_array_encoded(_type, _item, _src, _length) \ + __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); + +#undef ctf_sequence_encoded +#define ctf_sequence_encoded(_type, _item, _src, _length_type, \ + _src_length, _encoding) \ + __event_align = max_t(size_t, __event_align, ltt_alignof(_length_type)); \ + __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); + +#undef ctf_string +#define ctf_string(_item, _src) + +#undef TP_PROTO +#define TP_PROTO(args...) args + +#undef TP_FIELDS +#define TP_FIELDS(args...) args + +#undef TRACEPOINT_EVENT_CLASS +#define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ +static inline size_t __event_get_align__##_name(_proto) \ +{ \ + size_t __event_align = 1; \ + _fields \ + return __event_align; \ +} + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + + +/* + * Stage 7 of the trace events. + * + * Create the probe function : call even size calculation and write event data + * into the buffer. + * + * We use both the field and assignment macros to write the fields in the order + * defined in the field declaration. The field declarations control the + * execution order, jumping to the appropriate assignment block. + */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +#undef ctf_integer_ext +#define ctf_integer_ext(_type, _item, _src, _byte_order, _base) \ + { \ + _type __tmp = (_src); \ + lib_ring_buffer_align_ctx(&ctx, ltt_alignof(__tmp)); \ + __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \ + } + +#undef ctf_array_encoded +#define ctf_array_encoded(_type, _item, _src, _length) \ + lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_type)); \ + __chan->ops->event_write(&ctx, _src, _length); + +#undef ctf_sequence_encoded +#define ctf_sequence_encoded(_type, _item, _src, _length_type, \ + _src_length, _encoding) \ + { \ + _length_type __tmpl = __dynamic_len[__dynamic_len_idx]; \ + lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_length_type)); \ + __chan->ops->event_write(&ctx, &__tmpl, sizeof(_length_type)); \ + } \ + lib_ring_buffer_align_ctx(&ctx, ltt_alignof(_type)); \ + __chan->ops->event_write(&ctx, _src, \ + sizeof(_type) * __get_sequence_len(dest)); + +#undef ctf_string +#define ctf_string(_item, _src) \ + tp_memcpy(dest, _src, __get_sequence_len(dest)) + +/* Beware: this get len actually consumes the len value */ +#undef __get_sequence_len +#define __get_sequence_len(field) __dynamic_len[__dynamic_len_idx++] + +#undef TP_PROTO +#define TP_PROTO(args...) args + +#undef TP_ARGS +#define TP_ARGS(args...) args + +#undef TP_FIELDS +#define TP_FIELDS(args...) args + +#undef TRACEPOINT_EVENT_CLASS +#define TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ +static void __event_probe__##_name(void *__data, _proto) \ +{ \ + struct ltt_event *__event = __data; \ + struct ltt_channel *__chan = __event->chan; \ + struct lib_ring_buffer_ctx ctx; \ + size_t __event_len, __event_align; \ + size_t __dynamic_len_idx = 0; \ + size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ + int __ret; \ + \ + if (0) \ + (void) __dynamic_len_idx; /* don't warn if unused */ \ + if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ + return; \ + if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ + return; \ + if (unlikely(!ACCESS_ONCE(__event->enabled))) \ + return; \ + __event_len = __event_get_size__##_name(__dynamic_len, _args); \ + __event_align = __event_get_align__##_name(_args); \ + lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \ + __event_align, -1); \ + __ret = __chan->ops->event_reserve(&ctx, __event->id); \ + if (__ret < 0) \ + return; \ + _fields \ + __chan->ops->event_commit(&ctx); \ +} + +#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + +/* + * Stage 8 of the trace events. + * + * Register/unregister probes at module load/unload. + */ + +/* Reset all macros within TRACE_EVENT */ +#include "lttng-tracepoint-events-reset.h" + +#define TP_ID1(_token, _system) _token##_system +#define TP_ID(_token, _system) TP_ID1(_token, _system) + +static void __attribute__((constructor)) +TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) +{ + int ret; + + ret = ltt_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); + assert(!ret); +} + +static void __attribute__((destructor)) +TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) +{ + ltt_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); +} + +#undef TP_ID1 +#undef TP_ID diff --git a/include/ust/lttng-ust-abi.h b/include/ust/lttng-ust-abi.h index ff76a710..f8ba13e5 100644 --- a/include/ust/lttng-ust-abi.h +++ b/include/ust/lttng-ust-abi.h @@ -11,6 +11,8 @@ * Dual LGPL v2.1/GPL v2 license. */ +#include + #define LTTNG_UST_SYM_NAME_LEN 128 enum lttng_ust_instrumentation { diff --git a/include/ust/probe.h b/include/ust/probe.h deleted file mode 100644 index fe27da2b..00000000 --- a/include/ust/probe.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2009 Steven Rostedt - * Copyright (C) 2010 Nils Carlson - * Copyright (C) 2011 Mathieu Desnoyers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * This whole file is currently a dummy. - */ - -#include - -#undef TRACEPOINT_EVENT -#define TRACEPOINT_EVENT(name, proto, args, fields) \ - TRACEPOINT_EVENT_CLASS(name, \ - TP_PARAMS(proto), \ - TP_PARAMS(args), \ - TP_PARAMS(fields)); \ - TRACEPOINT_EVENT_INSTANCE(name, name, TP_PARAMS(proto), \ - TP_PARAMS(args)); - -#undef TRACEPOINT_EVENT_NOARGS -#define TRACEPOINT_EVENT_NOARGS(name, fields) \ - TRACEPOINT_EVENT_CLASS_NOARGS(name, \ - TP_PARAMS(fields)); \ - TRACEPOINT_EVENT_INSTANCE_NOARGS(name, name); - -#undef tp_field -#define tp_field(type, item, src) type item; - -#undef TP_FIELDS -#define TP_FIELDS(args...) args - -#undef TRACEPOINT_EVENT_INSTANCE -#define TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) - -#undef TRACEPOINT_EVENT_INSTANCE_NOARGS -#define TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) - -#undef TRACEPOINT_EVENT_CLASS -#define TRACEPOINT_EVENT_CLASS(name, proto, args, fields) \ - struct trace_raw_##name { \ - fields \ - }; \ - static void trace_printf_##name(void *dummy, proto) \ - { \ - } \ - struct trace_event __event_##name = { \ - __tpstrtab_##name, \ - }; \ - static struct trace_event * const __event_ptrs_##name \ - __attribute__((used, section("__trace_events_ptrs"))) = \ - &__event_##name; \ - \ - static void __attribute__((constructor)) init_##name() \ - { \ - void *dummy = NULL; \ - __register_tracepoint(name, trace_printf_##name, dummy);\ - } - -#undef TRACEPOINT_EVENT_CLASS_NOARGS -#define TRACEPOINT_EVENT_CLASS_NOARGS(name, fields) \ - struct trace_raw_##name { \ - fields \ - }; \ - static void trace_printf_##name(void *dummy) \ - { \ - } \ - struct trace_event __event_##name = { \ - __tpstrtab_##name, \ - }; \ - static struct trace_event * const __event_ptrs_##name \ - __attribute__((used, section("__trace_events_ptrs"))) = \ - &__event_##name; \ - \ - static void __attribute__((constructor)) init_##name() \ - { \ - void *dummy = NULL; \ - __register_tracepoint(name, trace_printf_##name, dummy);\ - } - -#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) diff --git a/include/ust/tracepoint_event.h b/include/ust/tracepoint-event.h similarity index 98% rename from include/ust/tracepoint_event.h rename to include/ust/tracepoint-event.h index 12e8e497..d1d5069b 100644 --- a/include/ust/tracepoint_event.h +++ b/include/ust/tracepoint-event.h @@ -82,7 +82,7 @@ #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #ifndef CONFIG_NO_EVENT_TRACING -#include +#include #endif #undef TRACEPOINT_EVENT diff --git a/include/ust/tracepoint.h b/include/ust/tracepoint.h index 3d61f728..18ee28b0 100644 --- a/include/ust/tracepoint.h +++ b/include/ust/tracepoint.h @@ -199,17 +199,48 @@ int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start); /* * For use with the TRACEPOINT_EVENT macro: * - * We define a tracepoint, its arguments, its printf format - * and its 'fast binary record' layout. + * We define a tracepoint, its arguments, and its 'fast binary record' + * layout. * - * Firstly, name your tracepoint via TRACEPOINT_EVENT(name : the - * 'subsystem_event' notation is fine. + * Firstly, name your tracepoint via TRACEPOINT_EVENT(name, * - * Think about this whole construct as the - * 'trace_sched_switch() function' from now on. + * The "name" MUST follow these rules to ensure no namespace clash + * occurs: * + * For projects (applications and libraries) for which an entity + * specific to the project controls the source code and thus its + * tracepoints (typically with a scope larger than a single company): * - * TRACEPOINT_EVENT(sched_switch, + * either: + * project_component_event + * or: + * project_event + * + * Where "project" is the name of the project, + * "component" is the name of the project component where the + * tracepoint is located (optional), + * "event" is the name of the tracepoint event. + * + * For projects issued from a single company wishing to advertise that + * the company controls the source code and thus the tracepoints, the + * "com_" prefix should be used: + * + * either: + * com_company_project_component_event + * or: + * com_company_project_event + * + * Where "company" is the name of the company, + * "project" is the name of the project, + * "component" is the name of the project component where the + * tracepoint is located (optional), + * "event" is the name of the tracepoint event. + * + * + * As an example, let's consider a user-space application "someproject" + * that would have an internal thread scheduler: + * + * TRACEPOINT_EVENT(someproject_sched_switch, * * * * * A function has a regular function arguments @@ -236,7 +267,7 @@ int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start); * * be saved into the ring buffer. These are the fields * * that will be exposed to readers. * * - * * tp_field(pid_t, prev_pid, prev->pid) is equivalent + * * ctf_integer(pid_t, prev_pid, prev->pid) is equivalent * * to a standard declaraton: * * * * pid_t prev_pid; @@ -245,7 +276,7 @@ int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start); * * * * prev_pid = prev->pid; * * - * * tp_array(char, prev_comm, TASK_COMM_LEN, prev->comm) is + * * ctf_array(char, prev_comm, prev->comm, TASK_COMM_LEN) is * * equivalent to: * * * * char prev_comm[TASK_COMM_LEN]; @@ -256,14 +287,14 @@ int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start); * * * * TP_FIELDS( - * tp_array(char, prev_comm, TASK_COMM_LEN, prev->comm) - * tp_field(pid_t, prev_pid, prev->pid) - * tp_field(int, prev_prio, prev->prio) - * tp_array(char, next_comm, TASK_COMM_LEN, next->comm) - * tp_field(pid_t, next_pid, next->pid) - * tp_field(int, next_prio, next->prio) + * ctf_array(char, prev_comm, prev->comm, TASK_COMM_LEN) + * ctf_integer(pid_t, prev_pid, prev->pid) + * ctf_integer(int, prev_prio, prev->prio) + * ctf_array(char, next_comm, next->comm, TASK_COMM_LEN) + * ctf_integer(pid_t, next_pid, next->pid) + * ctf_integer(int, next_prio, next->prio) * ) - * ); + * ) */ #define TRACEPOINT_EVENT(name, proto, args, fields) \ @@ -283,45 +314,6 @@ int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start); #define TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \ _DECLARE_TRACEPOINT_NOARGS(name) - - -#define TRACEPOINT_EVENT_LIB \ - extern struct trace_event * const __start___trace_events_ptrs[] \ - __attribute__((weak, visibility("hidden"))); \ - extern struct trace_event * const __stop___trace_events_ptrs[] \ - __attribute__((weak, visibility("hidden"))); \ - static struct trace_event * __event_ptrs_dummy \ - __attribute__((used, section("__trace_events_ptrs"))); \ - static void __attribute__((constructor)) \ - __trace_events__init(void) \ - { \ - trace_event_register_lib(__start___trace_events_ptrs, \ - __stop___trace_events_ptrs - \ - __start___trace_events_ptrs); \ - } \ - \ - static void __attribute__((destructor)) \ - __trace_event__destroy(void) \ - { \ - trace_event_unregister_lib(__start___trace_events_ptrs);\ - } - -struct trace_event { - const char *name; -}; - -struct trace_event_lib { - struct trace_event * const *trace_events_start; - int trace_events_count; - struct cds_list_head list; -}; - -extern -int trace_event_register_lib(struct trace_event * const *start_trace_events, - int trace_event_count); -extern -int trace_event_unregister_lib(struct trace_event * const *start_trace_events); - #endif /* #ifndef TRACEPOINT_EVENT */ #endif /* _UST_TRACEPOINT_H */ -- 2.34.1