Skip to contentSkip to conversation

libtracefs: Minor formating updates to options code

PATCH New Steven Rostedt 1 participant 3 messages Feb 2, 2021

lore
Share & tools
lore
#0 lore raw

cover libtracefs: Minor formating updates to options code

This is based on top of the options patches:

https://patchwork.kernel.org/project/linux-trace-devel/list/?series=418299

This adds a BUILD_BUG_ON() and ARRAY_SIZE helper macros and structures the options_map slightly different.

No functional changes.

Steven Rostedt (VMware) (2):
tracefs: Use new BUILD_BUG_ON() and ARRAY_SIZE() macros for options_map intergity
libtracefs: Have the options_map elements be each on their own line

----

 include/tracefs-local.h |  6 ++++++
 src/tracefs-tools.c     | 56 ++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 52 insertions(+), 10 deletions(-)
#2 lore raw

PATCH 2/2 libtracefs: Have the options_map elements be each on their own line

From: "Steven Rostedt (VMware)" <[email protected]>

In order to verify the order of the option names in the options_map array, have each name on its own line. This is much easier to see the mapping when compared to the enums in tracefs_options_id that represent them.

No function changes.

---
 src/tracefs-tools.c | 51 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 9 deletions(-)
src/tracefs-tools.c +42 -9
index 7f69cde93115..e2dfc7b8acff 100644
@@ -20,15 +20,48 @@
 #define TRACE_CTRL	"tracing_on"
 
 static const char * const options_map[] = {
-	"unknown", "annotate", "bin", "blk_cgname", "blk_cgroup", "blk_classic",
-	"block", "context-info", "disable_on_free", "display-graph", "event-fork",
-	"funcgraph-abstime", "funcgraph-cpu", "funcgraph-duration", "funcgraph-irqs",
-	"funcgraph-overhead", "funcgraph-overrun", "funcgraph-proc", "funcgraph-tail",
-	"func_stack_trace", "function-fork", "function-trace", "graph-time", "hex",
-	"irq-info", "latency-format", "markers", "overwrite", "pause-on-trace",
-	"printk-msg-only", "print-parent", "raw", "record-cmd", "record-tgid",
-	"sleep-time", "stacktrace", "sym-addr", "sym-offset", "sym-userobj",
-	"trace_printk", "userstacktrace", "verbose" };
+	"unknown",
+	"annotate",
+	"bin",
+	"blk_cgname",
+	"blk_cgroup",
+	"blk_classic",
+	"block",
+	"context-info",
+	"disable_on_free",
+	"display-graph",
+	"event-fork",
+	"funcgraph-abstime",
+	"funcgraph-cpu",
+	"funcgraph-duration",
+	"funcgraph-irqs",
+	"funcgraph-overhead",
+	"funcgraph-overrun",
+	"funcgraph-proc",
+	"funcgraph-tail",
+	"func_stack_trace",
+	"function-fork",
+	"function-trace",
+	"graph-time",
+	"hex",
+	"irq-info",
+	"latency-format",
+	"markers",
+	"overwrite",
+	"pause-on-trace",
+	"printk-msg-only",
+	"print-parent",
+	"raw",
+	"record-cmd",
+	"record-tgid",
+	"sleep-time",
+	"stacktrace",
+	"sym-addr",
+	"sym-offset",
+	"sym-userobj",
+	"trace_printk",
+	"userstacktrace",
+	"verbose" };
 
 static int trace_on_off(int fd, bool on)
 {
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/2 tracefs: Use new BUILD_BUG_ON() and ARRAY_SIZE() macros for options_map intergity

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Instead of having the options_map use TRACEFS_OPTIONS_MAX as its index, have the array extend by the elements, and use the new macros BUILD_BUG_ON() and ARRAY_SIZE() to make sure that the array always is the same size as the TRACEFS_OPTIONS_MAX.

No functional changes.

---
 include/tracefs-local.h | 6 ++++++
 src/tracefs-tools.c     | 5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
include/tracefs-local.h +6 -0
index 3a7ec32a8853..187870e7c491 100644
@@ -8,6 +8,12 @@
 
 #define __hidden __attribute__((visibility ("hidden")))
 
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+
+/* Will cause a division by zero warning if cond is true */
+#define BUILD_BUG_ON(cond)			\
+	do { if (!(1/!(cond))) { } } while (0)
+
 /* Can be overridden */
 void warning(const char *fmt, ...);
 
src/tracefs-tools.c +4 -1
index 6e7fce53cef1..7f69cde93115 100644
@@ -19,7 +19,7 @@
 
 #define TRACE_CTRL	"tracing_on"
 
-static const char * const options_map[TRACEFS_OPTION_MAX] = {
+static const char * const options_map[] = {
 	"unknown", "annotate", "bin", "blk_cgname", "blk_cgroup", "blk_classic",
 	"block", "context-info", "disable_on_free", "display-graph", "event-fork",
 	"funcgraph-abstime", "funcgraph-cpu", "funcgraph-duration", "funcgraph-irqs",
@@ -132,6 +132,9 @@ int tracefs_trace_off_fd(int fd)
  */
 const char *tracefs_option_name(enum tracefs_option_id id)
 {
+	/* Make sure options map contains all the options */
+	BUILD_BUG_ON(ARRAY_SIZE(options_map) != TRACEFS_OPTION_MAX);
+
 	if (id < TRACEFS_OPTION_MAX)
 		return options_map[id];
 
Signature · 1 line
2.29.2