Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
feat: add log format flags
Browse files Browse the repository at this point in the history
With these flags API consumers can optimize the depiction of libliftoff's debug
log.

For now the two flags for a section start and end are introduced. It is
guaranteed that one section always ends before the next one begins.

Is no callback function setup section starts and ends in the default stderr
output will be marked with an empty line.

BREAKING CHANGE: The signature of the log callback changes.
  • Loading branch information
romangg committed Feb 29, 2020
1 parent 4257354 commit 7908175
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 29 deletions.
20 changes: 11 additions & 9 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ static void log_reuse(struct liftoff_output *output)

static void log_no_reuse(struct liftoff_output *output)
{
liftoff_log(LIFTOFF_DEBUG,
"\n== Apply request for output %"PRIu32" ==", output->crtc_id);
liftoff_log_formatted(LIFTOFF_DEBUG, LIFTOFF_LOG_SECTION_START,
"== Apply request for output %"PRIu32" ==", output->crtc_id);

if (output->alloc_reuse != 0) {
liftoff_log(LIFTOFF_DEBUG,
Expand Down Expand Up @@ -618,7 +618,7 @@ static void log_planes(struct liftoff_device *device,
} else {
debug_cnt(device, ":");
}
debug_cnt(device, NULL);
debug_end(device, LIFTOFF_LOG_SECTION_START);

liftoff_list_for_each(plane, &device->planes, link) {
bool active = false;
Expand Down Expand Up @@ -661,7 +661,7 @@ static void log_planes(struct liftoff_device *device,
char *name;

if (++per_line == max_per_line) {
debug_cnt(device, NULL);
debug_end(device, 0);
debug_cnt(device, " ");
per_line = 0;
}
Expand Down Expand Up @@ -693,7 +693,7 @@ static void log_planes(struct liftoff_device *device,
}
debug_cnt(device, " %s: %"PRIu64, name, value);
}
debug_cnt(device, NULL);
debug_end(device, 0);
}
}

Expand All @@ -703,7 +703,7 @@ static bool reset_planes(struct liftoff_device *device, drmModeAtomicReq *req)
uint32_t debug_type = DRM_PLANE_TYPE_PRIMARY;
bool compatible;

debug_cnt(device, "\nReset planes:");
debug_cnt(device, "Reset planes:");

liftoff_list_for_each(plane, &device->planes, link) {
if (plane->layer != NULL) {
Expand All @@ -720,13 +720,14 @@ static bool reset_planes(struct liftoff_device *device, drmModeAtomicReq *req)

if (!plane_apply(plane, NULL, req, &compatible)) {
debug_cnt(device, "... Error resetting: %"PRIu32, plane->id);
debug_cnt(device, NULL);
debug_end(device,
LIFTOFF_LOG_SECTION_START | LIFTOFF_LOG_SECTION_END);
return false;
}
assert(compatible);
}

debug_cnt(device, NULL);
debug_end(device, LIFTOFF_LOG_SECTION_START | LIFTOFF_LOG_SECTION_END);
return true;
}

Expand Down Expand Up @@ -805,7 +806,8 @@ bool liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req)
"score=%d", (void *)output, result.best_score);

/* Apply the best allocation */
liftoff_log(LIFTOFF_DEBUG, "\nFinal assignment of layers to planes:");
liftoff_log_formatted(LIFTOFF_DEBUG, LIFTOFF_LOG_SECTION_START,
"Final assignment of layers to planes:");
i = j = 0;
liftoff_list_for_each(plane, &device->planes, link) {
layer = result.best[i];
Expand Down
9 changes: 8 additions & 1 deletion include/libliftoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ enum liftoff_log_importance {
LIFTOFF_DEBUG,
};

enum liftoff_log_flags {
LIFTOFF_LOG_NO_FLAG = 0,
LIFTOFF_LOG_SECTION_START = 1,
LIFTOFF_LOG_SECTION_END = 2,
};

typedef void (*liftoff_log_func)(enum liftoff_log_importance importance,
const char *fmt, va_list args);
enum liftoff_log_flags flags,
const char *fmt, va_list args);

void liftoff_log_init(enum liftoff_log_importance verbosity,
liftoff_log_func callback);
Expand Down
4 changes: 4 additions & 0 deletions include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ 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_formatted(enum liftoff_log_importance verbosity,
enum liftoff_log_flags flags,
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(3, 4);
void liftoff_log_errno(enum liftoff_log_importance verbosity, const char *msg);

void debug_cnt(struct liftoff_device *device, const char *format, ...)
_LIFTOFF_ATTRIB_PRINTF(2, 3);
void debug_end(struct liftoff_device *device, enum liftoff_log_flags flags);

#endif
54 changes: 39 additions & 15 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@

static enum liftoff_log_importance log_importance = LIFTOFF_ERROR;

static void log_stderr(enum liftoff_log_importance verbosity, const char *fmt,
va_list args)
static void log_stderr(enum liftoff_log_importance verbosity,
enum liftoff_log_flags flags,
const char *fmt, va_list args)
{
if (flags & LIFTOFF_LOG_SECTION_START) {
fprintf(stderr, "\n");
}
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
if (flags & LIFTOFF_LOG_SECTION_END) {
fprintf(stderr, "\n");
}
}

static liftoff_log_func log_callback = log_stderr;
Expand Down Expand Up @@ -39,7 +46,21 @@ 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, 0, fmt, args);
va_end(args);
}

void liftoff_log_formatted(enum liftoff_log_importance verbosity,
enum liftoff_log_flags flags,
const char *fmt, ...)
{
if (!log_has(verbosity)) {
return;
}

va_list args;
va_start(args, fmt);
log_callback(verbosity, flags, fmt, args);
va_end(args);
}

Expand All @@ -55,18 +76,6 @@ void debug_cnt(struct liftoff_device *device, const char *fmt, ...)
return;
}

if (fmt == NULL) {
if (device->log_buf == 0) {
return;
}
liftoff_log(LIFTOFF_DEBUG, "%s", device->log_buf);
free(device->log_buf);
device->log_buf = NULL;
device->log_buf_index = 0;
device->log_buf_len = 0;
return;
}

va_list args;
va_start(args, fmt);

Expand Down Expand Up @@ -112,3 +121,18 @@ void debug_cnt(struct liftoff_device *device, const char *fmt, ...)
final_out:
va_end(args);
}

void debug_end(struct liftoff_device *device, enum liftoff_log_flags flags)
{
if (!log_has(LIFTOFF_DEBUG)) {
return;
}
if (device->log_buf == NULL) {
return;
}
liftoff_log_formatted(LIFTOFF_DEBUG, flags, "%s", device->log_buf);
free(device->log_buf);
device->log_buf = NULL;
device->log_buf_index = 0;
device->log_buf_len = 0;
}
8 changes: 4 additions & 4 deletions plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ static void log_plane(struct liftoff_device *device,
} else {
debug_cnt(device, "Overlay");
}
debug_cnt(device, NULL);
debug_end(device, 0);

liftoff_log(LIFTOFF_DEBUG, " zpos: %"PRIu32, plane->zpos);

debug_cnt(device, " props:");
for (i = 0; i < plane->props_len; i++) {
if (per_line == 5) {
debug_cnt(device, NULL);
debug_end(device, 0);
debug_cnt(device, " ");
per_line = 0;
}
debug_cnt(device, " %s", plane->props[i].name);
per_line++;
}
debug_cnt(device, NULL);
debug_end(device, 0);
}

struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id)
Expand All @@ -77,7 +77,7 @@ struct liftoff_plane *plane_create(struct liftoff_device *device, uint32_t id)
bool has_type = false, has_zpos = false;

debug_cnt(device, "Plane %"PRIu32, id);
debug_cnt(device, NULL);
debug_end(device, 0);

plane = calloc(1, sizeof(*plane));
if (plane == NULL) {
Expand Down

0 comments on commit 7908175

Please sign in to comment.