diff mbox series

[3/7] ndctl: cxl: add common function to enable event trace

Message ID 166318848691.3087953.726606131511690601.stgit@djiang5-desk3.ch.intel.com
State Superseded
Delegated to: Vishal Verma
Headers show
Series ndctl: cxl: add monitor support for trace events | expand

Commit Message

Dave Jiang Sept. 14, 2022, 8:48 p.m. UTC
Add a common function for cxl command to enable event tracing for the
instance created. The interested "systems" will be enabled for tracing
as well.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 cxl/event_trace.c |   27 +++++++++++++++++++++++++++
 cxl/event_trace.h |    1 +
 2 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/cxl/event_trace.c b/cxl/event_trace.c
index d5e67b55a4d8..39ca5a9c49be 100644
--- a/cxl/event_trace.c
+++ b/cxl/event_trace.c
@@ -199,3 +199,30 @@  int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx)
 	tep_free(tep);
 	return rc;
 }
+
+int cxl_event_tracing_enable(struct tracefs_instance *inst, const char **systems)
+{
+	int rc, i, en_count = 0;
+
+	for (i = 0; systems[i]; i++) {
+		char *path;
+
+		rc = asprintf(&path, "events/%s/enable", systems[i]);
+		if (rc == -1)
+			continue;
+		rc = tracefs_instance_file_write(inst, path, "1");
+		free(path);
+		if (rc == -1)
+			continue;
+		en_count++;
+	}
+
+	if (!en_count)
+		return -ENOENT;
+
+	if (tracefs_trace_is_on(inst))
+		return 0;
+
+	tracefs_trace_on(inst);
+	return 0;
+}
diff --git a/cxl/event_trace.h b/cxl/event_trace.h
index 98cfbb4602e1..b4453c393e7a 100644
--- a/cxl/event_trace.h
+++ b/cxl/event_trace.h
@@ -17,5 +17,6 @@  struct event_ctx {
 };
 
 int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx);
+int cxl_event_tracing_enable(struct tracefs_instance *inst, const char **systems);
 
 #endif