mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-07 13:29:49 -05:00
util/trace: add context helpers
These allow gpuvis to link two events and compute the duration.
This commit is contained in:
parent
79b5dcb17d
commit
6531bff140
2 changed files with 36 additions and 0 deletions
|
|
@ -1,9 +1,17 @@
|
|||
#ifndef UTIL_TRACE_H
|
||||
#define UTIL_TRACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
void wlr_trace(const char *format, ...) _WLR_ATTRIB_PRINTF(1, 2);
|
||||
void wlr_vtrace(const char *format, va_list args) _WLR_ATTRIB_PRINTF(1, 0);
|
||||
|
||||
struct wlr_trace_ctx {
|
||||
uint32_t seq;
|
||||
};
|
||||
|
||||
void wlr_trace_begin_ctx(struct wlr_trace_ctx *ctx, const char *format, ...) _WLR_ATTRIB_PRINTF(2, 3);
|
||||
void wlr_trace_end_ctx(struct wlr_trace_ctx *ctx, const char *format, ...) _WLR_ATTRIB_PRINTF(2, 3);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
28
util/trace.c
28
util/trace.c
|
|
@ -1,8 +1,10 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include "util/trace.h"
|
||||
|
||||
static bool trace_initialized = false;
|
||||
static FILE *trace_file = NULL;
|
||||
static uint32_t prev_ctx = 0;
|
||||
|
||||
void wlr_vtrace(const char *fmt, va_list args) {
|
||||
if (!trace_initialized) {
|
||||
|
|
@ -28,3 +30,29 @@ void wlr_trace(const char *fmt, ...) {
|
|||
wlr_vtrace(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void wlr_trace_begin_ctx(struct wlr_trace_ctx *ctx, const char *fmt, ...) {
|
||||
*ctx = (struct wlr_trace_ctx){
|
||||
.seq = prev_ctx++,
|
||||
};
|
||||
|
||||
static char new_fmt[512];
|
||||
snprintf(new_fmt, sizeof(new_fmt), "%s (begin_ctx=%"PRIu32")", fmt, ctx->seq);
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
wlr_vtrace(new_fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void wlr_trace_end_ctx(struct wlr_trace_ctx *ctx, const char *fmt, ...) {
|
||||
static char new_fmt[512];
|
||||
snprintf(new_fmt, sizeof(new_fmt), "%s (end_ctx=%"PRIu32")", fmt, ctx->seq);
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
wlr_vtrace(new_fmt, args);
|
||||
va_end(args);
|
||||
|
||||
ctx->seq = 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue