Filter: prepare filter stack data
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 8 Jul 2012 17:35:48 +0000 (13:35 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 8 Jul 2012 17:35:48 +0000 (13:35 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
liblttng-ust/ltt-events.c
liblttng-ust/ltt-probes.c
liblttng-ust/lttng-ust-abi.c

index 5edfbb99f88019565669adaf735cefa2e6cc3b12..91d5839bfa6c1386ea13f9160207e7c27413be3e 100644 (file)
@@ -293,7 +293,8 @@ struct ltt_event {
        struct ltt_channel *chan;
        int enabled;
        const struct lttng_event_desc *desc;
-       void (*filter)(struct ltt_event *event);
+       int (*filter)(void *filter_data, const char *filter_stack_data);
+       void *filter_data;
        struct lttng_ctx *ctx;
        enum lttng_ust_instrumentation instrumentation;
        union {
@@ -413,7 +414,9 @@ struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
 
 int ltt_event_create(struct ltt_channel *chan,
                struct lttng_ust_event *event_param,
-               void (*filter)(struct ltt_event *event),
+               int (*filter)(void *filter_data,
+                       const char *filter_stack_data),
+               void *filter_data,
                struct ltt_event **event);
 
 int ltt_channel_enable(struct ltt_channel *channel);
index 853b599036865a44b9c5658e00002336a69d3703..98715bf410f5f275c166bbc0a891613bd5c08059 100644 (file)
@@ -291,6 +291,69 @@ static inline size_t __event_get_size__##_provider##___##_name(size_t *__dynamic
 
 #include TRACEPOINT_INCLUDE
 
+/*
+ * Stage 3.1 of tracepoint event generation.
+ *
+ * Create static inline function that layout the filter stack data.
+ */
+
+/* Reset all macros within TRACEPOINT_EVENT */
+#include <lttng/ust-tracepoint-event-reset.h>
+
+#undef ctf_integer_ext
+#define ctf_integer_ext(_type, _item, _src, _byte_order, _base)                       \
+       if (lttng_is_signed_type(_type))                                       \
+               *(int64_t *) __stack_data = (int64_t) (_type) (_src);          \
+       else                                                                   \
+               *(uint64_t *) __stack_data = (uint64_t) (_type) (_src);        \
+       __stack_data += sizeof(int64_t);
+
+#undef ctf_float
+#define ctf_float(_type, _item, _src)                                         \
+       *(double *) __stack_data = (double) (_type) (_src);                    \
+       __stack_data += sizeof(double);
+
+#undef ctf_array_encoded
+#define ctf_array_encoded(_type, _item, _src, _length, _encoding)             \
+       *(unsigned long *) __stack_data = (unsigned long) (_length);           \
+       __stack_data += sizeof(unsigned long);                                 \
+       *(const void **) __stack_data = (_src);                                \
+       __stack_data += sizeof(void *);
+
+#undef ctf_sequence_encoded
+#define ctf_sequence_encoded(_type, _item, _src, _length_type,                \
+                       _src_length, _encoding)                                \
+       *(unsigned long *) __stack_data = (unsigned long) (_src_length);       \
+       __stack_data += sizeof(unsigned long);                                 \
+       *(const void **) __stack_data = (_src);                                \
+       __stack_data += sizeof(void *);
+
+#undef ctf_string
+#define ctf_string(_item, _src)                                                       \
+       *(unsigned long *) __stack_data = (unsigned long) (strlen(_src) + 1);  \
+       __stack_data += sizeof(unsigned long);                                 \
+       *(const void **) __stack_data = (_src);                                \
+       __stack_data += sizeof(void *);
+
+#undef TP_ARGS
+#define TP_ARGS(...) __VA_ARGS__
+
+#undef TP_FIELDS
+#define TP_FIELDS(...) __VA_ARGS__
+
+#undef TRACEPOINT_EVENT_CLASS
+#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields)             \
+static inline                                                                \
+void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
+                                                _TP_ARGS_DATA_PROTO(_args))  \
+{                                                                            \
+       _fields                                                               \
+}
+
+#include TRACEPOINT_INCLUDE
+
+
+
 /*
  * Stage 4 of tracepoint event generation.
  *
@@ -398,6 +461,12 @@ size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args))      \
 #undef TP_FIELDS
 #define TP_FIELDS(...) __VA_ARGS__
 
+/*
+ * Using twice size for filter stack data to hold size and pointer for
+ * each field (worse case). For integers, max size required is 64-bit.
+ * Same for double-precision floats. Those fit within
+ * 2*sizeof(unsigned long) for all supported architectures.
+ */
 #undef TRACEPOINT_EVENT_CLASS
 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields)             \
 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))\
@@ -408,7 +477,8 @@ static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))\
        size_t __event_len, __event_align;                                    \
        size_t __dynamic_len_idx = 0;                                         \
        union {                                                               \
-               size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)];       \
+               size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
+               char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
        } __stackvar;                                                         \
        int __ret;                                                            \
                                                                              \
@@ -420,7 +490,13 @@ static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))\
                return;                                                       \
        if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled)))                 \
                return;                                                       \
-       __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len,\
+       if (caa_unlikely(__event->filter)) {                                  \
+               __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
+                       _TP_ARGS_DATA_VAR(_args));                                    \
+               if (caa_likely(!__event->filter(__event->filter_data, __stackvar.__filter_stack_data))) \
+                       return;                                               \
+       }                                                                     \
+       __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
                 _TP_ARGS_DATA_VAR(_args));                                   \
        __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
        lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len,  \
index 0fdfd2fd5bcdb115ace5ea1b4d70663c50b0a8eb..eb6749d944628043332e5e1426c5c8fe25a77926 100644 (file)
@@ -251,7 +251,7 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
                                        sizeof(event_param.name));
                                /* create event */
                                ret = ltt_event_create(sw->chan,
-                                       &event_param, NULL,
+                                       &event_param, NULL, NULL,
                                        &ev);
                                if (ret) {
                                        DBG("Error creating event");
@@ -500,7 +500,9 @@ void _ltt_channel_destroy(struct ltt_channel *chan)
  */
 int ltt_event_create(struct ltt_channel *chan,
                struct lttng_ust_event *event_param,
-               void (*filter)(struct ltt_event *event),
+               int (*filter)(void *filter_data,
+                       const char *filter_stack_data),
+               void *filter_data,
                struct ltt_event **_event)
 {
        const struct lttng_event_desc *desc = NULL;     /* silence gcc */
@@ -549,6 +551,7 @@ int ltt_event_create(struct ltt_channel *chan,
        }
        event->chan = chan;
        event->filter = filter;
+       event->filter_data = filter_data;
        /*
         * used_event_id counts the maximum number of event IDs that can
         * register if all probes register.
index 9072d37e30f0eb5f8470ec583a0d586cd8f321ac..39fb571607ad5cd1ff76e99b1d1f2ab2aa51de19 100644 (file)
@@ -372,7 +372,7 @@ void ltt_probes_create_wildcard_events(struct wildcard_entry *entry,
                                        sizeof(event_param.name));
                                /* create event */
                                ret = ltt_event_create(wildcard->chan,
-                                       &event_param, NULL,
+                                       &event_param, NULL, NULL,
                                        &ev);
                                if (ret) {
                                        DBG("Error creating event");
index dac86c7843494da620c920a7c55c5b3f5c86e4e5..fded1e3a806072c0fe8716a5c13d2ee654a54a8f 100644 (file)
@@ -361,7 +361,7 @@ void lttng_metadata_create_events(int channel_objd)
         * We tolerate no failure path after event creation. It will stay
         * invariant for the rest of the session.
         */
-       ret = ltt_event_create(channel, &metadata_params, NULL, &event);
+       ret = ltt_event_create(channel, &metadata_params, NULL, NULL, &event);
        if (ret < 0) {
                goto create_error;
        }
@@ -753,7 +753,7 @@ int lttng_abi_create_event(int channel_objd,
         * We tolerate no failure path after event creation. It will stay
         * invariant for the rest of the session.
         */
-       ret = ltt_event_create(channel, event_param, NULL, &event);
+       ret = ltt_event_create(channel, event_param, NULL, NULL, &event);
        if (ret < 0) {
                goto event_error;
        }
This page took 0.03255 seconds and 4 git commands to generate.