mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-12 10:26:12 +00:00
lib: add a ring buffer for log entries
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
This commit is contained in:
parent
89201c5328
commit
a5f21726cd
@ -11,7 +11,8 @@ noinst_HEADERS = check-ndebug.h
|
|||||||
AM_CPPFLAGS = -I$(top_srcdir)
|
AM_CPPFLAGS = -I$(top_srcdir)
|
||||||
AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
|
AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
|
||||||
-DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
|
-DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
|
||||||
-DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\"
|
-DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\" \
|
||||||
|
-pthread
|
||||||
|
|
||||||
|
|
||||||
LDADD = $(CAIRO_LIBS)
|
LDADD = $(CAIRO_LIBS)
|
||||||
|
@ -47,9 +47,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#else
|
|
||||||
#include <pthread.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <pthread.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -239,6 +238,35 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char* igt_log_domain_filter;
|
static char* igt_log_domain_filter;
|
||||||
|
static struct {
|
||||||
|
char *entries[256];
|
||||||
|
uint8_t start, end;
|
||||||
|
} log_buffer;
|
||||||
|
static pthread_mutex_t log_buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
static void _igt_log_buffer_append(char *line)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&log_buffer_mutex);
|
||||||
|
|
||||||
|
free(log_buffer.entries[log_buffer.end]);
|
||||||
|
log_buffer.entries[log_buffer.end] = line;
|
||||||
|
log_buffer.end++;
|
||||||
|
if (log_buffer.end == log_buffer.start)
|
||||||
|
log_buffer.start++;
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&log_buffer_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _igt_log_buffer_reset(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&log_buffer_mutex);
|
||||||
|
|
||||||
|
log_buffer.start = log_buffer.end = 0;
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&log_buffer_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__attribute__((format(printf, 1, 2)))
|
__attribute__((format(printf, 1, 2)))
|
||||||
static void kmsg(const char *format, ...)
|
static void kmsg(const char *format, ...)
|
||||||
@ -734,6 +762,8 @@ bool __igt_run_subtest(const char *subtest_name)
|
|||||||
kmsg(KERN_INFO "%s: starting subtest %s\n", command_str, subtest_name);
|
kmsg(KERN_INFO "%s: starting subtest %s\n", command_str, subtest_name);
|
||||||
igt_debug("Starting subtest: %s\n", subtest_name);
|
igt_debug("Starting subtest: %s\n", subtest_name);
|
||||||
|
|
||||||
|
_igt_log_buffer_reset();
|
||||||
|
|
||||||
gettime(&subtest_time);
|
gettime(&subtest_time);
|
||||||
return (in_subtest = subtest_name);
|
return (in_subtest = subtest_name);
|
||||||
}
|
}
|
||||||
@ -1532,6 +1562,7 @@ void igt_log(const char *domain, enum igt_log_level level, const char *format, .
|
|||||||
void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args)
|
void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
char *line, *formatted_line;
|
||||||
const char *program_name;
|
const char *program_name;
|
||||||
const char *igt_log_level_str[] = {
|
const char *igt_log_level_str[] = {
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
@ -1552,18 +1583,33 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
|
|||||||
if (list_subtests && level <= IGT_LOG_WARN)
|
if (list_subtests && level <= IGT_LOG_WARN)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (igt_log_level > level)
|
if (vasprintf(&line, format, args) == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (asprintf(&formatted_line, "(%s:%d) %s%s%s: %s", program_name,
|
||||||
|
getpid(), (domain) ? domain : "", (domain) ? "-" : "",
|
||||||
|
igt_log_level_str[level], line) == -1) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* append log buffer */
|
||||||
|
_igt_log_buffer_append(formatted_line);
|
||||||
|
|
||||||
|
/* check print log level */
|
||||||
|
if (igt_log_level > level)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* check domain filter */
|
||||||
if (igt_log_domain_filter) {
|
if (igt_log_domain_filter) {
|
||||||
/* if null domain and filter is not "application", return */
|
/* if null domain and filter is not "application", return */
|
||||||
if (!domain && strcmp(igt_log_domain_filter, "application"))
|
if (!domain && strcmp(igt_log_domain_filter, "application"))
|
||||||
return;
|
goto out;
|
||||||
/* else if domain and filter do not match, return */
|
/* else if domain and filter do not match, return */
|
||||||
else if (domain && strcmp(igt_log_domain_filter, domain))
|
else if (domain && strcmp(igt_log_domain_filter, domain))
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* use stderr for warning messages and above */
|
||||||
if (level >= IGT_LOG_WARN) {
|
if (level >= IGT_LOG_WARN) {
|
||||||
file = stderr;
|
file = stderr;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -1571,12 +1617,16 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
|
|||||||
else
|
else
|
||||||
file = stdout;
|
file = stdout;
|
||||||
|
|
||||||
if (level != IGT_LOG_INFO) {
|
/* prepend all except information messages with process, domain and log
|
||||||
fprintf(file, "(%s:%d) %s%s%s: ", program_name, getpid(),
|
* level information */
|
||||||
(domain) ? domain : "", (domain) ? "-" : "",
|
if (level != IGT_LOG_INFO)
|
||||||
igt_log_level_str[level]);
|
fwrite(formatted_line, sizeof(char), strlen(formatted_line),
|
||||||
}
|
file);
|
||||||
vfprintf(file, format, args);
|
else
|
||||||
|
fwrite(line, sizeof(char), strlen(line), file);
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void igt_alarm_handler(int signal)
|
static void igt_alarm_handler(int signal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user