diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2015-04-01 15:55:36 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2015-04-08 09:39:58 -0400 |
commit | 32eb3d0d09943ab9dcc01fb8d2619b64e965992c (patch) | |
tree | d370b85fcc0885d435588070b04832a87d5d42ce /samples/trace_events | |
parent | 3673b8e4ce7237160fa31ee8d7e94a4d5a9976a1 (diff) |
tracing/samples: Update the trace-event-sample.h with TRACE_DEFINE_ENUM()
Document the use of TRACE_DEFINE_ENUM() by adding enums to the
trace-event-sample.h and using this macro to convert them in the format
files.
Also update the comments and sho the use of __print_symbolic() and
__print_flags() as well as adding comments abount __print_array().
Link: http://lkml.kernel.org/r/20150403013802.220157513@goodmis.org
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'samples/trace_events')
-rw-r--r-- | samples/trace_events/trace-events-sample.h | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h index 19405f18cc8a..8965d1bb8811 100644 --- a/samples/trace_events/trace-events-sample.h +++ b/samples/trace_events/trace-events-sample.h | |||
@@ -198,8 +198,30 @@ static inline int __length_of(const int *list) | |||
198 | ; | 198 | ; |
199 | return i; | 199 | return i; |
200 | } | 200 | } |
201 | |||
202 | enum { | ||
203 | TRACE_SAMPLE_FOO = 2, | ||
204 | TRACE_SAMPLE_BAR = 4, | ||
205 | TRACE_SAMPLE_ZOO = 8, | ||
206 | }; | ||
201 | #endif | 207 | #endif |
202 | 208 | ||
209 | /* | ||
210 | * If enums are used in the TP_printk(), their names will be shown in | ||
211 | * format files and not their values. This can cause problems with user | ||
212 | * space programs that parse the format files to know how to translate | ||
213 | * the raw binary trace output into human readable text. | ||
214 | * | ||
215 | * To help out user space programs, any enum that is used in the TP_printk() | ||
216 | * should be defined by TRACE_DEFINE_ENUM() macro. All that is needed to | ||
217 | * be done is to add this macro with the enum within it in the trace | ||
218 | * header file, and it will be converted in the output. | ||
219 | */ | ||
220 | |||
221 | TRACE_DEFINE_ENUM(TRACE_SAMPLE_FOO); | ||
222 | TRACE_DEFINE_ENUM(TRACE_SAMPLE_BAR); | ||
223 | TRACE_DEFINE_ENUM(TRACE_SAMPLE_ZOO); | ||
224 | |||
203 | TRACE_EVENT(foo_bar, | 225 | TRACE_EVENT(foo_bar, |
204 | 226 | ||
205 | TP_PROTO(const char *foo, int bar, const int *lst, | 227 | TP_PROTO(const char *foo, int bar, const int *lst, |
@@ -224,7 +246,47 @@ TRACE_EVENT(foo_bar, | |||
224 | __assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus()); | 246 | __assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus()); |
225 | ), | 247 | ), |
226 | 248 | ||
227 | TP_printk("foo %s %d %s %s (%s)", __entry->foo, __entry->bar, | 249 | TP_printk("foo %s %d %s %s %s %s (%s)", __entry->foo, __entry->bar, |
250 | |||
251 | /* | ||
252 | * Notice here the use of some helper functions. This includes: | ||
253 | * | ||
254 | * __print_symbolic( variable, { value, "string" }, ... ), | ||
255 | * | ||
256 | * The variable is tested against each value of the { } pair. If | ||
257 | * the variable matches one of the values, then it will print the | ||
258 | * string in that pair. If non are matched, it returns a string | ||
259 | * version of the number (if __entry->bar == 7 then "7" is returned). | ||
260 | */ | ||
261 | __print_symbolic(__entry->bar, | ||
262 | { 0, "zero" }, | ||
263 | { TRACE_SAMPLE_FOO, "TWO" }, | ||
264 | { TRACE_SAMPLE_BAR, "FOUR" }, | ||
265 | { TRACE_SAMPLE_ZOO, "EIGHT" }, | ||
266 | { 10, "TEN" } | ||
267 | ), | ||
268 | |||
269 | /* | ||
270 | * __print_flags( variable, "delim", { value, "flag" }, ... ), | ||
271 | * | ||
272 | * This is similar to __print_symbolic, except that it tests the bits | ||
273 | * of the value. If ((FLAG & variable) == FLAG) then the string is | ||
274 | * printed. If more than one flag matches, then each one that does is | ||
275 | * also printed with delim in between them. | ||
276 | * If not all bits are accounted for, then the not found bits will be | ||
277 | * added in hex format: 0x506 will show BIT2|BIT4|0x500 | ||
278 | */ | ||
279 | __print_flags(__entry->bar, "|", | ||
280 | { 1, "BIT1" }, | ||
281 | { 2, "BIT2" }, | ||
282 | { 4, "BIT3" }, | ||
283 | { 8, "BIT4" } | ||
284 | ), | ||
285 | /* | ||
286 | * __print_array( array, len, element_size ) | ||
287 | * | ||
288 | * This prints out the array that is defined by __array in a nice format. | ||
289 | */ | ||
228 | __print_array(__get_dynamic_array(list), | 290 | __print_array(__get_dynamic_array(list), |
229 | __get_dynamic_array_len(list), | 291 | __get_dynamic_array_len(list), |
230 | sizeof(int)), | 292 | sizeof(int)), |