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 <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39125>
This commit is contained in:
Jhanani Thiagarajan 2025-12-29 11:08:20 -06:00 committed by Marge Bot
parent 04dfd3fe3f
commit 2a60e9e769
3 changed files with 19 additions and 5 deletions

View file

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

View file

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

View file

@ -9,6 +9,7 @@
#include "tar.h"
#include "util/ralloc.h"
#include "util/u_debug.h"
#include "util/u_process.h"
#include <string.h>
#include <sys/stat.h>
@ -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 = ".";