diff mbox

[i-g-t,2/3] igt/igt_core: Provide an option to check for the log buffer contents

Message ID 1496739254-18898-2-git-send-email-abdiel.janulgue@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Abdiel Janulgue June 6, 2017, 8:54 a.m. UTC
Signed-off-by: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
---
 lib/igt_core.c | 24 ++++++++++++++++++++++++
 lib/igt_core.h |  3 +++
 2 files changed, 27 insertions(+)

Comments

Arkadiusz Hiler June 12, 2017, 11:48 a.m. UTC | #1
On Tue, Jun 06, 2017 at 11:54:13AM +0300, Abdiel Janulgue wrote:
> Signed-off-by: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
> ---
>  lib/igt_core.c | 24 ++++++++++++++++++++++++
>  lib/igt_core.h |  3 +++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 26f7fc5..94f5529 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -329,6 +329,30 @@ static void _igt_log_buffer_dump(void)
>  	pthread_mutex_unlock(&log_buffer_mutex);
>  }
>  
> +/**
> + * igt_log_buffer_inspect:
> + *
> + * Provides a way to replay the internal igt log buffer for inspection.
> + * @check: A user-specified handler that gets invoked for each line of
> +           the log buffer. The handler should return true to stop
> +           inspecting the rest of the buffer.

Looks like we have an asterisk even for the indented lines elsewhere.

With the above nitpick
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
diff mbox

Patch

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 26f7fc5..94f5529 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -329,6 +329,30 @@  static void _igt_log_buffer_dump(void)
 	pthread_mutex_unlock(&log_buffer_mutex);
 }
 
+/**
+ * igt_log_buffer_inspect:
+ *
+ * Provides a way to replay the internal igt log buffer for inspection.
+ * @check: A user-specified handler that gets invoked for each line of
+           the log buffer. The handler should return true to stop
+           inspecting the rest of the buffer.
+ * @data: passed as a user argument to the inspection function.
+ */
+void igt_log_buffer_inspect(igt_buffer_log_handler_t check, void *data)
+{
+	uint8_t i;
+	pthread_mutex_lock(&log_buffer_mutex);
+
+	i = log_buffer.start;
+	do {
+		if (check(log_buffer.entries[i], data))
+			break;
+		i++;
+	} while (i != log_buffer.start && i != log_buffer.end);
+
+	pthread_mutex_unlock(&log_buffer_mutex);
+}
+
 __attribute__((format(printf, 1, 2)))
 static void kmsg(const char *format, ...)
 #define KERN_EMER	"<0>"
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 1855c5e..a2ed972 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -818,6 +818,9 @@  void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
  */
 #define igt_critical(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_CRITICAL, f)
 
+typedef bool (*igt_buffer_log_handler_t)(const char *line, void *data);
+void igt_log_buffer_inspect(igt_buffer_log_handler_t check, void *data);
+
 extern enum igt_log_level igt_log_level;
 
 /**