[igt-dev] [PATCH i-g-t 3/7] lib/igt_core: add prefix to logging

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Mon Dec 5 06:12:08 UTC 2022


On Fri,  2 Dec 2022 21:57:01 +0100
Kamil Konieczny <kamil.konieczny at linux.intel.com> wrote:

> Allow to store prefix for logs and print it before any message.
> This will allow to diagnose on wich GPU occurred problems when
> tested on multi-GPU machines.
> 
> Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>

Reviewed-by: Mauro Carvalho Chehab <mchehab at kernel.org>

> ---
>  lib/igt_core.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 68ae7289..65b7be64 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -348,6 +348,8 @@ static struct {
>  	uint8_t start, end;
>  } log_buffer;
>  static pthread_mutex_t log_buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
> +#define LOG_PREFIX_SIZE 32
> +char log_prefix[LOG_PREFIX_SIZE] = { 0 };
>  
>  GKeyFile *igt_key_file;
>  
> @@ -3105,8 +3107,12 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
>  	program_name = command_str;
>  #endif
>  
> -	if (asprintf(&thread_id, "[thread:%d] ", gettid()) == -1)
> -		thread_id = NULL;
> +	if (igt_thread_is_main()) {
> +		thread_id = strdup(log_prefix);
> +	} else {
> +		if (asprintf(&thread_id, "%s[thread:%d] ", log_prefix, gettid()) == -1)
> +			thread_id = NULL;
> +	}
>  
>  	if (!thread_id)
>  		return;


More information about the igt-dev mailing list