diff mbox series

[ndctl,18/37] cxl/list: Add --debug option

Message ID 164298560409.3021641.11040422738199381922.stgit@dwillia2-desk3.amr.corp.intel.com
State New, archived
Headers show
Series cxl: Full topology enumeration | expand

Commit Message

Dan Williams Jan. 24, 2022, 12:53 a.m. UTC
Add an option to turn on libray and cxl_filter_walk() messages. Gate it
based on the global ENABLE_DEBUG configuration setting.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 Documentation/cxl/cxl-list.txt |    6 ++++--
 cxl/filter.c                   |    3 +++
 cxl/list.c                     |    9 +++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
index 3076deb43b9e..42b6de6e5c61 100644
--- a/Documentation/cxl/cxl-list.txt
+++ b/Documentation/cxl/cxl-list.txt
@@ -200,9 +200,11 @@  OPTIONS
 	descendants of the individual ports that match the filter. By default
 	all descendant objects are listed.
 
-include::human-option.txt[]
+--debug::
+	If the cxl tool was built with debug enabled, turn on debug
+	messages.
 
-include::verbose-option.txt[]
+include::human-option.txt[]
 
 include::../copyright.txt[]
 
diff --git a/cxl/filter.c b/cxl/filter.c
index 8b79db3dae8d..32171a47e8d5 100644
--- a/cxl/filter.c
+++ b/cxl/filter.c
@@ -387,6 +387,7 @@  int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *p)
 	if (!jports)
 		goto err;
 
+	dbg(p, "walk memdevs\n");
 	cxl_memdev_foreach(ctx, memdev) {
 		struct json_object *jdev;
 
@@ -403,6 +404,7 @@  int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *p)
 		}
 	}
 
+	dbg(p, "walk buses\n");
 	cxl_bus_foreach(ctx, bus) {
 		struct json_object *jbus = NULL;
 		struct json_object *jchildports = NULL;
@@ -431,6 +433,7 @@  int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *p)
 			}
 		}
 walk_children:
+		dbg(p, "walk ports\n");
 		walk_child_ports(port, p, pick_array(jchildports, jports),
 				 flags);
 		cond_add_put_array_suffix(jbus, "ports", devname, jchildports);
diff --git a/cxl/list.c b/cxl/list.c
index 1ef91b44dca1..01ab19bff706 100644
--- a/cxl/list.c
+++ b/cxl/list.c
@@ -13,6 +13,7 @@ 
 #include "filter.h"
 
 static struct cxl_filter_params param;
+static bool debug;
 
 static const struct option options[] = {
 	OPT_STRING('m', "memdev", &param.memdev_filter, "memory device name(s)",
@@ -35,6 +36,9 @@  static const struct option options[] = {
 		    "use human friendly number formats "),
 	OPT_BOOLEAN('H', "health", &param.health,
 		    "include memory device health information "),
+#ifdef ENABLE_DEBUG
+	OPT_BOOLEAN(0, "debug", &debug, "debug list walk"),
+#endif
 	OPT_END(),
 };
 
@@ -84,9 +88,14 @@  int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
 	}
 
 	log_init(&param.ctx, "cxl list", "CXL_LIST_LOG");
+	if (debug) {
+		cxl_set_log_priority(ctx, LOG_DEBUG);
+		param.ctx.log_priority = LOG_DEBUG;
+	}
 
 	if (cxl_filter_has(param.port_filter, "root") && param.ports)
 		param.buses = true;
 
+	dbg(&param, "walk topology\n");
 	return cxl_filter_walk(ctx, &param);
 }