From 8028aef65428e3c2b3f6b0cbe9f290c34a896310 Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Wed, 26 Feb 2020 14:16:10 +0100 Subject: [PATCH] feat: log disabling planes without line breaks Enumerating all planes to be disabled makes the log unnecessary sparse. Instead just list all planes in a single line. For that introduce new API function to log something without line break in the end and adapt the log callback function pointer. BREAKING CHANGE: log callback function arguments change. --- alloc.c | 5 +++-- include/libliftoff.h | 2 +- include/log.h | 2 ++ log.c | 20 +++++++++++++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/alloc.c b/alloc.c index 6f5526f..1eeff0d 100644 --- a/alloc.c +++ b/alloc.c @@ -614,16 +614,17 @@ bool liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req) /* Disable all planes. Do it before building mappings to make sure not to hit bandwidth limits because too many planes are enabled. */ + liftoff_log_cnt(LIFTOFF_DEBUG, "Disabling planes:"); liftoff_list_for_each(plane, &device->planes, link) { if (plane->layer == NULL) { - liftoff_log(LIFTOFF_DEBUG, - "Disabling plane %"PRIu32, plane->id); + liftoff_log_cnt(LIFTOFF_DEBUG, " %"PRIu32, plane->id); if (!plane_apply(plane, NULL, req, &compatible)) { return false; } assert(compatible); } } + liftoff_log_cnt(LIFTOFF_DEBUG, "\n"); result.req = req; result.planes_len = liftoff_list_length(&device->planes); diff --git a/include/libliftoff.h b/include/libliftoff.h index f3ec515..adb9e34 100644 --- a/include/libliftoff.h +++ b/include/libliftoff.h @@ -74,7 +74,7 @@ enum liftoff_log_importance { LIFTOFF_DEBUG, }; -typedef void (*liftoff_log_func)(enum liftoff_log_importance importance, +typedef void (*liftoff_log_func)(enum liftoff_log_importance importance, bool newline, const char *fmt, va_list args); void liftoff_log_init(enum liftoff_log_importance verbosity, diff --git a/include/log.h b/include/log.h index dc5afc2..219792b 100644 --- a/include/log.h +++ b/include/log.h @@ -13,6 +13,8 @@ bool log_has(enum liftoff_log_importance verbosity); void liftoff_log(enum liftoff_log_importance verbosity, const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3); +void liftoff_log_cnt(enum liftoff_log_importance verbosity, + const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3); void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg); #endif diff --git a/log.c b/log.c index 957517f..8a4fe3e 100644 --- a/log.c +++ b/log.c @@ -5,11 +5,13 @@ static enum liftoff_log_importance log_importance = LIFTOFF_ERROR; -static void log_stderr(enum liftoff_log_importance verbosity, const char *fmt, +static void log_stderr(enum liftoff_log_importance verbosity, bool newline, const char *fmt, va_list args) { vfprintf(stderr, fmt, args); - fprintf(stderr, "\n"); + if (newline) { + fprintf(stderr, "\n"); + } } static liftoff_log_func log_callback = log_stderr; @@ -37,7 +39,19 @@ void liftoff_log(enum liftoff_log_importance verbosity, const char *fmt, ...) va_list args; va_start(args, fmt); - log_callback(verbosity, fmt, args); + log_callback(verbosity, true, fmt, args); + va_end(args); +} + +void liftoff_log_cnt(enum liftoff_log_importance verbosity, const char *fmt, ...) +{ + if (!log_has(verbosity)) { + return; + } + + va_list args; + va_start(args, fmt); + log_callback(verbosity, false, fmt, args); va_end(args); }