From: Steven Rostedt This patch adds examples of all the new tags in the samples/trace_events/ example code. Signed-off-by: Steven Rostedt --- samples/trace_events/trace-events-sample.c | 21 ++++++++- samples/trace_events/trace-events-sample.h | 66 ++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c index aabc4e9..dea8eb3 100644 --- a/samples/trace_events/trace-events-sample.c +++ b/samples/trace_events/trace-events-sample.c @@ -10,12 +10,31 @@ #define CREATE_TRACE_POINTS #include "trace-events-sample.h" +static struct task_struct *simple_tsk; static void simple_thread_func(int cnt) { + static int mask; + static int myif; + set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ); trace_foo_bar("hello", cnt); + trace_format_examples(jiffies, + jiffies * 2, + "a string here", + &simple_tsk, + mask, mask, simple_thread_func, + myif, myif, cpu_clock(raw_smp_processor_id()), + 123456); + if (!myif) + myif = 3; + + if (!mask) + mask = 5; + + mask <<= mask; + myif <<= myif; } static int simple_thread(void *arg) @@ -28,8 +47,6 @@ static int simple_thread(void *arg) return 0; } -static struct task_struct *simple_tsk; - static int __init trace_event_init(void) { simple_tsk = kthread_run(simple_thread, NULL, "event-sample"); diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h index 128a897..08b4768 100644 --- a/samples/trace_events/trace-events-sample.h +++ b/samples/trace_events/trace-events-sample.h @@ -65,6 +65,11 @@ * Note, that for both the assign and the printk, __entry is the handler * to the data structure in the ring buffer, and is defined by the * TP_STRUCT__entry. + * + * Note it is better to now use the tag format. Examples are in the event + * below, and the explanation of the tag format language is in: + * + * kernel/trace/trace_read_binary.h */ TRACE_EVENT(foo_bar, @@ -84,6 +89,67 @@ TRACE_EVENT(foo_bar, TP_printk("foo %s %d", __entry->foo, __entry->bar) ); + +/* + * These are a few examples of the tag format to do the output. + */ +TRACE_EVENT(format_examples, + + TP_PROTO(int myint, long mylong, char *mystr, void *myptr, + unsigned long mask, unsigned sym, void *func, + int myif, int myifmask, unsigned long long nsec, + int dev), + + TP_ARGS(myint, mylong, mystr, myptr, mask, sym, func, + myif, myifmask, nsec, dev), + + TP_STRUCT__entry( + __field( int, myint ) + __field( long, mylong ) + __string(str, mystr) + __array( char, str_arr, 20 ) + __field( void *, func ) + __field( int, myif ) + __field( unsigned long, mask ) + __field( unsigned long, sym ) + __field( int, myifmask ) + __field( int, dev ) + __field( unsigned long long, nsec ) + ), + + TP_fast_assign( + __entry->myint = myint; + __entry->mylong = mylong; + __assign_str(str, mystr); + strncpy(__entry->str_arr, mystr, 19); + __entry->str_arr[19] = 0; + __entry->mask = mask; + __entry->sym = sym; + __entry->func = func; + __entry->myif = myif; + __entry->myifmask = myifmask; + __entry->dev = dev; + __entry->nsec = nsec; + ), + + TP_FORMAT("to see a normal int \n" + "or perhaps make it unsigned \n" + "no difference for the size \n" + "lets make it into a hex \n" + "dynamic strings are simple \n" + "and so are static ones \n" + "see a func and offset \n" + "or just the func name \n" + "should we print \n" + "or base it on a bit mask \n" + "we want to see that device ,\n" + "we can see masks \n" + "or values of symbols \n" + "and know what time it is in seconds \n" + "millisecs \n" + "or microsecs ") +); + #endif /***** NOTICE! The #if protection ends here. *****/ -- 1.6.3.1 -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/