From 2a60e9e7697b59750ca15dcc4f292bb23ccdde55 Mon Sep 17 00:00:00 2001 From: Jhanani Thiagarajan Date: Mon, 29 Dec 2025 11:08:20 -0600 Subject: [PATCH] intel/mda: Change the default output directory Directories are named using the process name and PID to avoid overwriting dumps from subsequent runs of the same application. v2 (Caio): Use util_get_process_name(). Change to be default behavior. Old behavior still accessible via MDA_OUTPUT_DIR="." env var. Reviewed-by: Caio Oliveira Part-of: --- docs/drivers/anv.rst | 8 +++++--- docs/envvars.rst | 5 ++++- src/intel/mda/debug_archiver.c | 11 ++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/drivers/anv.rst b/docs/drivers/anv.rst index ab929413fd9..3e6b4b343e6 100644 --- a/docs/drivers/anv.rst +++ b/docs/drivers/anv.rst @@ -421,12 +421,14 @@ paths in the shaders. To make use of this feature : 3. Exit the application once enough data is captured -4. Untar the ``anv-shaders.mda.tar`` file created in the directory the - application was launched (or in MDA_OUTPUT_DIR if it was set) +4. Untar the ``anv-shaders.mda.tar`` file created in the ``NAME_PID_mda`` + subdirectory, where ``NAME`` is the process name and ``PID`` is the process + ID. Set ``MDA_OUTPUT_DIR=.`` to create the file in the directory the + application was launched instead. .. code-block:: sh - mesa % tar xfv anv-shaders.mda.tar + mesa % tar xfv my_app_12345_mda/anv-shaders.mda.tar 5. Look at the hot spots with ``intel_eu_stall_viewer`` : diff --git a/docs/envvars.rst b/docs/envvars.rst index 2217732611b..d48f3ece59a 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -913,7 +913,10 @@ Intel driver environment variables .. envvar:: MDA_OUTPUT_DIR Directory where the mda.tar files generated when using INTEL_DEBUG=mda or ANV_DEBUG=shader-dump are - going to be written to. If not set, use the current directory. + going to be written to. If set, use that directory. If not set, create and + use a ``NAME_PID_mda`` subdirectory, where ``NAME`` is the process name and + ``PID`` is the process ID. If directory creation fails, use the current + directory. .. envvar:: MDA_PREFIX diff --git a/src/intel/mda/debug_archiver.c b/src/intel/mda/debug_archiver.c index e908dcafcf5..63216395ff5 100644 --- a/src/intel/mda/debug_archiver.c +++ b/src/intel/mda/debug_archiver.c @@ -9,6 +9,7 @@ #include "tar.h" #include "util/ralloc.h" #include "util/u_debug.h" +#include "util/u_process.h" #include #include @@ -25,7 +26,7 @@ struct debug_archiver char *mda_dir_in_archive; }; -DEBUG_GET_ONCE_OPTION(mda_output_dir, "MDA_OUTPUT_DIR", ".") +DEBUG_GET_ONCE_OPTION(mda_output_dir, "MDA_OUTPUT_DIR", "") DEBUG_GET_ONCE_OPTION(mda_prefix, "MDA_PREFIX", NULL) DEBUG_GET_ONCE_OPTION(mda_filter, "MDA_FILTER", NULL) @@ -81,6 +82,14 @@ debug_archiver_open(void *mem_ctx, const char *name, const char *info) const char *output_dir = debug_get_option_mda_output_dir(); const char *prefix = debug_get_option_mda_prefix(); + if (!output_dir || !*output_dir) { + const char *process_name = util_get_process_name(); + if (!process_name || !*process_name) + process_name = "unknown_process"; + + output_dir = ralloc_asprintf(da, "./%s_%d_mda", process_name, getpid()); + } + if (!ensure_output_dir(output_dir)) { /* Fallback to current directory on failure. */ output_dir = ".";