From ca6779f3cbb816e27ed7228720509185145ac038 Mon Sep 17 00:00:00 2001 From: Zan Dobersek Date: Wed, 27 Mar 2024 17:39:08 +0100 Subject: [PATCH] fd: enable prefixing the RD output filename When using Freedreno's RD output facilities, enable prefixing any output or trigger file with the string specified in the FD_RD_DUMP_TESTNAME environment option. This is similar to how the TESTNAME env can be used with libwrap to provide a more descriptive name for the output RD file. These prefixes can be quite long, e.g. the longest test case name in Vulkan CTS is above 250 characters. For that reason the output name string in the fd_rd_output struct is now allocated on the heap, and any path building using the output name has its on-stack string buffer enlarged. Signed-off-by: Zan Dobersek Acked-by: Rob Clark Part-of: --- docs/drivers/freedreno.rst | 3 ++- src/freedreno/common/freedreno_rd_output.c | 21 +++++++++++++++------ src/freedreno/common/freedreno_rd_output.h | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/drivers/freedreno.rst b/docs/drivers/freedreno.rst index 5b65873a83a..2eaee0b0d6f 100644 --- a/docs/drivers/freedreno.rst +++ b/docs/drivers/freedreno.rst @@ -406,7 +406,8 @@ capture from inside Mesa. Different ``FD_RD_DUMP`` options are available: until disabled. Writing 0 (or any other value) will disable dumps. Output dump files and trigger file (when enabled) are hard-coded to be placed -under ``/tmp``, or ``/data/local/tmp`` under Android. +under ``/tmp``, or ``/data/local/tmp`` under Android. `FD_RD_DUMP_TESTNAME` can +be used to specify a more descriptive prefix for the output or trigger files. Functionality is generic to any Freedreno-based backend, but is currently only integrated in the MSM backend of Turnip. Using the existing ``TU_DEBUG=rd`` diff --git a/src/freedreno/common/freedreno_rd_output.c b/src/freedreno/common/freedreno_rd_output.c index 135e181d694..17a5c395cb9 100644 --- a/src/freedreno/common/freedreno_rd_output.c +++ b/src/freedreno/common/freedreno_rd_output.c @@ -57,7 +57,7 @@ fd_rd_dump_env_init(void) static void fd_rd_output_sanitize_name(char *name) { - /* The name string is null-terminated after being constructed via snprintf. + /* The name string is null-terminated after being constructed via asprintf. * Sanitize it by reducing to an underscore anything that's not a hyphen, * underscore, dot or alphanumeric character. */ @@ -71,7 +71,13 @@ fd_rd_output_sanitize_name(char *name) void fd_rd_output_init(struct fd_rd_output *output, char* output_name) { - snprintf(output->name, sizeof(output->name), "%s", output_name); + const char *test_name = os_get_option("FD_RD_DUMP_TESTNAME"); + ASSERTED int name_len; + if (test_name) + name_len = asprintf(&output->name, "%s_%s", test_name, output_name); + else + name_len = asprintf(&output->name, "%s", output_name); + assert(name_len != -1); fd_rd_output_sanitize_name(output->name); output->combine = false; @@ -82,14 +88,14 @@ fd_rd_output_init(struct fd_rd_output *output, char* output_name) if (FD_RD_DUMP(COMBINE)) { output->combine = true; - char file_path[256]; + char file_path[PATH_MAX]; snprintf(file_path, sizeof(file_path), "%s/%s_combined.rd", fd_rd_output_base_path, output->name); output->file = gzopen(file_path, "w"); } if (FD_RD_DUMP(TRIGGER)) { - char file_path[256]; + char file_path[PATH_MAX]; snprintf(file_path, sizeof(file_path), "%s/%s_trigger", fd_rd_output_base_path, output->name); output->trigger_fd = open(file_path, O_RDWR | O_CREAT | O_TRUNC, 0600); @@ -99,6 +105,9 @@ fd_rd_output_init(struct fd_rd_output *output, char* output_name) void fd_rd_output_fini(struct fd_rd_output *output) { + if (output->name != NULL) + free(output->name); + if (output->file != NULL) { assert(output->combine); gzclose(output->file); @@ -110,7 +119,7 @@ fd_rd_output_fini(struct fd_rd_output *output) /* Remove the trigger file. The filename is reconstructed here * instead of having to spend memory to store it in the struct. */ - char file_path[256]; + char file_path[PATH_MAX]; snprintf(file_path, sizeof(file_path), "%s/%s_trigger", fd_rd_output_base_path, output->name); unlink(file_path); @@ -200,7 +209,7 @@ fd_rd_output_begin(struct fd_rd_output *output, uint32_t submit_idx) if (output->combine) return true; - char file_path[256]; + char file_path[PATH_MAX]; snprintf(file_path, sizeof(file_path), "%s/%s_%.5d.rd", fd_rd_output_base_path, output->name, submit_idx); output->file = gzopen(file_path, "w"); diff --git a/src/freedreno/common/freedreno_rd_output.h b/src/freedreno/common/freedreno_rd_output.h index 0c6058ac933..7d597b79ebe 100644 --- a/src/freedreno/common/freedreno_rd_output.h +++ b/src/freedreno/common/freedreno_rd_output.h @@ -35,7 +35,7 @@ void fd_rd_dump_env_init(void); struct fd_rd_output { - char name[128]; + char *name; bool combine; gzFile file;