diff options
| author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2015-02-09 17:14:04 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2015-02-09 18:05:51 -0500 |
| commit | 7496946a88ab48830f3101c08f8e770cc0902bbb (patch) | |
| tree | 1fc88b3e2cdeb598b5dfe03d9aa2766d1f8f8048 /samples | |
| parent | 6adc13f8c096736957444ffa2aa11421b5671aef (diff) | |
tracing: Add samples of DECLARE_EVENT_CLASS() and DEFINE_EVENT()
Add to samples/trace_events/ the macros DECLARE_EVENT_CLASS() and
DEFINE_EVENT() and recommend using them over multiple TRACE_EVENT()
macros if the multiple events have the same format.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/trace_events/trace-events-sample.c | 7 | ||||
| -rw-r--r-- | samples/trace_events/trace-events-sample.h | 81 |
2 files changed, 88 insertions, 0 deletions
diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c index 39d4484aef53..880a7d1d27d2 100644 --- a/samples/trace_events/trace-events-sample.c +++ b/samples/trace_events/trace-events-sample.c | |||
| @@ -35,7 +35,13 @@ static void simple_thread_func(int cnt) | |||
| 35 | trace_foo_bar("hello", cnt, array, random_strings[len], | 35 | trace_foo_bar("hello", cnt, array, random_strings[len], |
| 36 | tsk_cpus_allowed(current)); | 36 | tsk_cpus_allowed(current)); |
| 37 | 37 | ||
| 38 | trace_foo_with_template_simple("HELLO", cnt); | ||
| 39 | |||
| 38 | trace_foo_bar_with_cond("Some times print", cnt); | 40 | trace_foo_bar_with_cond("Some times print", cnt); |
| 41 | |||
| 42 | trace_foo_with_template_cond("prints other times", cnt); | ||
| 43 | |||
| 44 | trace_foo_with_template_print("I have to be different", cnt); | ||
| 39 | } | 45 | } |
| 40 | 46 | ||
| 41 | static int simple_thread(void *arg) | 47 | static int simple_thread(void *arg) |
| @@ -58,6 +64,7 @@ static void simple_thread_func_fn(int cnt) | |||
| 58 | 64 | ||
| 59 | /* More silly tracepoints */ | 65 | /* More silly tracepoints */ |
| 60 | trace_foo_bar_with_fn("Look at me", cnt); | 66 | trace_foo_bar_with_fn("Look at me", cnt); |
| 67 | trace_foo_with_template_fn("Look at me too", cnt); | ||
| 61 | } | 68 | } |
| 62 | 69 | ||
| 63 | static int simple_thread_fn(void *arg) | 70 | static int simple_thread_fn(void *arg) |
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h index d0be8411b527..a2c8b02b6359 100644 --- a/samples/trace_events/trace-events-sample.h +++ b/samples/trace_events/trace-events-sample.h | |||
| @@ -314,6 +314,87 @@ TRACE_EVENT_FN(foo_bar_with_fn, | |||
| 314 | foo_bar_reg, foo_bar_unreg | 314 | foo_bar_reg, foo_bar_unreg |
| 315 | ); | 315 | ); |
| 316 | 316 | ||
| 317 | /* | ||
| 318 | * Each TRACE_EVENT macro creates several helper functions to produce | ||
| 319 | * the code to add the tracepoint, create the files in the trace | ||
| 320 | * directory, hook it to perf, assign the values and to print out | ||
| 321 | * the raw data from the ring buffer. To prevent too much bloat, | ||
| 322 | * if there are more than one tracepoint that uses the same format | ||
| 323 | * for the proto, args, struct, assign and printk, and only the name | ||
| 324 | * is different, it is highly recommended to use the DECLARE_EVENT_CLASS | ||
| 325 | * | ||
| 326 | * DECLARE_EVENT_CLASS() macro creates most of the functions for the | ||
| 327 | * tracepoint. Then DEFINE_EVENT() is use to hook a tracepoint to those | ||
| 328 | * functions. This DEFINE_EVENT() is an instance of the class and can | ||
| 329 | * be enabled and disabled separately from other events (either TRACE_EVENT | ||
| 330 | * or other DEFINE_EVENT()s). | ||
| 331 | * | ||
| 332 | * Note, TRACE_EVENT() itself is simply defined as: | ||
| 333 | * | ||
| 334 | * #define TRACE_EVENT(name, proto, args, tstruct, assign, printk) \ | ||
| 335 | * DEFINE_EVENT_CLASS(name, proto, args, tstruct, assign, printk); \ | ||
| 336 | * DEFINE_EVENT(name, name, proto, args) | ||
| 337 | * | ||
| 338 | * The DEFINE_EVENT() also can be declared with conditions and reg functions: | ||
| 339 | * | ||
| 340 | * DEFINE_EVENT_CONDITION(template, name, proto, args, cond); | ||
| 341 | * DEFINE_EVENT_FN(template, name, proto, args, reg, unreg); | ||
| 342 | */ | ||
| 343 | DECLARE_EVENT_CLASS(foo_template, | ||
| 344 | |||
| 345 | TP_PROTO(const char *foo, int bar), | ||
| 346 | |||
| 347 | TP_ARGS(foo, bar), | ||
| 348 | |||
| 349 | TP_STRUCT__entry( | ||
| 350 | __string( foo, foo ) | ||
| 351 | __field( int, bar ) | ||
| 352 | ), | ||
| 353 | |||
| 354 | TP_fast_assign( | ||
| 355 | __assign_str(foo, foo); | ||
| 356 | __entry->bar = bar; | ||
| 357 | ), | ||
| 358 | |||
| 359 | TP_printk("foo %s %d", __get_str(foo), __entry->bar) | ||
| 360 | ); | ||
| 361 | |||
| 362 | /* | ||
| 363 | * Here's a better way for the previous samples (except, the first | ||
| 364 | * exmaple had more fields and could not be used here). | ||
| 365 | */ | ||
| 366 | DEFINE_EVENT(foo_template, foo_with_template_simple, | ||
| 367 | TP_PROTO(const char *foo, int bar), | ||
| 368 | TP_ARGS(foo, bar)); | ||
| 369 | |||
| 370 | DEFINE_EVENT_CONDITION(foo_template, foo_with_template_cond, | ||
| 371 | TP_PROTO(const char *foo, int bar), | ||
| 372 | TP_ARGS(foo, bar), | ||
| 373 | TP_CONDITION(!(bar % 8))); | ||
| 374 | |||
| 375 | |||
| 376 | DEFINE_EVENT_FN(foo_template, foo_with_template_fn, | ||
| 377 | TP_PROTO(const char *foo, int bar), | ||
| 378 | TP_ARGS(foo, bar), | ||
| 379 | foo_bar_reg, foo_bar_unreg); | ||
| 380 | |||
| 381 | /* | ||
| 382 | * Anytime two events share basically the same values and have | ||
| 383 | * the same output, use the DECLARE_EVENT_CLASS() and DEFINE_EVENT() | ||
| 384 | * when ever possible. | ||
| 385 | */ | ||
| 386 | |||
| 387 | /* | ||
| 388 | * If the event is similar to the DECLARE_EVENT_CLASS, but you need | ||
| 389 | * to have a different output, then use DEFINE_EVENT_PRINT() which | ||
| 390 | * lets you override the TP_printk() of the class. | ||
| 391 | */ | ||
| 392 | |||
| 393 | DEFINE_EVENT_PRINT(foo_template, foo_with_template_print, | ||
| 394 | TP_PROTO(const char *foo, int bar), | ||
| 395 | TP_ARGS(foo, bar), | ||
| 396 | TP_printk("bar %s %d", __get_str(foo), __entry->bar)); | ||
| 397 | |||
| 317 | #endif | 398 | #endif |
| 318 | 399 | ||
| 319 | /***** NOTICE! The #if protection ends here. *****/ | 400 | /***** NOTICE! The #if protection ends here. *****/ |
