Skip to content

Commit

Permalink
Add tracepoint_enabled() macro
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dmitri-shubin committed Mar 27, 2015
1 parent 07d8f12 commit 4eb9d63
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
27 changes: 27 additions & 0 deletions doc/man/lttng-ust.3
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions include/lttng/tracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@
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__
Expand Down

0 comments on commit 4eb9d63

Please sign in to comment.