From b5b32387d6fe16ae6ed5d582a165f8f21afee395 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 9 Apr 2020 16:51:22 -0700 Subject: [PATCH] freedreno/log: android support In particular, when stdout doesn't go anywhere useful we need to log to file. Signed-off-by: Rob Clark Part-of: --- .../drivers/freedreno/freedreno_context.c | 20 +++++++++++++++++++ .../drivers/freedreno/freedreno_context.h | 1 + src/gallium/drivers/freedreno/freedreno_log.c | 12 ++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/freedreno/freedreno_context.c b/src/gallium/drivers/freedreno/freedreno_context.c index 5b52e1381f4..4969172e449 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.c +++ b/src/gallium/drivers/freedreno/freedreno_context.c @@ -39,6 +39,12 @@ #include "freedreno_util.h" #include "util/u_upload_mgr.h" +#if DETECT_OS_ANDROID +#include "util/u_process.h" +#include +#include +#endif + static void fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fencep, unsigned flags) @@ -413,12 +419,26 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen, list_inithead(&ctx->acc_active_queries); list_inithead(&ctx->log_chunks); + ctx->log_out = stdout; + if ((fd_mesa_debug & FD_DBG_LOG) && !(ctx->record_timestamp && ctx->ts_to_ns)) { printf("logging not supported!\n"); fd_mesa_debug &= ~FD_DBG_LOG; } +#if DETECT_OS_ANDROID + if (fd_mesa_debug && FD_DBG_LOG) { + static unsigned idx = 0; + char *p; + asprintf(&p, "/data/fdlog/%s-%d.log", util_get_process_name(), idx++); + + FILE *f = fopen(p, "w"); + if (f) + ctx->log_out = f; + } +#endif + return pctx; fail: diff --git a/src/gallium/drivers/freedreno/freedreno_context.h b/src/gallium/drivers/freedreno/freedreno_context.h index c07ef83e49d..8665d886a69 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.h +++ b/src/gallium/drivers/freedreno/freedreno_context.h @@ -361,6 +361,7 @@ struct fd_context { struct list_head log_chunks; /* list of flushed log chunks in fifo order */ unsigned frame_nr; /* frame counter (for fd_log) */ + FILE *log_out; /* * Common pre-cooked VBO state (used for a3xx and later): diff --git a/src/gallium/drivers/freedreno/freedreno_log.c b/src/gallium/drivers/freedreno/freedreno_log.c index 8eb1966aabf..81160f86a92 100644 --- a/src/gallium/drivers/freedreno/freedreno_log.c +++ b/src/gallium/drivers/freedreno/freedreno_log.c @@ -109,7 +109,7 @@ free_chunk(struct fd_log_chunk *chunk) static void process_chunk(struct fd_context *ctx, struct fd_log_chunk *chunk) { - printf("+----- TS -----+ +----- NS -----+ +-- Δ --+ +----- MSG -----\n"); + fprintf(ctx->log_out, "+----- TS -----+ +----- NS -----+ +-- Δ --+ +----- MSG -----\n"); uint64_t *timestamps = fd_bo_map(chunk->timestamps_bo); uint64_t last_time_ns = 0; @@ -136,15 +136,15 @@ process_chunk(struct fd_context *ctx, struct fd_log_chunk *chunk) delta = 0; } - printf("%016"PRIu64" %016"PRIu64" %+9d: %s\n", ts, ns, delta, msg); + fprintf(ctx->log_out, "%016"PRIu64" %016"PRIu64" %+9d: %s\n", ts, ns, delta, msg); free(msg); } - printf("ELAPSED: %"PRIu64" ns\n", last_time_ns - first_time_ns); + fprintf(ctx->log_out, "ELAPSED: %"PRIu64" ns\n", last_time_ns - first_time_ns); if (chunk->eof) - printf("END OF FRAME %u\n", ctx->frame_nr++); + fprintf(ctx->log_out, "END OF FRAME %u\n", ctx->frame_nr++); } void @@ -165,6 +165,8 @@ fd_log_process(struct fd_context *ctx, bool wait) process_chunk(ctx, chunk); free_chunk(chunk); } + + fflush(ctx->log_out); } void @@ -217,7 +219,7 @@ void fd_log_eof(struct fd_context *ctx) return; if (list_is_empty(&ctx->log_chunks)) { - printf("WARNING: no log chunks!\n"); + fprintf(ctx->log_out, "WARNING: no log chunks!\n"); return; } -- 2.30.2