diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-14 13:49:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-14 13:49:03 -0400 |
commit | eeee78cf77df0450ca285a7cd6d73842181e825c (patch) | |
tree | 330540323eae82977756e5086492654b9e461871 /samples | |
parent | 3f3c73de77b5598e9f87812ac4da9445090c3b4a (diff) | |
parent | 9828413d4715d4ed12bc92b161f4ed377d777ffb (diff) |
Merge tag 'trace-v4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt:
"Some clean ups and small fixes, but the biggest change is the addition
of the TRACE_DEFINE_ENUM() macro that can be used by tracepoints.
Tracepoints have helper functions for the TP_printk() called
__print_symbolic() and __print_flags() that lets a numeric number be
displayed as a a human comprehensible text. What is placed in the
TP_printk() is also shown in the tracepoint format file such that user
space tools like perf and trace-cmd can parse the binary data and
express the values too. Unfortunately, the way the TRACE_EVENT()
macro works, anything placed in the TP_printk() will be shown pretty
much exactly as is. The problem arises when enums are used. That's
because unlike macros, enums will not be changed into their values by
the C pre-processor. Thus, the enum string is exported to the format
file, and this makes it useless for user space tools.
The TRACE_DEFINE_ENUM() solves this by converting the enum strings in
the TP_printk() format into their number, and that is what is shown to
user space. For example, the tracepoint tlb_flush currently has this
in its format file:
__print_symbolic(REC->reason,
{ TLB_FLUSH_ON_TASK_SWITCH, "flush on task switch" },
{ TLB_REMOTE_SHOOTDOWN, "remote shootdown" },
{ TLB_LOCAL_SHOOTDOWN, "local shootdown" },
{ TLB_LOCAL_MM_SHOOTDOWN, "local mm shootdown" })
After adding:
TRACE_DEFINE_ENUM(TLB_FLUSH_ON_TASK_SWITCH);
TRACE_DEFINE_ENUM(TLB_REMOTE_SHOOTDOWN);
TRACE_DEFINE_ENUM(TLB_LOCAL_SHOOTDOWN);
TRACE_DEFINE_ENUM(TLB_LOCAL_MM_SHOOTDOWN);
Its format file will contain this:
__print_symbolic(REC->reason,
{ 0, "flush on task switch" },
{ 1, "remote shootdown" },
{ 2, "local shootdown" },
{ 3, "local mm shootdown" })"
* tag 'trace-v4.1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (27 commits)
tracing: Add enum_map file to show enums that have been mapped
writeback: Export enums used by tracepoint to user space
v4l: Export enums used by tracepoints to user space
SUNRPC: Export enums in tracepoints to user space
mm: tracing: Export enums in tracepoints to user space
irq/tracing: Export enums in tracepoints to user space
f2fs: Export the enums in the tracepoints to userspace
net/9p/tracing: Export enums in tracepoints to userspace
x86/tlb/trace: Export enums in used by tlb_flush tracepoint
tracing/samples: Update the trace-event-sample.h with TRACE_DEFINE_ENUM()
tracing: Allow for modules to convert their enums to values
tracing: Add TRACE_DEFINE_ENUM() macro to map enums to their values
tracing: Update trace-event-sample with TRACE_SYSTEM_VAR documentation
tracing: Give system name a pointer
brcmsmac: Move each system tracepoints to their own header
iwlwifi: Move each system tracepoints to their own header
mac80211: Move message tracepoints to their own header
tracing: Add TRACE_SYSTEM_VAR to xhci-hcd
tracing: Add TRACE_SYSTEM_VAR to kvm-s390
tracing: Add TRACE_SYSTEM_VAR to intel-sst
...
Diffstat (limited to 'samples')
-rw-r--r-- | samples/trace_events/trace-events-sample.h | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h index a2c8b02b6359..8965d1bb8811 100644 --- a/samples/trace_events/trace-events-sample.h +++ b/samples/trace_events/trace-events-sample.h | |||
@@ -22,7 +22,25 @@ | |||
22 | * protection, just like TRACE_INCLUDE_FILE. | 22 | * protection, just like TRACE_INCLUDE_FILE. |
23 | */ | 23 | */ |
24 | #undef TRACE_SYSTEM | 24 | #undef TRACE_SYSTEM |
25 | #define TRACE_SYSTEM sample | 25 | #define TRACE_SYSTEM sample-trace |
26 | |||
27 | /* | ||
28 | * TRACE_SYSTEM is expected to be a C valid variable (alpha-numeric | ||
29 | * and underscore), although it may start with numbers. If for some | ||
30 | * reason it is not, you need to add the following lines: | ||
31 | */ | ||
32 | #undef TRACE_SYSTEM_VAR | ||
33 | #define TRACE_SYSTEM_VAR sample_trace | ||
34 | /* | ||
35 | * But the above is only needed if TRACE_SYSTEM is not alpha-numeric | ||
36 | * and underscored. By default, TRACE_SYSTEM_VAR will be equal to | ||
37 | * TRACE_SYSTEM. As TRACE_SYSTEM_VAR must be alpha-numeric, if | ||
38 | * TRACE_SYSTEM is not, then TRACE_SYSTEM_VAR must be defined with | ||
39 | * only alpha-numeric and underscores. | ||
40 | * | ||
41 | * The TRACE_SYSTEM_VAR is only used internally and not visible to | ||
42 | * user space. | ||
43 | */ | ||
26 | 44 | ||
27 | /* | 45 | /* |
28 | * Notice that this file is not protected like a normal header. | 46 | * Notice that this file is not protected like a normal header. |
@@ -180,8 +198,30 @@ static inline int __length_of(const int *list) | |||
180 | ; | 198 | ; |
181 | return i; | 199 | return i; |
182 | } | 200 | } |
201 | |||
202 | enum { | ||
203 | TRACE_SAMPLE_FOO = 2, | ||
204 | TRACE_SAMPLE_BAR = 4, | ||
205 | TRACE_SAMPLE_ZOO = 8, | ||
206 | }; | ||
183 | #endif | 207 | #endif |
184 | 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 | |||
185 | TRACE_EVENT(foo_bar, | 225 | TRACE_EVENT(foo_bar, |
186 | 226 | ||
187 | TP_PROTO(const char *foo, int bar, const int *lst, | 227 | TP_PROTO(const char *foo, int bar, const int *lst, |
@@ -206,7 +246,47 @@ TRACE_EVENT(foo_bar, | |||
206 | __assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus()); | 246 | __assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus()); |
207 | ), | 247 | ), |
208 | 248 | ||
209 | 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 | */ | ||
210 | __print_array(__get_dynamic_array(list), | 290 | __print_array(__get_dynamic_array(list), |
211 | __get_dynamic_array_len(list), | 291 | __get_dynamic_array_len(list), |
212 | sizeof(int)), | 292 | sizeof(int)), |