[igt-dev] [PATCH i-g-t 2/3] lib: Add more debugfs and ftrace helpers

Ashutosh Dixit ashutosh.dixit at intel.com
Tue Apr 2 02:44:20 UTC 2019


Add functions to:
* enable/disable dynamic debug using <debugfs>/dynamic_debug/control
* set ftrace events for the nop tracer
* clear the ftrace buffer

Signed-off-by: Ashutosh Dixit <ashutosh.dixit at intel.com>
---
 lib/igt_debugfs.c | 24 ++++++++++++++++++++++++
 lib/igt_debugfs.h |  1 +
 lib/igt_ftrace.c  | 39 ++++++++++++++++++++++++++++++++++++---
 lib/igt_ftrace.h  |  4 ++++
 4 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index dd229c09..cf08a0a3 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -367,6 +367,30 @@ bool igt_debugfs_search(int device, const char *filename, const char *substring)
 	return matched;
 }
 
+/* Echo array of strings into <debugfs>/dynamic_debug/control */
+int igt_set_dynamic_debug(const char **str, int nstr)
+{
+	int debugfs, dyn, err, i;
+
+	debugfs = open(igt_debugfs_mount(), O_RDONLY);
+	if (debugfs < 0)
+		return -errno;
+
+	dyn = openat(debugfs, "dynamic_debug", O_RDONLY);
+	close(debugfs);
+	if (dyn < 0)
+		return -errno;
+
+	for (i = 0; i < nstr; i++) {
+		err = igt_sysfs_set(dyn, "control", str[i]);
+		if (err < 0)
+			return -errno;
+	}
+
+	close(dyn);
+	return 0;
+}
+
 /*
  * Pipe CRC
  */
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index f8e57a6b..74bfae5b 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -41,6 +41,7 @@ int igt_debugfs_open(int fd, const char *filename, int mode);
 void __igt_debugfs_read(int fd, const char *filename, char *buf, int size);
 int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size);
 bool igt_debugfs_search(int fd, const char *filename, const char *substring);
+int igt_set_dynamic_debug(const char **str, int nstr);
 
 /**
  * igt_debugfs_read:
diff --git a/lib/igt_ftrace.c b/lib/igt_ftrace.c
index 43f396d6..1f02e1da 100644
--- a/lib/igt_ftrace.c
+++ b/lib/igt_ftrace.c
@@ -139,7 +139,7 @@ int __igt_ftrace_enable(const char *mode,
 		igt_ftrace.flags |= EXCLUDE_SET;
 	}
 
-	err = igt_sysfs_set(igt_ftrace.dir, "tracer_on", "1");
+	err = igt_sysfs_set(igt_ftrace.dir, "tracing_on", "1");
 	if (err < 0)
 		return err;
 
@@ -157,7 +157,7 @@ int igt_ftrace_disable(void)
 	if (igt_ftrace.dir < 0)
 		return -ENODEV;
 
-	err = igt_sysfs_set(igt_ftrace.dir, "tracer_on", "0");
+	err = igt_sysfs_set(igt_ftrace.dir, "tracing_on", "0");
 	if (err < 0)
 		return err;
 
@@ -179,6 +179,24 @@ int igt_ftrace_disable(void)
 	return 0;
 }
 
+/* Implement 'echo 0/1 > <debugfs>/tracing/str[i]' */
+int igt_ftrace_set_events(const char **str, int nstr, bool enable)
+{
+	int i, ret, err = 0;
+
+	if (igt_ftrace.dir < 0)
+		return -ENODEV;
+
+	for (i = 0; i < nstr; i++) {
+		ret = igt_sysfs_set(igt_ftrace.dir, str[i],
+				    enable ? "1\n" : "0\n");
+		if (ret)
+			err = ret;
+	}
+
+	return err;
+}
+
 void igt_ftrace_dump(const char *header)
 {
 	char *txt;
@@ -190,10 +208,25 @@ void igt_ftrace_dump(const char *header)
 	if (!txt)
 		return;
 
-	igt_info("%s:\n%s", header, txt);
+	igt_info("%s:\n%s\n", header, txt);
 	free(txt);
 }
 
+/* Implement the equivalent of 'echo > <debugfs>/tracing/trace' */
+int igt_ftrace_clear(void)
+{
+	int fd;
+
+	if (igt_ftrace.dir < 0)
+		return -ENODEV;
+
+	fd = openat(igt_ftrace.dir, "trace", O_WRONLY | O_TRUNC);
+	if (fd < 0)
+		return -errno;
+	close(fd);
+	return 0;
+}
+
 void igt_ftrace_close(void)
 {
 	if (igt_ftrace.dir < 0)
diff --git a/lib/igt_ftrace.h b/lib/igt_ftrace.h
index 9aceeca9..6f4225ee 100644
--- a/lib/igt_ftrace.h
+++ b/lib/igt_ftrace.h
@@ -39,8 +39,12 @@ int __igt_ftrace_enable(const char *mode,
 
 int igt_ftrace_disable(void);
 
+int igt_ftrace_set_events(const char **str, int nstr, bool enable);
+
 void igt_ftrace_dump(const char *header);
 
+int igt_ftrace_clear(void);
+
 void igt_ftrace_close(void);
 
 #endif /* IGT_FTRACE_H */
-- 
2.21.0



More information about the igt-dev mailing list