[lttng-dev] How to check is tracepoint is currently enabled (UST)
Simon Marchi
simon.marchi at polymtl.ca
Wed Jun 25 11:36:15 EDT 2014
I am pretty sure that Dmitri is talking about a check that you can use
in your application, to see if a specific tracepoint is enabled. If
some data that you pass to the tracepoint is expensive to compute, yo
might want to avoid computing it when tracing is disabled.
> #define tracepoint_enabled(provider, name) caa_unlikely(__tracepoint_##provider##___##name.state)
Dmitri, that macro that you posted, does it work for you?
Otherwise, you can simply embed the code in the call to tracepoint:
tracepoint(hello, world, expensive_work(data));
In the expansion of the "tracepoint" macro [1], expensive_work is only
called if the tracepoint is enabled, so you don't pay the cost if the
tracepoint is disabled.
If the code that you need to run to compute your data is not a single
function call, you can: (a) make it a function or (b) use gcc's
statement expressions [2]. For example, instead of:
/* Here we call get_data and compute_median even if tracing is disabled. */
struct data* data = get_data();
int median = compute_median(data);
free(data);
tracepoint(hello, world, median);
you could do:
/* Here we _don't_ call get_data and compute_median when tracing
is disabled. */
tracepoint(hello, world, ({
struct data* data = get_data();
int median = compute_median(data);
free(data);
median;
}));
The statement expression will only be executed if the tracepoint is
enabled (you can verify that by adding a printf in there).
Does it answer you question?
Simon
[1] http://git.lttng.org/?p=lttng-ust.git;a=blob;f=include/lttng/tracepoint.h;h=c5a09d815db1383e539c8c455e8477dda29a579a;hb=HEAD#l47
[2] https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
More information about the lttng-dev
mailing list