diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2015-02-09 16:05:55 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2015-02-09 16:05:55 -0500 |
commit | c4c7eb29382c456b9be9858c357a490ae0ccd0f6 (patch) | |
tree | 96116b672ee0fa5a2347828b33c31fb8dbed6434 /samples/trace_events | |
parent | 4e20e3a60b57efa1e5c26324ce0260d58be6c81b (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')
-rw-r--r-- | samples/trace_events/trace-events-sample.c | 3 | ||||
-rw-r--r-- | samples/trace_events/trace-events-sample.h | 58 |
2 files changed, 61 insertions, 0 deletions
diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c index 16c15c08ed38..c396a49b5d78 100644 --- a/samples/trace_events/trace-events-sample.c +++ b/samples/trace_events/trace-events-sample.c | |||
@@ -31,8 +31,11 @@ static void simple_thread_func(int cnt) | |||
31 | array[i] = i + 1; | 31 | array[i] = i + 1; |
32 | array[i] = 0; | 32 | array[i] = 0; |
33 | 33 | ||
34 | /* Silly tracepoints */ | ||
34 | trace_foo_bar("hello", cnt, array, random_strings[len], | 35 | trace_foo_bar("hello", cnt, array, random_strings[len], |
35 | tsk_cpus_allowed(current)); | 36 | tsk_cpus_allowed(current)); |
37 | |||
38 | trace_foo_bar_with_cond("Some times print", cnt); | ||
36 | } | 39 | } |
37 | 40 | ||
38 | static int simple_thread(void *arg) | 41 | static int simple_thread(void *arg) |
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 | */ | ||
253 | TRACE_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. *****/ |