diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2015-09-29 09:43:30 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2015-09-29 13:23:57 -0400 |
commit | a3418a364ec3c8f0c29bf3f4cfc71dc6f240150e (patch) | |
tree | 419f836952e6d981d196aeecdcf21a1ac9dcd79e /kernel/trace/trace.c | |
parent | ce3fed628ecc86d81fdb2be5a5c336c636960bfe (diff) |
tracing: Use TRACE_FLAGS macro to keep enums and strings matched
Use a cute little macro trick to keep the names of the trace flags file
guaranteed to match the corresponding masks.
The macro TRACE_FLAGS is defined as a serious of enum names followed by
the string name of the file that matches it. For example:
#define TRACE_FLAGS \
C(PRINT_PARENT, "print-parent"), \
C(SYM_OFFSET, "sym-offset"), \
C(SYM_ADDR, "sym-addr"), \
C(VERBOSE, "verbose"),
Now we can define the following:
#undef C
#define C(a, b) TRACE_ITER_##a##_BIT
enum trace_iterator_bits { TRACE_FLAGS };
The above creates:
enum trace_iterator_bits {
TRACE_ITER_PRINT_PARENT_BIT,
TRACE_ITER_SYM_OFFSET_BIT,
TRACE_ITER_SYM_ADDR_BIT,
TRACE_ITER_VERBOSE_BIT,
};
Then we can redefine C as:
#undef C
#define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
enum trace_iterator_flags { TRACE_FLAGS };
Which creates:
enum trace_iterator_flags {
TRACE_ITER_PRINT_PARENT = (1 << TRACE_ITER_PRINT_PARENT_BIT),
TRACE_ITER_SYM_OFFSET = (1 << TRACE_ITER_SYM_OFFSET_BIT),
TRACE_ITER_SYM_ADDR = (1 << TRACE_ITER_SYM_ADDR_BIT),
TRACE_ITER_VERBOSE = (1 << TRACE_ITER_VERBOSE_BIT),
};
Then finally we can create the list of file names:
#undef C
#define C(a, b) b
static const char *trace_options[] = {
TRACE_FLAGS
NULL
};
Which creates:
static const char *trace_options[] = {
"print-parent",
"sym-offset",
"sym-addr",
"verbose",
NULL
};
The importance of this is that the strings match the bit index.
trace_options[TRACE_ITER_SYM_ADDR_BIT] == "sym-addr"
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index f2fbf610d20e..e80e380d0238 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -854,34 +854,18 @@ unsigned long nsecs_to_usecs(unsigned long nsecs) | |||
854 | return nsecs / 1000; | 854 | return nsecs / 1000; |
855 | } | 855 | } |
856 | 856 | ||
857 | /* | ||
858 | * TRACE_FLAGS is defined as a tuple matching bit masks with strings. | ||
859 | * It uses C(a, b) where 'a' is the enum name and 'b' is the string that | ||
860 | * matches it. By defining "C(a, b) b", TRACE_FLAGS becomes a list | ||
861 | * of strings in the order that the enums were defined. | ||
862 | */ | ||
863 | #undef C | ||
864 | #define C(a, b) b | ||
865 | |||
857 | /* These must match the bit postions in trace_iterator_flags */ | 866 | /* These must match the bit postions in trace_iterator_flags */ |
858 | static const char *trace_options[] = { | 867 | static const char *trace_options[] = { |
859 | "print-parent", | 868 | TRACE_FLAGS |
860 | "sym-offset", | ||
861 | "sym-addr", | ||
862 | "verbose", | ||
863 | "raw", | ||
864 | "hex", | ||
865 | "bin", | ||
866 | "block", | ||
867 | "stacktrace", | ||
868 | "trace_printk", | ||
869 | "branch", | ||
870 | "annotate", | ||
871 | "userstacktrace", | ||
872 | "sym-userobj", | ||
873 | "printk-msg-only", | ||
874 | "context-info", | ||
875 | "latency-format", | ||
876 | "sleep-time", | ||
877 | "graph-time", | ||
878 | "record-cmd", | ||
879 | "overwrite", | ||
880 | "disable_on_free", | ||
881 | "irq-info", | ||
882 | "markers", | ||
883 | "function-trace", | ||
884 | "display-graph", | ||
885 | NULL | 869 | NULL |
886 | }; | 870 | }; |
887 | 871 | ||