[v3,23/33] eal/trace: add trace level configuration parameter
diff mbox series

Message ID 20200329144342.1543749-24-jerinj@marvell.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • DPDK Trace support
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Jerin Jacob March 29, 2020, 2:43 p.m. UTC
From: Sunil Kumar Kori <skori@marvell.com>

Trace library exposes --trace-level EAL parameter to configure
global and trace point specific level.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
 doc/guides/linux_gsg/eal_args.include.rst     |  19 ++++
 lib/librte_eal/common/eal_common_options.c    |  19 +++-
 lib/librte_eal/common/eal_common_trace.c      |  10 ++
 .../common/eal_common_trace_utils.c           | 104 ++++++++++++++++++
 lib/librte_eal/common/eal_options.h           |   2 +
 lib/librte_eal/common/eal_private.h           |   3 +
 lib/librte_eal/common/eal_trace.h             |  11 +-
 7 files changed, 166 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/doc/guides/linux_gsg/eal_args.include.rst b/doc/guides/linux_gsg/eal_args.include.rst
index ed8b0e35b..94289d1e2 100644
--- a/doc/guides/linux_gsg/eal_args.include.rst
+++ b/doc/guides/linux_gsg/eal_args.include.rst
@@ -136,6 +136,25 @@  Debugging options
 
     Can be specified multiple times.
 
+*   ``--trace-level=<val> | <*type*:val> | <type, val>``
+
+    Specify trace level for global or specific component, based on pattern or
+    regular expression matching. For example:
+
+    Global trace level configuration::
+
+        --trace-level=8
+
+    Global trace level configuration for EAL only using pattern match::
+
+        --trace-level=*eal*:8
+
+    Global trace level configuration for EAL only using regexp match::
+
+        --trace-level=eal,8
+
+    Can be specified multiple times up to 32 times.
+
 Other options
 ~~~~~~~~~~~~~
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 525e51e7d..0d6576a12 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -34,6 +34,7 @@ 
 #include "eal_options.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
+#include "eal_trace.h"
 
 #define BITS_PER_HEX 4
 #define LCORE_OPT_LST 1
@@ -67,6 +68,7 @@  eal_long_options[] = {
 	{OPT_IOVA_MODE,	        1, NULL, OPT_IOVA_MODE_NUM        },
 	{OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
+	{OPT_TRACE_LEVEL,       1, NULL, OPT_TRACE_LEVEL_NUM      },
 	{OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
 	{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
 	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
@@ -976,7 +978,7 @@  eal_parse_syslog(const char *facility, struct internal_config *conf)
 }
 #endif
 
-static int
+int
 eal_parse_log_priority(const char *level)
 {
 	static const char * const levels[] = {
@@ -1418,6 +1420,16 @@  eal_parse_common_option(int opt, const char *optarg,
 		}
 		break;
 	}
+
+	case OPT_TRACE_LEVEL_NUM: {
+		if (eal_trace_level_args_save(optarg) < 0) {
+			RTE_LOG(ERR, EAL, "invalid parameters for --"
+				OPT_TRACE_LEVEL "\n");
+			return -1;
+		}
+		break;
+	}
+
 	case OPT_LCORES_NUM:
 		if (eal_parse_lcores(optarg) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1693,6 +1705,11 @@  eal_common_usage(void)
 	       "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
 	       "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
 	       "                      Set specific log level\n"
+	       "  --"OPT_TRACE_LEVEL"=<int> Set global trace level\n"
+	       "  --"OPT_TRACE_LEVEL"=<type-match>:<int>\n"
+	       "                    Set trace level specific to component\n"
+	       "                    Default, there is no trace level enabled\n"
+	       "                    User must specify this option if required\n"
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
 	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index 840cab5a1..075d17528 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -38,6 +38,8 @@  trace_list_head_get(void)
 int
 eal_trace_init(void)
 {
+	uint8_t i;
+
 	/* Trace memory should start with 8B aligned for natural alignment */
 	RTE_BUILD_BUG_ON((offsetof(struct __rte_trace_header, mem) % 8) != 0);
 
@@ -47,6 +49,9 @@  eal_trace_init(void)
 		goto fail;
 	}
 
+	if (trace.args.nb_args)
+		trace.global_status = true;
+
 	if (rte_trace_global_is_disabled())
 		return 0;
 
@@ -71,6 +76,10 @@  eal_trace_init(void)
 	if (trace_epoch_time_save() < 0)
 		goto fail;
 
+	/* Apply global configurations */
+	for (i = 0; i < trace.args.nb_args; i++)
+		trace_level_args_apply(trace.args.args[i]);
+
 	rte_trace_global_mode_set(trace.mode);
 
 	return 0;
@@ -89,6 +98,7 @@  eal_trace_fini(void)
 		return;
 	trace_mem_per_thread_free();
 	trace_metadata_destroy();
+	eal_trace_level_args_free();
 }
 
 bool
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 64e7a7cfa..1f47faed4 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -118,6 +118,110 @@  trace_session_name_generate(char *trace_dir)
 	return -rte_errno;
 }
 
+int
+eal_trace_level_args_save(const char *optarg)
+{
+	struct trace *trace = trace_obj_get();
+	char *trace_args;
+	uint8_t nb_args;
+
+	nb_args = trace->args.nb_args;
+
+	if (nb_args >= TRACE_LEVEL_MAX_ARGS) {
+		trace_err("ignoring trace level %s as limit exceeds", optarg);
+		return 0;
+	}
+
+	trace_args = calloc(1, (strlen(optarg) + 1));
+	if (trace_args == NULL) {
+		trace_err("fail to allocate memory for %s", optarg);
+		return -ENOMEM;
+	}
+
+	memcpy(trace_args, optarg, strlen(optarg));
+	trace->args.args[nb_args++] = trace_args;
+	trace->args.nb_args = nb_args;
+	return 0;
+}
+
+void
+eal_trace_level_args_free(void)
+{
+	struct trace *trace = trace_obj_get();
+	int i;
+
+	for (i = 0; i < trace->args.nb_args; i++) {
+		if (trace->args.args[i]) {
+			free((void *)trace->args.args[i]);
+			trace->args.args[i] = NULL;
+		}
+	}
+}
+
+int
+trace_level_args_apply(const char *arg)
+{
+	struct trace *trace = trace_obj_get();
+	const char *pattern = NULL;
+	const char *regex = NULL;
+	char *str, *level;
+	int level_idx;
+
+	str = strdup(arg);
+	if (str == NULL)
+		return -1;
+
+	level = strchr(str, ',');
+	if (level) {
+		regex = str;
+		*level++ = '\0';
+		goto found;
+	}
+
+	level = strchr(str, ':');
+	if (level) {
+		pattern = str;
+		*level++ = '\0';
+		goto found;
+	}
+
+	level = str;
+
+found:
+	level_idx = eal_parse_log_priority(level);
+	if (level_idx < 0) {
+		trace_err("invalid trace level: %s\n", level);
+		goto fail;
+	}
+
+	/* Update global level */
+	trace->level = level_idx;
+
+	if (regex) {
+		if (rte_trace_regexp(regex, true) < 0) {
+			trace_err("cannot set trace level %s:%d\n",
+				regex, level_idx);
+			goto fail;
+		}
+
+	} else if (pattern) {
+		if (rte_trace_pattern(pattern, true) < 0) {
+			trace_err("cannot set trace level %s:%d\n",
+				pattern, level_idx);
+			goto fail;
+		}
+	} else {
+		rte_trace_global_level_set(level_idx);
+	}
+
+	free(str);
+	return 0;
+
+fail:
+	free(str);
+	return -1;
+}
+
 int
 trace_epoch_time_save(void)
 {
diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
index 9855429e5..c274a30cc 100644
--- a/lib/librte_eal/common/eal_options.h
+++ b/lib/librte_eal/common/eal_options.h
@@ -33,6 +33,8 @@  enum {
 	OPT_LCORES_NUM,
 #define OPT_LOG_LEVEL         "log-level"
 	OPT_LOG_LEVEL_NUM,
+#define OPT_TRACE_LEVEL       "trace-level"
+	OPT_TRACE_LEVEL_NUM,
 #define OPT_MASTER_LCORE      "master-lcore"
 	OPT_MASTER_LCORE_NUM,
 #define OPT_MBUF_POOL_OPS_NAME "mbuf-pool-ops-name"
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index f61f52eff..1876bc01e 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -446,6 +446,9 @@  eal_get_baseaddr(void);
 const char *
 eal_loglevel_to_string(uint32_t level);
 
+int
+eal_parse_log_priority(const char *level);
+
 void *
 eal_malloc_no_trace(const char *type, size_t size, unsigned int align);
 
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 848d1dfc0..acdc8ecab 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -28,7 +28,7 @@ 
 #define TRACE_CTF_FIELD_SIZE 384
 #define TRACE_POINT_NAME_SIZE 64
 #define TRACE_CTF_MAGIC 0xC1FC1FC1
-
+#define TRACE_LEVEL_MAX_ARGS	32
 
 struct trace_point {
 	STAILQ_ENTRY(trace_point) next;
@@ -47,6 +47,11 @@  struct thread_mem_meta {
 	enum trace_area_e area;
 };
 
+struct trace_args {
+	uint8_t nb_args;
+	char *args[TRACE_LEVEL_MAX_ARGS];
+};
+
 struct trace {
 	char dir[PATH_MAX];
 	int dir_offset;
@@ -56,6 +61,7 @@  struct trace {
 	rte_uuid_t uuid;
 	uint32_t buff_len;
 	uint32_t level;
+	struct trace_args args;
 	uint32_t nb_trace_points;
 	uint32_t nb_trace_mem_list;
 	struct thread_mem_meta *lcore_meta;
@@ -94,6 +100,7 @@  struct trace_point_head *trace_list_head_get(void);
 /* Util functions */
 const char *trace_mode_to_string(enum rte_trace_mode mode);
 const char *trace_area_to_string(enum trace_area_e area);
+int trace_level_args_apply(const char *arg);
 bool trace_has_duplicate_entry(void);
 void trace_uuid_generate(void);
 int trace_metadata_create(void);
@@ -105,5 +112,7 @@  void trace_mem_per_thread_free(void);
 /* EAL interface */
 int eal_trace_init(void);
 void eal_trace_fini(void);
+int eal_trace_level_args_save(const char *optarg);
+void eal_trace_level_args_free(void);
 
 #endif /* __EAL_TRACE_H */