All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] aubdump: add --command option to stream aubdump to another program
@ 2016-10-04 14:21 Lionel Landwerlin
  2016-10-05 22:48 ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Lionel Landwerlin
  2016-11-01 18:15 ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Lionel Landwerlin
  0 siblings, 2 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2016-10-04 14:21 UTC (permalink / raw)
  To: intel-gfx

This comes handy if you want to look at your application output without
having to save it into a file. For example, use this with aubinator from
Mesa :

$ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Kristian Høgsberg <krh@bitplanet.net>
---
 tools/aubdump.c        | 101 +++++++++++++++++++++++++++++++++++++++----------
 tools/intel_aubdump.in |  26 ++++++++++++-
 2 files changed, 106 insertions(+), 21 deletions(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index 30dc742..5c0e2bb 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -50,6 +50,7 @@ static int (*libc_close)(int fd) = close_init_helper;
 static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;
 
 static int drm_fd = -1;
+static char *command;
 static char *filename;
 static FILE *file;
 static int gen = 0;
@@ -113,6 +114,76 @@ fail_if(int cond, const char *format, ...)
 	raise(SIGTRAP);
 }
 
+static FILE *
+launch_command(void)
+{
+	int i = 0, fds[2];
+	char **args = calloc(strlen(command), sizeof(char *));
+	char *iter = command;
+
+	args[i++] = iter = command;
+
+	while ((iter = strstr(iter, ",")) != NULL) {
+		*iter = '\0';
+		iter += 1;
+		args[i++] = iter;
+	}
+
+	if (pipe(fds) == -1)
+		return NULL;
+
+	switch (fork()) {
+	case 0:
+		dup2(fds[0], 0);
+		fail_if(execv(args[0], args) == -1,
+			"intel_aubdump: fail to launch child command\n");
+		return NULL;
+
+	default:
+		free(args);
+		return fdopen(fds[1], "w");
+
+	case -1:
+		return NULL;
+	}
+}
+
+static void
+maybe_init_output(void)
+{
+	const char *args;
+	static bool initialized = false;
+	int nb_args;
+
+	if (initialized)
+		return;
+
+	args = getenv("INTEL_AUBDUMP_ARGS");
+
+	nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;command=%m[^;];",
+			 &verbose, &filename, &device, &command);
+	fail_if(nb_args != 4, "intel_aubdump: invalid number of arguments");
+        fail_if(filename == NULL || command == 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");
+
+        if (strlen(command) != 0) {
+          file = launch_command();
+          fail_if(file == NULL,
+                  "intel_aubdump: failed to launch command '%s'\n", command);
+        } else {
+          file = fopen(filename, "w+");
+          fail_if(file == NULL,
+                  "intel_aubdump: failed to open file '%s'\n", filename);
+        }
+
+	initialized = true;
+}
+
 static struct bo *
 get_bo(uint32_t handle)
 {
@@ -140,13 +211,18 @@ align_u64(uint64_t v, uint64_t a)
 static void
 dword_out(uint32_t data)
 {
-	fwrite(&data, 1, 4, file);
+	fail_if(fwrite(&data, 1, 4, file) == 0,
+		"Writing to output failed\n");
 }
 
 static void
 data_out(const void *data, size_t size)
 {
-	fwrite(data, 1, size, file);
+	if (size == 0)
+		return;
+
+	fail_if(fwrite(data, 1, size, file) == 0,
+		"Writing to output failed\n");
 }
 
 static void
@@ -447,6 +523,8 @@ ioctl(int fd, unsigned long request, ...)
 	}
 
 	if (fd == drm_fd) {
+		maybe_init_output();
+
 		switch (request) {
 		case DRM_IOCTL_I915_GETPARAM: {
 			struct drm_i915_getparam *getparam = argp;
@@ -550,26 +628,8 @@ 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
@@ -596,6 +656,7 @@ ioctl_init_helper(int fd, unsigned long request, ...)
 static void __attribute__ ((destructor))
 fini(void)
 {
+	free(command);
 	free(filename);
 	if (file)
 		fclose(file);
diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
index 3666b6e..2357e9b 100644
--- a/tools/intel_aubdump.in
+++ b/tools/intel_aubdump.in
@@ -10,6 +10,9 @@ contents and execution of the GEM application.
 
   -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub
 
+  -c, --command=CMD  Execute CMD and write the AUB file's content to its
+                     standard input
+
       --device=ID    Override PCI ID of the reported device
 
   -v                 Enable verbose output
@@ -23,6 +26,19 @@ EOF
 
 verbose=0
 device=0
+file="intel.aub"
+command=""
+
+build_command () {
+    command=""
+    for i in $1; do
+        if [ -z $command ]; then
+            command=$i
+        else
+            command="$command,$i"
+        fi;
+    done
+}
 
 while true; do
       case "$1" in
@@ -38,6 +54,14 @@ while true; do
 	      file=${1##--output=}
 	      shift
 	      ;;
+	  -c)
+              build_command "$2"
+	      shift 2
+	      ;;
+	  --command=*)
+              build_command "${1##--command=}"
+	      shift
+	      ;;
 	  --device=*)
 	      device=${1##--device=}
 	      shift
@@ -69,5 +93,5 @@ 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" \
+	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device;command=$command;" \
 	  exec -- "$@"
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH i-g-t 1/2] aubdump: remove already handled -o
  2016-10-04 14:21 [PATCH] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
@ 2016-10-05 22:48 ` Lionel Landwerlin
  2016-10-05 22:48   ` [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
  2016-10-06  9:09   ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Petri Latvala
  2016-11-01 18:15 ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Lionel Landwerlin
  1 sibling, 2 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2016-10-05 22:48 UTC (permalink / raw)
  To: intel-gfx; +Cc: Lionel Landwerlin, Sirisha Gandikota

From: Lionel Landwerlin <llandwerlin@gmail.com>

Signed-off-by: Lionel Landwerlin <llandwerlin@gmail.com>
Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
---
 tools/intel_aubdump.in | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
index feee23a..3666b6e 100644
--- a/tools/intel_aubdump.in
+++ b/tools/intel_aubdump.in
@@ -34,10 +34,6 @@ while true; do
 	      verbose=1
 	      shift 1
 	      ;;
-	  -o*)
-	      file=${1##-o}
-	      shift
-	      ;;
 	  --output=*)
 	      file=${1##--output=}
 	      shift
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program
  2016-10-05 22:48 ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Lionel Landwerlin
@ 2016-10-05 22:48   ` Lionel Landwerlin
  2016-10-06 10:13     ` [PATCH v3 i-g-t] " Lionel Landwerlin
  2016-10-06 10:25     ` [PATCH v2 i-g-t 2/2] " Petri Latvala
  2016-10-06  9:09   ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Petri Latvala
  1 sibling, 2 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2016-10-05 22:48 UTC (permalink / raw)
  To: intel-gfx; +Cc: Sirisha Gandikota

This comes handy if you want to look at your application output without
having to save it into a file. For example, use this with aubinator from
Mesa :

$ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app

v2: Fix handling empty command line option

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
---
 tools/aubdump.c        | 107 ++++++++++++++++++++++++++++++++++++++++---------
 tools/intel_aubdump.in |  31 +++++++++++++-
 2 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index 30dc742..3b85bc7 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -50,6 +50,7 @@ static int (*libc_close)(int fd) = close_init_helper;
 static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;

 static int drm_fd = -1;
+static char *command;
 static char *filename;
 static FILE *file;
 static int gen = 0;
@@ -113,6 +114,82 @@ fail_if(int cond, const char *format, ...)
 	raise(SIGTRAP);
 }

+static FILE *
+launch_command(void)
+{
+	int i = 0, fds[2];
+	char **args = calloc(strlen(command), sizeof(char *));
+	char *iter = command;
+
+	args[i++] = iter = command;
+
+	while ((iter = strstr(iter, ",")) != NULL) {
+		*iter = '\0';
+		iter += 1;
+		args[i++] = iter;
+	}
+
+	if (pipe(fds) == -1)
+		return NULL;
+
+	switch (fork()) {
+	case 0:
+		dup2(fds[0], 0);
+		fail_if(execv(args[0], args) == -1,
+			"intel_aubdump: fail to launch child command\n");
+		return NULL;
+
+	default:
+		free(args);
+		return fdopen(fds[1], "w");
+
+	case -1:
+		return NULL;
+	}
+}
+
+static void
+maybe_init_output(void)
+{
+	const char *args;
+	static bool initialized = false;
+	int nb_args;
+
+	if (initialized)
+		return;
+
+	args = getenv("INTEL_AUBDUMP_ARGS");
+
+	nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;command=%m[^;];",
+			 &verbose, &filename, &device, &command);
+	if (nb_args != 4) {
+		if (filename)
+			free(filename);
+		nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;",
+				 &verbose, &filename, &device);
+		command = strdup("");
+	}
+        fail_if(filename == NULL || command == 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");
+
+        if (strlen(command) != 0) {
+          file = launch_command();
+          fail_if(file == NULL,
+                  "intel_aubdump: failed to launch command '%s'\n", command);
+        } else {
+          file = fopen(filename, "w+");
+          fail_if(file == NULL,
+                  "intel_aubdump: failed to open file '%s'\n", filename);
+        }
+
+	initialized = true;
+}
+
 static struct bo *
 get_bo(uint32_t handle)
 {
@@ -140,13 +217,18 @@ align_u64(uint64_t v, uint64_t a)
 static void
 dword_out(uint32_t data)
 {
-	fwrite(&data, 1, 4, file);
+	fail_if(fwrite(&data, 1, 4, file) == 0,
+		"Writing to output failed\n");
 }

 static void
 data_out(const void *data, size_t size)
 {
-	fwrite(data, 1, size, file);
+	if (size == 0)
+		return;
+
+	fail_if(fwrite(data, 1, size, file) == 0,
+		"Writing to output failed\n");
 }

 static void
@@ -447,6 +529,8 @@ ioctl(int fd, unsigned long request, ...)
 	}

 	if (fd == drm_fd) {
+		maybe_init_output();
+
 		switch (request) {
 		case DRM_IOCTL_I915_GETPARAM: {
 			struct drm_i915_getparam *getparam = argp;
@@ -550,26 +634,8 @@ 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
@@ -596,6 +662,7 @@ ioctl_init_helper(int fd, unsigned long request, ...)
 static void __attribute__ ((destructor))
 fini(void)
 {
+	free(command);
 	free(filename);
 	if (file)
 		fclose(file);
diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
index 3666b6e..2a1704c 100644
--- a/tools/intel_aubdump.in
+++ b/tools/intel_aubdump.in
@@ -10,6 +10,9 @@ contents and execution of the GEM application.

   -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub

+  -c, --command=CMD  Execute CMD and write the AUB file's content to its
+                     standard input
+
       --device=ID    Override PCI ID of the reported device

   -v                 Enable verbose output
@@ -23,6 +26,19 @@ EOF

 verbose=0
 device=0
+file="intel.aub"
+command=""
+
+build_command () {
+    command=""
+    for i in $1; do
+        if [ -z $command ]; then
+            command=$i
+        else
+            command="$command,$i"
+        fi;
+    done
+}

 while true; do
       case "$1" in
@@ -38,6 +54,14 @@ while true; do
 	      file=${1##--output=}
 	      shift
 	      ;;
+	  -c)
+              build_command "$2"
+	      shift 2
+	      ;;
+	  --command=*)
+              build_command "${1##--command=}"
+	      shift
+	      ;;
 	  --device=*)
 	      device=${1##--device=}
 	      shift
@@ -68,6 +92,11 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@

+ARGS="verbose=$verbose;file=$file;device=$device"
+if [ ! -z $command ]; then
+   ARGS="$INTEL_AUBDUMP_ARGS;command=$command;"
+fi
+
 LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
-	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \
+         INTEL_AUBDUMP_ARGS="$ARGS" \
 	  exec -- "$@"
--
2.9.3
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH i-g-t 1/2] aubdump: remove already handled -o
  2016-10-05 22:48 ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Lionel Landwerlin
  2016-10-05 22:48   ` [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
@ 2016-10-06  9:09   ` Petri Latvala
  2016-10-06  9:16     ` Lionel Landwerlin
  1 sibling, 1 reply; 13+ messages in thread
From: Petri Latvala @ 2016-10-06  9:09 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: intel-gfx, Sirisha Gandikota

On Wed, Oct 05, 2016 at 11:48:26PM +0100, Lionel Landwerlin wrote:
> -	  -o*)
> -	      file=${1##-o}
> -	      shift
> -	      ;;


This breaks using -ofilename without spaces.


--
Petri Latvala
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH i-g-t 1/2] aubdump: remove already handled -o
  2016-10-06  9:09   ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Petri Latvala
@ 2016-10-06  9:16     ` Lionel Landwerlin
  0 siblings, 0 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2016-10-06  9:16 UTC (permalink / raw)
  To: intel-gfx; +Cc: Sirisha Gandikota

On 06/10/16 10:09, Petri Latvala wrote:
> On Wed, Oct 05, 2016 at 11:48:26PM +0100, Lionel Landwerlin wrote:
>> -	  -o*)
>> -	      file=${1##-o}
>> -	      shift
>> -	      ;;
>
> This breaks using -ofilename without spaces.
>
>

Oh right, I didn't realize that was an acceptable input.
Let's drop this patch then.

Thanks!

-
Lionel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 i-g-t] aubdump: add --command option to stream aubdump to another program
  2016-10-05 22:48   ` [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
@ 2016-10-06 10:13     ` Lionel Landwerlin
  2016-10-06 12:46       ` Ville Syrjälä
  2016-10-06 10:25     ` [PATCH v2 i-g-t 2/2] " Petri Latvala
  1 sibling, 1 reply; 13+ messages in thread
From: Lionel Landwerlin @ 2016-10-06 10:13 UTC (permalink / raw)
  To: intel-gfx; +Cc: Sirisha Gandikota

This comes handy if you want to look at your application output without
having to save it into a file. For example, use this with aubinator from
Mesa :

$ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app

v2: Fix handling empty command line option

v3: Fix command line concatenation (again...)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
---
 tools/aubdump.c        | 107 ++++++++++++++++++++++++++++++++++++++++---------
 tools/intel_aubdump.in |  31 +++++++++++++-
 2 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index 30dc742..3b85bc7 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -50,6 +50,7 @@ static int (*libc_close)(int fd) = close_init_helper;
 static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;

 static int drm_fd = -1;
+static char *command;
 static char *filename;
 static FILE *file;
 static int gen = 0;
@@ -113,6 +114,82 @@ fail_if(int cond, const char *format, ...)
 	raise(SIGTRAP);
 }

+static FILE *
+launch_command(void)
+{
+	int i = 0, fds[2];
+	char **args = calloc(strlen(command), sizeof(char *));
+	char *iter = command;
+
+	args[i++] = iter = command;
+
+	while ((iter = strstr(iter, ",")) != NULL) {
+		*iter = '\0';
+		iter += 1;
+		args[i++] = iter;
+	}
+
+	if (pipe(fds) == -1)
+		return NULL;
+
+	switch (fork()) {
+	case 0:
+		dup2(fds[0], 0);
+		fail_if(execv(args[0], args) == -1,
+			"intel_aubdump: fail to launch child command\n");
+		return NULL;
+
+	default:
+		free(args);
+		return fdopen(fds[1], "w");
+
+	case -1:
+		return NULL;
+	}
+}
+
+static void
+maybe_init_output(void)
+{
+	const char *args;
+	static bool initialized = false;
+	int nb_args;
+
+	if (initialized)
+		return;
+
+	args = getenv("INTEL_AUBDUMP_ARGS");
+
+	nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;command=%m[^;];",
+			 &verbose, &filename, &device, &command);
+	if (nb_args != 4) {
+		if (filename)
+			free(filename);
+		nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;",
+				 &verbose, &filename, &device);
+		command = strdup("");
+	}
+        fail_if(filename == NULL || command == 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");
+
+        if (strlen(command) != 0) {
+          file = launch_command();
+          fail_if(file == NULL,
+                  "intel_aubdump: failed to launch command '%s'\n", command);
+        } else {
+          file = fopen(filename, "w+");
+          fail_if(file == NULL,
+                  "intel_aubdump: failed to open file '%s'\n", filename);
+        }
+
+	initialized = true;
+}
+
 static struct bo *
 get_bo(uint32_t handle)
 {
@@ -140,13 +217,18 @@ align_u64(uint64_t v, uint64_t a)
 static void
 dword_out(uint32_t data)
 {
-	fwrite(&data, 1, 4, file);
+	fail_if(fwrite(&data, 1, 4, file) == 0,
+		"Writing to output failed\n");
 }

 static void
 data_out(const void *data, size_t size)
 {
-	fwrite(data, 1, size, file);
+	if (size == 0)
+		return;
+
+	fail_if(fwrite(data, 1, size, file) == 0,
+		"Writing to output failed\n");
 }

 static void
@@ -447,6 +529,8 @@ ioctl(int fd, unsigned long request, ...)
 	}

 	if (fd == drm_fd) {
+		maybe_init_output();
+
 		switch (request) {
 		case DRM_IOCTL_I915_GETPARAM: {
 			struct drm_i915_getparam *getparam = argp;
@@ -550,26 +634,8 @@ 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
@@ -596,6 +662,7 @@ ioctl_init_helper(int fd, unsigned long request, ...)
 static void __attribute__ ((destructor))
 fini(void)
 {
+	free(command);
 	free(filename);
 	if (file)
 		fclose(file);
diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
index feee23a..8adf4a5 100644
--- a/tools/intel_aubdump.in
+++ b/tools/intel_aubdump.in
@@ -10,6 +10,9 @@ contents and execution of the GEM application.

   -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub

+  -c, --command=CMD  Execute CMD and write the AUB file's content to its
+                     standard input
+
       --device=ID    Override PCI ID of the reported device

   -v                 Enable verbose output
@@ -23,6 +26,19 @@ EOF

 verbose=0
 device=0
+file="intel.aub"
+command=""
+
+build_command () {
+    command=""
+    for i in $1; do
+        if [ -z $command ]; then
+            command=$i
+        else
+            command="$command,$i"
+        fi;
+    done
+}

 while true; do
       case "$1" in
@@ -42,6 +58,14 @@ while true; do
 	      file=${1##--output=}
 	      shift
 	      ;;
+	  -c)
+              build_command "$2"
+	      shift 2
+	      ;;
+	  --command=*)
+              build_command "${1##--command=}"
+	      shift
+	      ;;
 	  --device=*)
 	      device=${1##--device=}
 	      shift
@@ -72,6 +96,11 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@

+ARGS="verbose=$verbose;file=$file;device=$device"
+if [ ! -z $command ]; then
+   ARGS="$ARGS;command=$command;"
+fi
+
 LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
-	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \
+         INTEL_AUBDUMP_ARGS="$ARGS" \
 	  exec -- "$@"
--
2.9.3
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program
  2016-10-05 22:48   ` [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
  2016-10-06 10:13     ` [PATCH v3 i-g-t] " Lionel Landwerlin
@ 2016-10-06 10:25     ` Petri Latvala
  1 sibling, 0 replies; 13+ messages in thread
From: Petri Latvala @ 2016-10-06 10:25 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: intel-gfx, Sirisha Gandikota

On Wed, Oct 05, 2016 at 11:48:27PM +0100, Lionel Landwerlin wrote:
> This comes handy if you want to look at your application output without
> having to save it into a file. For example, use this with aubinator from
> Mesa :
> 
> $ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app
> 
> v2: Fix handling empty command line option
> 
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
> ---
>  tools/aubdump.c        | 107 ++++++++++++++++++++++++++++++++++++++++---------
>  tools/intel_aubdump.in |  31 +++++++++++++-
>  2 files changed, 117 insertions(+), 21 deletions(-)
> 
> diff --git a/tools/aubdump.c b/tools/aubdump.c
> index 30dc742..3b85bc7 100644
> --- a/tools/aubdump.c
> +++ b/tools/aubdump.c
> @@ -50,6 +50,7 @@ static int (*libc_close)(int fd) = close_init_helper;
>  static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;
> 
>  static int drm_fd = -1;
> +static char *command;
>  static char *filename;
>  static FILE *file;
>  static int gen = 0;
> @@ -113,6 +114,82 @@ fail_if(int cond, const char *format, ...)
>  	raise(SIGTRAP);
>  }
> 
> +static FILE *
> +launch_command(void)
> +{
> +	int i = 0, fds[2];
> +	char **args = calloc(strlen(command), sizeof(char *));
> +	char *iter = command;
> +
> +	args[i++] = iter = command;
> +
> +	while ((iter = strstr(iter, ",")) != NULL) {
> +		*iter = '\0';
> +		iter += 1;
> +		args[i++] = iter;
> +	}
> +
> +	if (pipe(fds) == -1)
> +		return NULL;
> +
> +	switch (fork()) {
> +	case 0:
> +		dup2(fds[0], 0);
> +		fail_if(execv(args[0], args) == -1,
> +			"intel_aubdump: fail to launch child command\n");
> +		return NULL;
> +

Why not use execvp to avoid having to use an absolute path?

"failed" instead of "fail"


> +	default:
> +		free(args);
> +		return fdopen(fds[1], "w");
> +
> +	case -1:
> +		return NULL;
> +	}
> +}
> +
> +static void
> +maybe_init_output(void)
> +{
> +	const char *args;
> +	static bool initialized = false;
> +	int nb_args;
> +
> +	if (initialized)
> +		return;
> +
> +	args = getenv("INTEL_AUBDUMP_ARGS");
> +
> +	nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;command=%m[^;];",
> +			 &verbose, &filename, &device, &command);
> +	if (nb_args != 4) {
> +		if (filename)
> +			free(filename);
> +		nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;",
> +				 &verbose, &filename, &device);
> +		command = strdup("");
> +	}
> +        fail_if(filename == NULL || command == NULL,
> +                "intel_aubdump: out of memory\n");
> +	if (device)
> +		device_override = true;
> +

Indentation on that fail_if.


> +	bos = malloc(MAX_BO_COUNT * sizeof(bos[0]));
> +	fail_if(bos == NULL, "intel_aubdump: out of memory\n");
> +
> +        if (strlen(command) != 0) {
> +          file = launch_command();
> +          fail_if(file == NULL,
> +                  "intel_aubdump: failed to launch command '%s'\n", command);
> +        } else {
> +          file = fopen(filename, "w+");
> +          fail_if(file == NULL,
> +                  "intel_aubdump: failed to open file '%s'\n", filename);
> +        }
> +
> +	initialized = true;
> +}
> +

Indentation again.


>  static struct bo *
>  get_bo(uint32_t handle)
>  {
> @@ -140,13 +217,18 @@ align_u64(uint64_t v, uint64_t a)
>  static void
>  dword_out(uint32_t data)
>  {
> -	fwrite(&data, 1, 4, file);
> +	fail_if(fwrite(&data, 1, 4, file) == 0,
> +		"Writing to output failed\n");
>  }
> 
>  static void
>  data_out(const void *data, size_t size)
>  {
> -	fwrite(data, 1, size, file);
> +	if (size == 0)
> +		return;
> +
> +	fail_if(fwrite(data, 1, size, file) == 0,
> +		"Writing to output failed\n");
>  }
> 
>  static void
> @@ -447,6 +529,8 @@ ioctl(int fd, unsigned long request, ...)
>  	}
> 
>  	if (fd == drm_fd) {
> +		maybe_init_output();
> +
>  		switch (request) {
>  		case DRM_IOCTL_I915_GETPARAM: {
>  			struct drm_i915_getparam *getparam = argp;
> @@ -550,26 +634,8 @@ 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
> @@ -596,6 +662,7 @@ ioctl_init_helper(int fd, unsigned long request, ...)
>  static void __attribute__ ((destructor))
>  fini(void)
>  {
> +	free(command);
>  	free(filename);
>  	if (file)
>  		fclose(file);
> diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
> index 3666b6e..2a1704c 100644
> --- a/tools/intel_aubdump.in
> +++ b/tools/intel_aubdump.in
> @@ -10,6 +10,9 @@ contents and execution of the GEM application.
> 
>    -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub
> 
> +  -c, --command=CMD  Execute CMD and write the AUB file's content to its
> +                     standard input
> +


When -c is used, -o is then ignored. Document that here.

>        --device=ID    Override PCI ID of the reported device
> 
>    -v                 Enable verbose output
> @@ -23,6 +26,19 @@ EOF
> 
>  verbose=0
>  device=0
> +file="intel.aub"
> +command=""
> +
> +build_command () {
> +    command=""
> +    for i in $1; do
> +        if [ -z $command ]; then
> +            command=$i
> +        else
> +            command="$command,$i"
> +        fi;
> +    done
> +}

Passing the command this way feels a bit hairy. What if the command
string has to contain a ',', or a ';'? That should maybe be checked
and error out if there's a nonrepresentable character present.

> 
>  while true; do
>        case "$1" in
> @@ -38,6 +54,14 @@ while true; do
>  	      file=${1##--output=}
>  	      shift
>  	      ;;
> +	  -c)
> +              build_command "$2"
> +	      shift 2
> +	      ;;
> +	  --command=*)
> +              build_command "${1##--command=}"
> +	      shift
> +	      ;;

Indentation on those build_command lines.


>  	  --device=*)
>  	      device=${1##--device=}
>  	      shift
> @@ -68,6 +92,11 @@ prefix=@prefix@
>  exec_prefix=@exec_prefix@
>  libdir=@libdir@
> 
> +ARGS="verbose=$verbose;file=$file;device=$device"
> +if [ ! -z $command ]; then
> +   ARGS="$INTEL_AUBDUMP_ARGS;command=$command;"
> +fi
> +

This needs to be ARGS="$ARGS;command=$command;"

>  LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
> -	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \
> +         INTEL_AUBDUMP_ARGS="$ARGS" \
>  	  exec -- "$@"

Indentation looks off.

There's also an old typo on LD_PRELOAD on the line above, feel free to
fix that at the same time.

With those nitpicks addressed,

Reviewed-by: Petri Latvala <petri.latvala@intel.com>

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 i-g-t] aubdump: add --command option to stream aubdump to another program
  2016-10-06 10:13     ` [PATCH v3 i-g-t] " Lionel Landwerlin
@ 2016-10-06 12:46       ` Ville Syrjälä
  2016-10-06 12:57         ` Lionel Landwerlin
  0 siblings, 1 reply; 13+ messages in thread
From: Ville Syrjälä @ 2016-10-06 12:46 UTC (permalink / raw)
  To: Lionel Landwerlin; +Cc: intel-gfx, Sirisha Gandikota

On Thu, Oct 06, 2016 at 11:13:22AM +0100, Lionel Landwerlin wrote:
> This comes handy if you want to look at your application output without
> having to save it into a file. For example, use this with aubinator from
> Mesa :
> 
> $ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app

Why not just write to stdout so you could just pipe it to something else?

> 
> v2: Fix handling empty command line option
> 
> v3: Fix command line concatenation (again...)
> 
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
> Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
> ---
>  tools/aubdump.c        | 107 ++++++++++++++++++++++++++++++++++++++++---------
>  tools/intel_aubdump.in |  31 +++++++++++++-
>  2 files changed, 117 insertions(+), 21 deletions(-)
> 
> diff --git a/tools/aubdump.c b/tools/aubdump.c
> index 30dc742..3b85bc7 100644
> --- a/tools/aubdump.c
> +++ b/tools/aubdump.c
> @@ -50,6 +50,7 @@ static int (*libc_close)(int fd) = close_init_helper;
>  static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;
> 
>  static int drm_fd = -1;
> +static char *command;
>  static char *filename;
>  static FILE *file;
>  static int gen = 0;
> @@ -113,6 +114,82 @@ fail_if(int cond, const char *format, ...)
>  	raise(SIGTRAP);
>  }
> 
> +static FILE *
> +launch_command(void)
> +{
> +	int i = 0, fds[2];
> +	char **args = calloc(strlen(command), sizeof(char *));
> +	char *iter = command;
> +
> +	args[i++] = iter = command;
> +
> +	while ((iter = strstr(iter, ",")) != NULL) {
> +		*iter = '\0';
> +		iter += 1;
> +		args[i++] = iter;
> +	}
> +
> +	if (pipe(fds) == -1)
> +		return NULL;
> +
> +	switch (fork()) {
> +	case 0:
> +		dup2(fds[0], 0);
> +		fail_if(execv(args[0], args) == -1,
> +			"intel_aubdump: fail to launch child command\n");
> +		return NULL;
> +
> +	default:
> +		free(args);
> +		return fdopen(fds[1], "w");
> +
> +	case -1:
> +		return NULL;
> +	}
> +}
> +
> +static void
> +maybe_init_output(void)
> +{
> +	const char *args;
> +	static bool initialized = false;
> +	int nb_args;
> +
> +	if (initialized)
> +		return;
> +
> +	args = getenv("INTEL_AUBDUMP_ARGS");
> +
> +	nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;command=%m[^;];",
> +			 &verbose, &filename, &device, &command);
> +	if (nb_args != 4) {
> +		if (filename)
> +			free(filename);
> +		nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;",
> +				 &verbose, &filename, &device);
> +		command = strdup("");
> +	}
> +        fail_if(filename == NULL || command == 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");
> +
> +        if (strlen(command) != 0) {
> +          file = launch_command();
> +          fail_if(file == NULL,
> +                  "intel_aubdump: failed to launch command '%s'\n", command);
> +        } else {
> +          file = fopen(filename, "w+");
> +          fail_if(file == NULL,
> +                  "intel_aubdump: failed to open file '%s'\n", filename);
> +        }
> +
> +	initialized = true;
> +}
> +
>  static struct bo *
>  get_bo(uint32_t handle)
>  {
> @@ -140,13 +217,18 @@ align_u64(uint64_t v, uint64_t a)
>  static void
>  dword_out(uint32_t data)
>  {
> -	fwrite(&data, 1, 4, file);
> +	fail_if(fwrite(&data, 1, 4, file) == 0,
> +		"Writing to output failed\n");
>  }
> 
>  static void
>  data_out(const void *data, size_t size)
>  {
> -	fwrite(data, 1, size, file);
> +	if (size == 0)
> +		return;
> +
> +	fail_if(fwrite(data, 1, size, file) == 0,
> +		"Writing to output failed\n");
>  }
> 
>  static void
> @@ -447,6 +529,8 @@ ioctl(int fd, unsigned long request, ...)
>  	}
> 
>  	if (fd == drm_fd) {
> +		maybe_init_output();
> +
>  		switch (request) {
>  		case DRM_IOCTL_I915_GETPARAM: {
>  			struct drm_i915_getparam *getparam = argp;
> @@ -550,26 +634,8 @@ 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
> @@ -596,6 +662,7 @@ ioctl_init_helper(int fd, unsigned long request, ...)
>  static void __attribute__ ((destructor))
>  fini(void)
>  {
> +	free(command);
>  	free(filename);
>  	if (file)
>  		fclose(file);
> diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
> index feee23a..8adf4a5 100644
> --- a/tools/intel_aubdump.in
> +++ b/tools/intel_aubdump.in
> @@ -10,6 +10,9 @@ contents and execution of the GEM application.
> 
>    -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub
> 
> +  -c, --command=CMD  Execute CMD and write the AUB file's content to its
> +                     standard input
> +
>        --device=ID    Override PCI ID of the reported device
> 
>    -v                 Enable verbose output
> @@ -23,6 +26,19 @@ EOF
> 
>  verbose=0
>  device=0
> +file="intel.aub"
> +command=""
> +
> +build_command () {
> +    command=""
> +    for i in $1; do
> +        if [ -z $command ]; then
> +            command=$i
> +        else
> +            command="$command,$i"
> +        fi;
> +    done
> +}
> 
>  while true; do
>        case "$1" in
> @@ -42,6 +58,14 @@ while true; do
>  	      file=${1##--output=}
>  	      shift
>  	      ;;
> +	  -c)
> +              build_command "$2"
> +	      shift 2
> +	      ;;
> +	  --command=*)
> +              build_command "${1##--command=}"
> +	      shift
> +	      ;;
>  	  --device=*)
>  	      device=${1##--device=}
>  	      shift
> @@ -72,6 +96,11 @@ prefix=@prefix@
>  exec_prefix=@exec_prefix@
>  libdir=@libdir@
> 
> +ARGS="verbose=$verbose;file=$file;device=$device"
> +if [ ! -z $command ]; then
> +   ARGS="$ARGS;command=$command;"
> +fi
> +
>  LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
> -	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \
> +         INTEL_AUBDUMP_ARGS="$ARGS" \
>  	  exec -- "$@"
> --
> 2.9.3
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 i-g-t] aubdump: add --command option to stream aubdump to another program
  2016-10-06 12:46       ` Ville Syrjälä
@ 2016-10-06 12:57         ` Lionel Landwerlin
  0 siblings, 0 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2016-10-06 12:57 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: intel-gfx, Sirisha Gandikota

On 06/10/16 13:46, Ville Syrjälä wrote:
> On Thu, Oct 06, 2016 at 11:13:22AM +0100, Lionel Landwerlin wrote:
>> This comes handy if you want to look at your application output without
>> having to save it into a file. For example, use this with aubinator from
>> Mesa :
>>
>> $ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app
> Why not just write to stdout so you could just pipe it to something else?

Most of the applications I've dealt with end writing on stdout as well :(

>
>> v2: Fix handling empty command line option
>>
>> v3: Fix command line concatenation (again...)
>>
>> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>> Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
>> ---
>>   tools/aubdump.c        | 107 ++++++++++++++++++++++++++++++++++++++++---------
>>   tools/intel_aubdump.in |  31 +++++++++++++-
>>   2 files changed, 117 insertions(+), 21 deletions(-)
>>
>> diff --git a/tools/aubdump.c b/tools/aubdump.c
>> index 30dc742..3b85bc7 100644
>> --- a/tools/aubdump.c
>> +++ b/tools/aubdump.c
>> @@ -50,6 +50,7 @@ static int (*libc_close)(int fd) = close_init_helper;
>>   static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;
>>
>>   static int drm_fd = -1;
>> +static char *command;
>>   static char *filename;
>>   static FILE *file;
>>   static int gen = 0;
>> @@ -113,6 +114,82 @@ fail_if(int cond, const char *format, ...)
>>   	raise(SIGTRAP);
>>   }
>>
>> +static FILE *
>> +launch_command(void)
>> +{
>> +	int i = 0, fds[2];
>> +	char **args = calloc(strlen(command), sizeof(char *));
>> +	char *iter = command;
>> +
>> +	args[i++] = iter = command;
>> +
>> +	while ((iter = strstr(iter, ",")) != NULL) {
>> +		*iter = '\0';
>> +		iter += 1;
>> +		args[i++] = iter;
>> +	}
>> +
>> +	if (pipe(fds) == -1)
>> +		return NULL;
>> +
>> +	switch (fork()) {
>> +	case 0:
>> +		dup2(fds[0], 0);
>> +		fail_if(execv(args[0], args) == -1,
>> +			"intel_aubdump: fail to launch child command\n");
>> +		return NULL;
>> +
>> +	default:
>> +		free(args);
>> +		return fdopen(fds[1], "w");
>> +
>> +	case -1:
>> +		return NULL;
>> +	}
>> +}
>> +
>> +static void
>> +maybe_init_output(void)
>> +{
>> +	const char *args;
>> +	static bool initialized = false;
>> +	int nb_args;
>> +
>> +	if (initialized)
>> +		return;
>> +
>> +	args = getenv("INTEL_AUBDUMP_ARGS");
>> +
>> +	nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;command=%m[^;];",
>> +			 &verbose, &filename, &device, &command);
>> +	if (nb_args != 4) {
>> +		if (filename)
>> +			free(filename);
>> +		nb_args = sscanf(args, "verbose=%d;file=%m[^;];device=%i;",
>> +				 &verbose, &filename, &device);
>> +		command = strdup("");
>> +	}
>> +        fail_if(filename == NULL || command == 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");
>> +
>> +        if (strlen(command) != 0) {
>> +          file = launch_command();
>> +          fail_if(file == NULL,
>> +                  "intel_aubdump: failed to launch command '%s'\n", command);
>> +        } else {
>> +          file = fopen(filename, "w+");
>> +          fail_if(file == NULL,
>> +                  "intel_aubdump: failed to open file '%s'\n", filename);
>> +        }
>> +
>> +	initialized = true;
>> +}
>> +
>>   static struct bo *
>>   get_bo(uint32_t handle)
>>   {
>> @@ -140,13 +217,18 @@ align_u64(uint64_t v, uint64_t a)
>>   static void
>>   dword_out(uint32_t data)
>>   {
>> -	fwrite(&data, 1, 4, file);
>> +	fail_if(fwrite(&data, 1, 4, file) == 0,
>> +		"Writing to output failed\n");
>>   }
>>
>>   static void
>>   data_out(const void *data, size_t size)
>>   {
>> -	fwrite(data, 1, size, file);
>> +	if (size == 0)
>> +		return;
>> +
>> +	fail_if(fwrite(data, 1, size, file) == 0,
>> +		"Writing to output failed\n");
>>   }
>>
>>   static void
>> @@ -447,6 +529,8 @@ ioctl(int fd, unsigned long request, ...)
>>   	}
>>
>>   	if (fd == drm_fd) {
>> +		maybe_init_output();
>> +
>>   		switch (request) {
>>   		case DRM_IOCTL_I915_GETPARAM: {
>>   			struct drm_i915_getparam *getparam = argp;
>> @@ -550,26 +634,8 @@ 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
>> @@ -596,6 +662,7 @@ ioctl_init_helper(int fd, unsigned long request, ...)
>>   static void __attribute__ ((destructor))
>>   fini(void)
>>   {
>> +	free(command);
>>   	free(filename);
>>   	if (file)
>>   		fclose(file);
>> diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
>> index feee23a..8adf4a5 100644
>> --- a/tools/intel_aubdump.in
>> +++ b/tools/intel_aubdump.in
>> @@ -10,6 +10,9 @@ contents and execution of the GEM application.
>>
>>     -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub
>>
>> +  -c, --command=CMD  Execute CMD and write the AUB file's content to its
>> +                     standard input
>> +
>>         --device=ID    Override PCI ID of the reported device
>>
>>     -v                 Enable verbose output
>> @@ -23,6 +26,19 @@ EOF
>>
>>   verbose=0
>>   device=0
>> +file="intel.aub"
>> +command=""
>> +
>> +build_command () {
>> +    command=""
>> +    for i in $1; do
>> +        if [ -z $command ]; then
>> +            command=$i
>> +        else
>> +            command="$command,$i"
>> +        fi;
>> +    done
>> +}
>>
>>   while true; do
>>         case "$1" in
>> @@ -42,6 +58,14 @@ while true; do
>>   	      file=${1##--output=}
>>   	      shift
>>   	      ;;
>> +	  -c)
>> +              build_command "$2"
>> +	      shift 2
>> +	      ;;
>> +	  --command=*)
>> +              build_command "${1##--command=}"
>> +	      shift
>> +	      ;;
>>   	  --device=*)
>>   	      device=${1##--device=}
>>   	      shift
>> @@ -72,6 +96,11 @@ prefix=@prefix@
>>   exec_prefix=@exec_prefix@
>>   libdir=@libdir@
>>
>> +ARGS="verbose=$verbose;file=$file;device=$device"
>> +if [ ! -z $command ]; then
>> +   ARGS="$ARGS;command=$command;"
>> +fi
>> +
>>   LD_PRELOAD=${libdir}/intel_aubdump.so${LD_PPRELOAD:+:${LD_PRELOAD}} \
>> -	  INTEL_AUBDUMP_ARGS="verbose=$verbose;file=$file;device=$device" \
>> +         INTEL_AUBDUMP_ARGS="$ARGS" \
>>   	  exec -- "$@"
>> --
>> 2.9.3
>> _______________________________________________
>> Intel-gfx mailing list
>> Intel-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/intel-gfx


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor
  2016-10-04 14:21 [PATCH] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
  2016-10-05 22:48 ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Lionel Landwerlin
@ 2016-11-01 18:15 ` Lionel Landwerlin
  2016-11-01 18:15   ` [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
  2016-11-01 21:41   ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Gandikota, Sirisha
  1 sibling, 2 replies; 13+ messages in thread
From: Lionel Landwerlin @ 2016-11-01 18:15 UTC (permalink / raw)
  To: intel-gfx

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)

v3: Fix behavior change between bash 4.3 & 4.4 in <<< with \n characters
    (Lionel)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 tools/aubdump.c        | 58 ++++++++++++++++++++++++++++++++++++--------------
 tools/intel_aubdump.in | 24 +++++++++++++++------
 2 files changed, 59 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..18fd03b 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,13 @@ 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<<EOF
+`echo -e $args`
+EOF
--
2.10.2
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program
  2016-11-01 18:15 ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Lionel Landwerlin
@ 2016-11-01 18:15   ` Lionel Landwerlin
  2016-11-01 21:40     ` Gandikota, Sirisha
  2016-11-01 21:41   ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Gandikota, Sirisha
  1 sibling, 1 reply; 13+ messages in thread
From: Lionel Landwerlin @ 2016-11-01 18:15 UTC (permalink / raw)
  To: intel-gfx; +Cc: Sirisha Gandikota

This comes handy if you want to look at your application output without
having to save it into a file. For example, use this with aubinator from
Mesa :

$ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app

v2: Fix handling empty command line option

v3: Fix command line concatenation (again...)

v4: Use execvp (Petri)
    Indentation (Petri)
    Allow recording to a file and stream to an external application (Lionel)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
---
 tools/aubdump.c        | 83 ++++++++++++++++++++++++++++++++++++++++++++------
 tools/intel_aubdump.in | 26 +++++++++++++++-
 2 files changed, 98 insertions(+), 11 deletions(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index f2cd2c1..f7ef699 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -43,6 +43,10 @@
 #include "intel_aub.h"
 #include "intel_chipset.h"

+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+#endif
+
 static int close_init_helper(int fd);
 static int ioctl_init_helper(int fd, unsigned long request, ...);

@@ -50,8 +54,8 @@ static int (*libc_close)(int fd) = close_init_helper;
 static int (*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;

 static int drm_fd = -1;
-static char *filename;
-static FILE *file;
+static char *filename = NULL;
+static FILE *files[2] = { NULL, NULL };
 static int gen = 0;
 static int verbose = 0;
 static const uint32_t gtt_size = 0x10000;
@@ -140,13 +144,28 @@ align_u64(uint64_t v, uint64_t a)
 static void
 dword_out(uint32_t data)
 {
-	fwrite(&data, 1, 4, file);
+	for (int i = 0; i < ARRAY_SIZE (files); i++) {
+		if (files[i] == NULL)
+			continue;
+
+		fail_if(fwrite(&data, 1, 4, files[i]) == 0,
+			"Writing to output failed\n");
+	}
 }

 static void
 data_out(const void *data, size_t size)
 {
-	fwrite(data, 1, size, file);
+	if (size == 0)
+		return;
+
+	for (int i = 0; i < ARRAY_SIZE (files); i++) {
+		if (files[i] == NULL)
+			continue;
+
+		fail_if(fwrite(data, 1, size, files[i]) == 0,
+			"Writing to output failed\n");
+	}
 }

 static void
@@ -393,7 +412,10 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
 	aub_dump_ringbuffer(batch_bo->offset + execbuffer2->batch_start_offset,
 			    offset, ring_flag);

-	fflush(file);
+	for (int i = 0; i < ARRAY_SIZE(files); i++) {
+		if (files[i] != NULL)
+			fflush(files[i]);
+	}
 }

 static void
@@ -426,6 +448,40 @@ close(int fd)
 	return libc_close(fd);
 }

+static FILE *
+launch_command(char *command)
+{
+	int i = 0, fds[2];
+	char **args = calloc(strlen(command), sizeof(char *));
+	char *iter = command;
+
+	args[i++] = iter = command;
+
+	while ((iter = strstr(iter, ",")) != NULL) {
+		*iter = '\0';
+		iter += 1;
+		args[i++] = iter;
+	}
+
+	if (pipe(fds) == -1)
+		return NULL;
+
+	switch (fork()) {
+	case 0:
+		dup2(fds[0], 0);
+		fail_if(execvp(args[0], args) == -1,
+			"intel_aubdump: failed to launch child command\n");
+		return NULL;
+
+	default:
+		free(args);
+		return fdopen(fds[1], "w");
+
+	case -1:
+		return NULL;
+	}
+}
+
 static void
 maybe_init(void)
 {
@@ -448,11 +504,16 @@ maybe_init(void)
 				value);
 			device_override = true;
 		} else if (!strcmp(key, "file")) {
-			filename = value;
-			file = fopen(filename, "w+");
-			fail_if(file == NULL,
+			filename = strdup(value);
+			files[0] = fopen(filename, "w+");
+			fail_if(files[0] == NULL,
 				"intel_aubdump: failed to open file '%s'\n",
 				filename);
+		} else if (!strcmp(key,  "command")) {
+			files[1] = launch_command(value);
+			fail_if(files[1] == NULL,
+				"intel_aubdump: failed to launch command '%s'\n",
+				value);
 		} else {
 			fprintf(stderr, "intel_aubdump: unknown option '%s'\n", key);
 		}
@@ -623,7 +684,9 @@ static void __attribute__ ((destructor))
 fini(void)
 {
 	free(filename);
-	if (file)
-		fclose(file);
+	for (int i = 0; i < ARRAY_SIZE(files); i++) {
+		if (files[i] != NULL)
+			fclose(files[i]);
+	}
 	free(bos);
 }
diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in
index 18fd03b..343dc29 100644
--- a/tools/intel_aubdump.in
+++ b/tools/intel_aubdump.in
@@ -10,6 +10,9 @@ contents and execution of the GEM application.

   -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub

+  -c, --command=CMD  Execute CMD and write the AUB file's content to its
+                     standard input
+
       --device=ID    Override PCI ID of the reported device

   -v                 Enable verbose output
@@ -30,6 +33,17 @@ function add_arg() {
     args="$args$arg\n"
 }

+function build_command () {
+      command=""
+      for i in $1; do
+	  if [ -z $command ]; then
+	      command=$i
+	  else
+	      command="$command,$i"
+	  fi;
+      done
+}
+
 while true; do
       case "$1" in
 	  -o)
@@ -51,6 +65,16 @@ while true; do
 	      add_arg "file=${file:-$(basename ${file}).aub}"
 	      shift
 	      ;;
+	  -c)
+	      build_command "$2"
+	      add_arg "command=$command"
+	      shift 2
+	      ;;
+	  --command=*)
+	      build_command "${1##--command=}"
+	      add_arg "command=$command"
+	      shift
+	      ;;
 	  --device=*)
 	      add_arg "device=${1##--device=}"
 	      shift
@@ -75,7 +99,7 @@ done

 [ -z $1 ] && show_help

-[ -z $file ] && add_arg "file=intel.aub"
+[ -z $file ] && [ -z $command ] && add_arg "file=intel.aub"

 prefix=@prefix@
 exec_prefix=@exec_prefix@
--
2.10.2
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program
  2016-11-01 18:15   ` [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
@ 2016-11-01 21:40     ` Gandikota, Sirisha
  0 siblings, 0 replies; 13+ messages in thread
From: Gandikota, Sirisha @ 2016-11-01 21:40 UTC (permalink / raw)
  To: Landwerlin, Lionel G, intel-gfx

>-----Original Message-----
>From: Landwerlin, Lionel G
>Sent: Tuesday, November 01, 2016 11:15 AM
>To: intel-gfx@lists.freedesktop.org
>Cc: Landwerlin, Lionel G <lionel.g.landwerlin@intel.com>; Gandikota, Sirisha
><sirisha.gandikota@intel.com>
>Subject: [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream
>aubdump to another program
>
>This comes handy if you want to look at your application output without having
>to save it into a file. For example, use this with aubinator from Mesa :
>
>$ intel_aubdump -c '/path/to/aubinator --gen=hsw' my_gl_app
>
>v2: Fix handling empty command line option
>
>v3: Fix command line concatenation (again...)
>
>v4: Use execvp (Petri)
>    Indentation (Petri)
>    Allow recording to a file and stream to an external application (Lionel)
>
>Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>Cc: Sirisha Gandikota <Sirisha.Gandikota@intel.com>
>---
> tools/aubdump.c        | 83
>++++++++++++++++++++++++++++++++++++++++++++------
> tools/intel_aubdump.in | 26 +++++++++++++++-
> 2 files changed, 98 insertions(+), 11 deletions(-)
>
>diff --git a/tools/aubdump.c b/tools/aubdump.c index f2cd2c1..f7ef699 100644
>--- a/tools/aubdump.c
>+++ b/tools/aubdump.c
>@@ -43,6 +43,10 @@
> #include "intel_aub.h"
> #include "intel_chipset.h"
>
>+#ifndef ARRAY_SIZE
>+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) #endif
>+
> static int close_init_helper(int fd);
> static int ioctl_init_helper(int fd, unsigned long request, ...);
>
>@@ -50,8 +54,8 @@ static int (*libc_close)(int fd) = close_init_helper;  static int
>(*libc_ioctl)(int fd, unsigned long request, ...) = ioctl_init_helper;
>
> static int drm_fd = -1;
>-static char *filename;
>-static FILE *file;
>+static char *filename = NULL;
>+static FILE *files[2] = { NULL, NULL };
> static int gen = 0;
> static int verbose = 0;
> static const uint32_t gtt_size = 0x10000; @@ -140,13 +144,28 @@
>align_u64(uint64_t v, uint64_t a)  static void  dword_out(uint32_t data)  {
>-	fwrite(&data, 1, 4, file);
>+	for (int i = 0; i < ARRAY_SIZE (files); i++) {
>+		if (files[i] == NULL)
>+			continue;
>+
>+		fail_if(fwrite(&data, 1, 4, files[i]) == 0,
>+			"Writing to output failed\n");
>+	}
> }
>
> static void
> data_out(const void *data, size_t size)  {
>-	fwrite(data, 1, size, file);
>+	if (size == 0)
>+		return;
>+
>+	for (int i = 0; i < ARRAY_SIZE (files); i++) {
>+		if (files[i] == NULL)
>+			continue;
>+
>+		fail_if(fwrite(data, 1, size, files[i]) == 0,
>+			"Writing to output failed\n");
>+	}
> }
>
> static void
>@@ -393,7 +412,10 @@ dump_execbuffer2(int fd, struct
>drm_i915_gem_execbuffer2 *execbuffer2)
> 	aub_dump_ringbuffer(batch_bo->offset + execbuffer2-
>>batch_start_offset,
> 			    offset, ring_flag);
>
>-	fflush(file);
>+	for (int i = 0; i < ARRAY_SIZE(files); i++) {
>+		if (files[i] != NULL)
>+			fflush(files[i]);
>+	}
> }
>
> static void
>@@ -426,6 +448,40 @@ close(int fd)
> 	return libc_close(fd);
> }
>
>+static FILE *
>+launch_command(char *command)
>+{
>+	int i = 0, fds[2];
>+	char **args = calloc(strlen(command), sizeof(char *));
>+	char *iter = command;
>+
>+	args[i++] = iter = command;
>+
>+	while ((iter = strstr(iter, ",")) != NULL) {
>+		*iter = '\0';
>+		iter += 1;
>+		args[i++] = iter;
>+	}
>+
>+	if (pipe(fds) == -1)
>+		return NULL;
>+
>+	switch (fork()) {
>+	case 0:
>+		dup2(fds[0], 0);
>+		fail_if(execvp(args[0], args) == -1,
>+			"intel_aubdump: failed to launch child command\n");
>+		return NULL;
>+
>+	default:
>+		free(args);
>+		return fdopen(fds[1], "w");
>+
>+	case -1:
>+		return NULL;
>+	}
>+}
>+
> static void
> maybe_init(void)
> {
>@@ -448,11 +504,16 @@ maybe_init(void)
> 				value);
> 			device_override = true;
> 		} else if (!strcmp(key, "file")) {
>-			filename = value;
>-			file = fopen(filename, "w+");
>-			fail_if(file == NULL,
>+			filename = strdup(value);
>+			files[0] = fopen(filename, "w+");
>+			fail_if(files[0] == NULL,
> 				"intel_aubdump: failed to open file '%s'\n",
> 				filename);
>+		} else if (!strcmp(key,  "command")) {
>+			files[1] = launch_command(value);
>+			fail_if(files[1] == NULL,
>+				"intel_aubdump: failed to launch command
>'%s'\n",
>+				value);
> 		} else {
> 			fprintf(stderr, "intel_aubdump: unknown option '%s'\n",
>key);
> 		}
>@@ -623,7 +684,9 @@ static void __attribute__ ((destructor))
> fini(void)
> {
> 	free(filename);
>-	if (file)
>-		fclose(file);
>+	for (int i = 0; i < ARRAY_SIZE(files); i++) {
>+		if (files[i] != NULL)
>+			fclose(files[i]);
>+	}
> 	free(bos);
> }
>diff --git a/tools/intel_aubdump.in b/tools/intel_aubdump.in index
>18fd03b..343dc29 100644
>--- a/tools/intel_aubdump.in
>+++ b/tools/intel_aubdump.in
>@@ -10,6 +10,9 @@ contents and execution of the GEM application.
>
>   -o, --output=FILE  Name of AUB file. Defaults to COMMAND.aub
>
>+  -c, --command=CMD  Execute CMD and write the AUB file's content to its
>+                     standard input
>+
>       --device=ID    Override PCI ID of the reported device
>
>   -v                 Enable verbose output
>@@ -30,6 +33,17 @@ function add_arg() {
>     args="$args$arg\n"
> }
>
>+function build_command () {
>+      command=""
>+      for i in $1; do
>+	  if [ -z $command ]; then
>+	      command=$i
>+	  else
>+	      command="$command,$i"
>+	  fi;
>+      done
>+}
>+
> while true; do
>       case "$1" in
> 	  -o)
>@@ -51,6 +65,16 @@ while true; do
> 	      add_arg "file=${file:-$(basename ${file}).aub}"
> 	      shift
> 	      ;;
>+	  -c)
>+	      build_command "$2"
>+	      add_arg "command=$command"
>+	      shift 2
>+	      ;;
>+	  --command=*)
>+	      build_command "${1##--command=}"
>+	      add_arg "command=$command"
>+	      shift
>+	      ;;
> 	  --device=*)
> 	      add_arg "device=${1##--device=}"
> 	      shift
>@@ -75,7 +99,7 @@ done
>
> [ -z $1 ] && show_help
>
>-[ -z $file ] && add_arg "file=intel.aub"
>+[ -z $file ] && [ -z $command ] && add_arg "file=intel.aub"
>
> prefix=@prefix@
> exec_prefix=@exec_prefix@
>--
>2.10.2

[SG] Works for me
Reviewed-by: Sirisha Gandikota <sirisha.gandikota@intel.com>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor
  2016-11-01 18:15 ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Lionel Landwerlin
  2016-11-01 18:15   ` [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
@ 2016-11-01 21:41   ` Gandikota, Sirisha
  1 sibling, 0 replies; 13+ messages in thread
From: Gandikota, Sirisha @ 2016-11-01 21:41 UTC (permalink / raw)
  To: Landwerlin, Lionel G, intel-gfx

>-----Original Message-----
>From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf Of
>Lionel Landwerlin
>Sent: Tuesday, November 01, 2016 11:15 AM
>To: intel-gfx@lists.freedesktop.org
>Subject: [Intel-gfx] [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration
>through file descriptor
>
>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)
>
>v3: Fix behavior change between bash 4.3 & 4.4 in <<< with \n characters
>    (Lionel)
>
>Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>---
> tools/aubdump.c        | 58 ++++++++++++++++++++++++++++++++++++------------
>--
> tools/intel_aubdump.in | 24 +++++++++++++++------
> 2 files changed, 59 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..18fd03b 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,13 @@ 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<<EOF
>+`echo -e $args`
>+EOF
>--
>2.10.2

 [SG] Works for me
Reviewed-by: Sirisha Gandikota <sirisha.gandikota@intel.com>
__________________________________________
>Intel-gfx mailing list
>Intel-gfx@lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-11-01 21:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-04 14:21 [PATCH] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
2016-10-05 22:48 ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Lionel Landwerlin
2016-10-05 22:48   ` [PATCH v2 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
2016-10-06 10:13     ` [PATCH v3 i-g-t] " Lionel Landwerlin
2016-10-06 12:46       ` Ville Syrjälä
2016-10-06 12:57         ` Lionel Landwerlin
2016-10-06 10:25     ` [PATCH v2 i-g-t 2/2] " Petri Latvala
2016-10-06  9:09   ` [PATCH i-g-t 1/2] aubdump: remove already handled -o Petri Latvala
2016-10-06  9:16     ` Lionel Landwerlin
2016-11-01 18:15 ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Lionel Landwerlin
2016-11-01 18:15   ` [PATCH v4 i-g-t 2/2] aubdump: add --command option to stream aubdump to another program Lionel Landwerlin
2016-11-01 21:40     ` Gandikota, Sirisha
2016-11-01 21:41   ` [PATCH v3 i-g-t 1/2] tools: intel_aubdump: pass configuration through file descriptor Gandikota, Sirisha

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.