Commit a3418a36 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt

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: default avatarSteven Rostedt <rostedt@goodmis.org>
parent ce3fed62
...@@ -854,34 +854,18 @@ unsigned long nsecs_to_usecs(unsigned long nsecs) ...@@ -854,34 +854,18 @@ unsigned long nsecs_to_usecs(unsigned long nsecs)
return nsecs / 1000; return nsecs / 1000;
} }
/*
* TRACE_FLAGS is defined as a tuple matching bit masks with strings.
* It uses C(a, b) where 'a' is the enum name and 'b' is the string that
* matches it. By defining "C(a, b) b", TRACE_FLAGS becomes a list
* of strings in the order that the enums were defined.
*/
#undef C
#define C(a, b) b
/* These must match the bit postions in trace_iterator_flags */ /* These must match the bit postions in trace_iterator_flags */
static const char *trace_options[] = { static const char *trace_options[] = {
"print-parent", TRACE_FLAGS
"sym-offset",
"sym-addr",
"verbose",
"raw",
"hex",
"bin",
"block",
"stacktrace",
"trace_printk",
"branch",
"annotate",
"userstacktrace",
"sym-userobj",
"printk-msg-only",
"context-info",
"latency-format",
"sleep-time",
"graph-time",
"record-cmd",
"overwrite",
"disable_on_free",
"irq-info",
"markers",
"function-trace",
"display-graph",
NULL NULL
}; };
......
...@@ -884,65 +884,53 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf, ...@@ -884,65 +884,53 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
* positions into trace_flags that controls the output. * positions into trace_flags that controls the output.
* *
* NOTE: These bits must match the trace_options array in * NOTE: These bits must match the trace_options array in
* trace.c. * trace.c (this macro guarantees it).
*/ */
enum trace_iterator_bits { #define TRACE_FLAGS \
TRACE_ITER_PRINT_PARENT_BIT = 0, C(PRINT_PARENT, "print-parent"), \
TRACE_ITER_SYM_OFFSET_BIT, C(SYM_OFFSET, "sym-offset"), \
TRACE_ITER_SYM_ADDR_BIT, C(SYM_ADDR, "sym-addr"), \
TRACE_ITER_VERBOSE_BIT, C(VERBOSE, "verbose"), \
TRACE_ITER_RAW_BIT, C(RAW, "raw"), \
TRACE_ITER_HEX_BIT, C(HEX, "hex"), \
TRACE_ITER_BIN_BIT, C(BIN, "bin"), \
TRACE_ITER_BLOCK_BIT, C(BLOCK, "block"), \
TRACE_ITER_STACKTRACE_BIT, C(STACKTRACE, "stacktrace"), \
TRACE_ITER_PRINTK_BIT, C(PRINTK, "trace_printk"), \
TRACE_ITER_BRANCH_BIT, C(BRANCH, "branch"), \
TRACE_ITER_ANNOTATE_BIT, C(ANNOTATE, "annotate"), \
TRACE_ITER_USERSTACKTRACE_BIT, C(USERSTACKTRACE, "userstacktrace"), \
TRACE_ITER_SYM_USEROBJ_BIT, C(SYM_USEROBJ, "sym-userobj"), \
TRACE_ITER_PRINTK_MSGONLY_BIT, C(PRINTK_MSGONLY, "printk-msg-only"), \
TRACE_ITER_CONTEXT_INFO_BIT, /* Print pid/cpu/time */ C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
TRACE_ITER_LATENCY_FMT_BIT, C(LATENCY_FMT, "latency-format"), \
TRACE_ITER_SLEEP_TIME_BIT, C(SLEEP_TIME, "sleep-time"), \
TRACE_ITER_GRAPH_TIME_BIT, C(GRAPH_TIME, "graph-time"), \
TRACE_ITER_RECORD_CMD_BIT, C(RECORD_CMD, "record-cmd"), \
TRACE_ITER_OVERWRITE_BIT, C(OVERWRITE, "overwrite"), \
TRACE_ITER_STOP_ON_FREE_BIT, C(STOP_ON_FREE, "disable_on_free"), \
TRACE_ITER_IRQ_INFO_BIT, C(IRQ_INFO, "irq-info"), \
TRACE_ITER_MARKERS_BIT, C(MARKERS, "markers"), \
TRACE_ITER_FUNCTION_BIT, C(FUNCTION, "function-trace"), \
TRACE_ITER_DISPLAY_GRAPH_BIT, C(DISPLAY_GRAPH, "display-graph"),
};
enum trace_iterator_flags { /*
TRACE_ITER_PRINT_PARENT = (1 << TRACE_ITER_PRINT_PARENT_BIT), * By defining C, we can make TRACE_FLAGS a list of bit names
TRACE_ITER_SYM_OFFSET = (1 << TRACE_ITER_SYM_OFFSET_BIT), * that will define the bits for the flag masks.
TRACE_ITER_SYM_ADDR = (1 << TRACE_ITER_SYM_ADDR_BIT), */
TRACE_ITER_VERBOSE = (1 << TRACE_ITER_VERBOSE_BIT), #undef C
TRACE_ITER_RAW = (1 << TRACE_ITER_RAW_BIT), #define C(a, b) TRACE_ITER_##a##_BIT
TRACE_ITER_HEX = (1 << TRACE_ITER_HEX_BIT),
TRACE_ITER_BIN = (1 << TRACE_ITER_BIN_BIT), enum trace_iterator_bits { TRACE_FLAGS };
TRACE_ITER_BLOCK = (1 << TRACE_ITER_BLOCK_BIT),
TRACE_ITER_STACKTRACE = (1 << TRACE_ITER_STACKTRACE_BIT), /*
TRACE_ITER_PRINTK = (1 << TRACE_ITER_PRINTK_BIT), * By redefining C, we can make TRACE_FLAGS a list of masks that
TRACE_ITER_BRANCH = (1 << TRACE_ITER_BRANCH_BIT), * use the bits as defined above.
TRACE_ITER_ANNOTATE = (1 << TRACE_ITER_ANNOTATE_BIT), */
TRACE_ITER_USERSTACKTRACE = (1 << TRACE_ITER_USERSTACKTRACE_BIT), #undef C
TRACE_ITER_SYM_USEROBJ = (1 << TRACE_ITER_SYM_USEROBJ_BIT), #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
TRACE_ITER_PRINTK_MSGONLY = (1 << TRACE_ITER_PRINTK_MSGONLY_BIT),
TRACE_ITER_CONTEXT_INFO = (1 << TRACE_ITER_CONTEXT_INFO_BIT), enum trace_iterator_flags { TRACE_FLAGS };
TRACE_ITER_LATENCY_FMT = (1 << TRACE_ITER_LATENCY_FMT_BIT),
TRACE_ITER_SLEEP_TIME = (1 << TRACE_ITER_SLEEP_TIME_BIT),
TRACE_ITER_GRAPH_TIME = (1 << TRACE_ITER_GRAPH_TIME_BIT),
TRACE_ITER_RECORD_CMD = (1 << TRACE_ITER_RECORD_CMD_BIT),
TRACE_ITER_OVERWRITE = (1 << TRACE_ITER_OVERWRITE_BIT),
TRACE_ITER_STOP_ON_FREE = (1 << TRACE_ITER_STOP_ON_FREE_BIT),
TRACE_ITER_IRQ_INFO = (1 << TRACE_ITER_IRQ_INFO_BIT),
TRACE_ITER_MARKERS = (1 << TRACE_ITER_MARKERS_BIT),
TRACE_ITER_FUNCTION = (1 << TRACE_ITER_FUNCTION_BIT),
TRACE_ITER_DISPLAY_GRAPH = (1 << TRACE_ITER_DISPLAY_GRAPH_BIT),
};
/* /*
* TRACE_ITER_SYM_MASK masks the options in trace_flags that * TRACE_ITER_SYM_MASK masks the options in trace_flags that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment