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 <zdobersek@igalia.com>
Acked-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28442>
This commit is contained in:
Zan Dobersek
2024-03-27 17:39:08 +01:00
parent 9e0d0190ea
commit ca6779f3cb
3 changed files with 18 additions and 8 deletions

View File

@@ -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``

View File

@@ -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");

View File

@@ -35,7 +35,7 @@ void
fd_rd_dump_env_init(void);
struct fd_rd_output {
char name[128];
char *name;
bool combine;
gzFile file;