[igt-dev] [PATCH i-g-t] lib: Add igt_trace()

Ville Syrjala ville.syrjala at linux.intel.com
Mon Oct 14 15:08:17 UTC 2019


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Add igt_trace() which can be used to inject messages into the
kernel ftrace buffer via the trace_marker file. Quite useful when
trying to correlate test case activity with kernel tracepoints.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_core.c | 16 ++++++++++++++++
 lib/igt_core.h |  9 +++++++++
 2 files changed, 25 insertions(+)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 940913c185ee..6a9c036393ac 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -421,6 +421,22 @@ void igt_kmsg(const char *format, ...)
 	fclose(file);
 }
 
+void igt_trace(const char *format, ...)
+{
+	va_list ap;
+	FILE *file;
+
+	file = fopen("/sys/kernel/debug/tracing/trace_marker", "w");
+	if (file == NULL)
+		return;
+
+	va_start(ap, format);
+	vfprintf(file, format, ap);
+	va_end(ap);
+
+	fclose(file);
+}
+
 #define time_valid(ts) ((ts)->tv_sec || (ts)->tv_nsec)
 
 double igt_time_elapsed(struct timespec *then,
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 521cda10f6fa..e8b61128680d 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -1190,6 +1190,15 @@ int igt_system_quiet(const char *command);
 		free(buf); \
 	} while (0)
 
+/**
+ * igt_trace:
+ * @format: printf-style format string with optional args
+ *
+ * Writes a message into the kernel trace log.
+ */
+__attribute__((format(printf, 1, 2)))
+void igt_trace(const char *format, ...);
+
 /**
  * igt_kmsg:
  * @format: printf-style format string with optional args
-- 
2.21.0



More information about the igt-dev mailing list