[Intel-gfx] [PATCH v2 i-g-t] tools: intel_aubdump: pass configuration through file descriptor

Lionel Landwerlin llandwerlin at gmail.com
Fri Oct 7 10:00:54 UTC 2016


This makes parsing options less complicated and easier to extend.

v2: Fix device id parsing (atoi -> sscanf) (Sirisha)
    Combine with previous commit moving init function (Sirisha)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 tools/aubdump.c        | 58 ++++++++++++++++++++++++++++++++++++--------------
 tools/intel_aubdump.in | 22 +++++++++++++------
 2 files changed, 57 insertions(+), 23 deletions(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index 30dc742..f2cd2c1 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -426,6 +426,46 @@ close(int fd)
 	return libc_close(fd);
 }

+static void
+maybe_init(void)
+{
+	static bool initialized = false;
+	FILE *config;
+	char *key, *value;
+
+	if (initialized)
+		return;
+
+	initialized = true;
+
+	config = fdopen(3, "r");
+	while (fscanf(config, "%m[^=]=%m[^\n]\n", &key, &value) != EOF) {
+		if (!strcmp(key, "verbose")) {
+			verbose = 1;
+		} else if (!strcmp(key, "device")) {
+			fail_if(sscanf(value, "%i", &device) != 1,
+				"intel_aubdump: failed to parse device id '%s'",
+				value);
+			device_override = true;
+		} else if (!strcmp(key, "file")) {
+			filename = value;
+			file = fopen(filename, "w+");
+			fail_if(file == NULL,
+				"intel_aubdump: failed to open file '%s'\n",
+				filename);
+		} else {
+			fprintf(stderr, "intel_aubdump: unknown option '%s'\n", key);
+		}
+
+		free(key);
+		free(value);
+	}
+	fclose(config);
+
+	bos = malloc(MAX_BO_COUNT * sizeof(bos[0]));
+	fail_if(bos == NULL, "intel_aubdump: out of memory\n");
+}
+
 int
 ioctl(int fd, unsigned long request, ...)
 {
@@ -447,6 +487,8 @@ ioctl(int fd, unsigned long request, ...)
 	}

 	if (fd == drm_fd) {
+		maybe_init();
+
 		switch (request) {
 		case DRM_IOCTL_I915_GETPARAM: {
 			struct drm_i915_getparam *getparam = argp;
@@ -550,26 +592,10 @@ ioctl(int fd, unsigned long request, ...)
 static void
 init(void)
 {
-	const char *args = getenv("INTEL_AUBDUMP_ARGS");
-
 	libc_close = dlsym(RTLD_NEXT, "close");
 	libc_ioctl = dlsym(RTLD_NEXT, "ioctl");
 	fail_if(libc_close == NULL || libc_ioctl == NULL,
 		"intel_aubdump: failed to get libc ioctl or close\n");
-
-	if (sscanf(args, "verbose=%d;file=%m[^;];device=%i",
-		   &verbose, &filename, &device) != 3)
-		filename = strdup("intel.aub");
-	fail_if(filename == NULL, "intel_aubdump: out of memory\n");
-
-	if (device)
-		device_override = true;
-
-	bos = malloc(MAX_BO_COUNT * sizeof(bos[0]));
-	fail_if(bos == NULL, "intel_aubdump: out of memory\n");
-
-	file = fopen(filename, "w+");
-	fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", filename);
 }

 static int
diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
index feee23a..445b60f 100644
--- a/tools/intel_aubdump.in
+++ b/tools/intel_aubdump.in
@@ -21,29 +21,38 @@ EOF
     exit 0
 }

-verbose=0
-device=0
+args=""
+command=""
+file=""
+
+function add_arg() {
+    arg=$1
+    args="$args$arg\n"
+}

 while true; do
       case "$1" in
 	  -o)
 	      file=$2
+	      add_arg "file=${f:-$(basename ${f}).aub}"
 	      shift 2
 	      ;;
 	  -v)
-	      verbose=1
+	      add_arg "verbose=1"
 	      shift 1
 	      ;;
 	  -o*)
 	      file=${1##-o}
+	      add_arg "file=${file:-$(basename ${file}).aub}"
 	      shift
 	      ;;
 	  --output=*)
 	      file=${1##--output=}
+	      add_arg "file=${file:-$(basename ${file}).aub}"
 	      shift
 	      ;;
 	  --device=*)
-	      device=${1##--device=}
+	      add_arg "device=${1##--device=}"
 	      shift
 	      ;;
 	  --help)
@@ -66,12 +75,11 @@ done

 [ -z $1 ] && show_help

-file=${file:-$(basename $1).aub}
+[ -z $file ] && add_arg "file=intel.aub"

 prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@

 LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
-	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \
-	  exec -- "$@"
+	  exec -- "$@" 3<<< `printf '%b' "$args"`
--
2.9.3


More information about the Intel-gfx mailing list