Add tracepoint_enabled() macro
authorDmitri Shubin <dmitri.shubin@orc-group.com>
Fri, 27 Mar 2015 19:34:11 +0000 (15:34 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 27 Mar 2015 19:35:36 +0000 (15:35 -0400)
Allows application to check if given probe is enabled.
It's useful when data it passes to tracepoint is expensive to compute.

Signed-off-by: Dmitri Shubin <dmitri.shubin@orc-group.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
doc/man/lttng-ust.3
include/lttng/tracepoint.h

index 6f8763b9d2dcaa2f9b19cb12358de256f1d49dcd..7dae8b538d8d4161e57f54bee9e5a872815e6f02 100644 (file)
@@ -290,6 +290,33 @@ Even though LTTng-UST supports tracepoint() call site duplicates having
 the same provider and event name, it is recommended to use a
 provider event name pair only once within the source code to help
 map events back to their call sites when analyzing the trace.
+
+Sometimes arguments to the probe are expensive to compute (e.g.
+take call stack). To avoid the computation when the tracepoint is
+disabled one can use more 'low level' tracepoint_enabled() and
+do_tracepoint() macros as following:
+
+       if (tracepoint_enabled(ust_tests_hello, tptest)) {
+               /* prepare arguments */
+               do_tracepoint(ust_tests_hello, tptest, i, netint, values,
+                       text, strlen(text), dbl, flt);
+       }
+
+Here do_tracepoint() doesn't contain check if the tracepoint is enabled.
+Using tracepoint() in such scenario is dangerous since it also contains
+enabled check and thus race condition is possible in the following code
+if the tracepoint has been enabled after check in tracepoint_enabled()
+but before tracepoint():
+
+       if (tracepoint_enabled(provider, name)) { /* tracepoint is disabled */
+               prepare(args);
+       }
+       /* tracepoint is enabled by 'lttng' tool */
+       tracepoint(provider, name, args); /* args wasn't prepared properly */
+
+Note also that neither tracepoint_enabled() nor do_tracepoint() have
+STAP_PROBEV() call so if you need it you should emit this call yourself.
+
 .fi
 
 .SH "BUILDING/LINKING THE TRACEPOINT PROVIDER"
index 63759a20ee3da5f7a7e0beb6f08219c8567abe55..1734c1b7ac8d6c0a5aaedcc9c5e9c4f3db8effc4 100644 (file)
 extern "C" {
 #endif
 
+#define tracepoint_enabled(provider, name) \
+       caa_unlikely(__tracepoint_##provider##___##name.state)
+
+#define do_tracepoint(provider, name, ...) \
+       __tracepoint_cb_##provider##___##name(__VA_ARGS__)
+
 #define tracepoint(provider, name, ...)                                            \
        do {                                                                \
                STAP_PROBEV(provider, name, ## __VA_ARGS__);                \
-               if (caa_unlikely(__tracepoint_##provider##___##name.state)) \
-                       __tracepoint_cb_##provider##___##name(__VA_ARGS__); \
+               if (tracepoint_enabled(provider, name))                     \
+                       do_tracepoint(provider, name, __VA_ARGS__);         \
        } while (0)
 
 #define TP_ARGS(...)       __VA_ARGS__
This page took 0.02675 seconds and 4 git commands to generate.