aboutsummaryrefslogtreecommitdiffstats
path: root/samples/trace_events/trace-events-sample.h
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2015-02-09 16:05:55 -0500
committerSteven Rostedt <rostedt@goodmis.org>2015-02-09 16:05:55 -0500
commitc4c7eb29382c456b9be9858c357a490ae0ccd0f6 (patch)
tree96116b672ee0fa5a2347828b33c31fb8dbed6434 /samples/trace_events/trace-events-sample.h
parent4e20e3a60b57efa1e5c26324ce0260d58be6c81b (diff)
tracing: Add TRACE_EVENT_CONDITION sample
The sample code lacks an example of TRACE_EVENT_CONDITION, and it has been expressed to me that this feature for TRACE_EVENT is not well known and not used when it could be. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'samples/trace_events/trace-events-sample.h')
-rw-r--r--samples/trace_events/trace-events-sample.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index dd65f7b8c0d9..c3232340914d 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -212,6 +212,64 @@ TRACE_EVENT(foo_bar,
212 sizeof(int)), 212 sizeof(int)),
213 __get_str(str), __get_bitmask(cpus)) 213 __get_str(str), __get_bitmask(cpus))
214); 214);
215
216/*
217 * There may be a case where a tracepoint should only be called if
218 * some condition is set. Otherwise the tracepoint should not be called.
219 * But to do something like:
220 *
221 * if (cond)
222 * trace_foo();
223 *
224 * Would cause a little overhead when tracing is not enabled, and that
225 * overhead, even if small, is not something we want. As tracepoints
226 * use static branch (aka jump_labels), where no branch is taken to
227 * skip the tracepoint when not enabled, and a jmp is placed to jump
228 * to the tracepoint code when it is enabled, having a if statement
229 * nullifies that optimization. It would be nice to place that
230 * condition within the static branch. This is where TRACE_EVENT_CONDITION
231 * comes in.
232 *
233 * TRACE_EVENT_CONDITION() is just like TRACE_EVENT, except it adds another
234 * parameter just after args. Where TRACE_EVENT has:
235 *
236 * TRACE_EVENT(name, proto, args, struct, assign, printk)
237 *
238 * the CONDITION version has:
239 *
240 * TRACE_EVENT_CONDITION(name, proto, args, cond, struct, assign, printk)
241 *
242 * Everything is the same as TRACE_EVENT except for the new cond. Think
243 * of the cond variable as:
244 *
245 * if (cond)
246 * trace_foo_bar_with_cond();
247 *
248 * Except that the logic for the if branch is placed after the static branch.
249 * That is, the if statement that processes the condition will not be
250 * executed unless that traecpoint is enabled. Otherwise it still remains
251 * a nop.
252 */
253TRACE_EVENT_CONDITION(foo_bar_with_cond,
254
255 TP_PROTO(const char *foo, int bar),
256
257 TP_ARGS(foo, bar),
258
259 TP_CONDITION(!(bar % 10)),
260
261 TP_STRUCT__entry(
262 __string( foo, foo )
263 __field( int, bar )
264 ),
265
266 TP_fast_assign(
267 __assign_str(foo, foo);
268 __entry->bar = bar;
269 ),
270
271 TP_printk("foo %s %d", __get_str(foo), __entry->bar)
272);
215#endif 273#endif
216 274
217/***** NOTICE! The #if protection ends here. *****/ 275/***** NOTICE! The #if protection ends here. *****/