From patchwork Tue Oct 4 14:21:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lionel Landwerlin X-Patchwork-Id: 9361961 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 88E8F607D6 for ; Tue, 4 Oct 2016 14:21:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AA05287E5 for ; Tue, 4 Oct 2016 14:21:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E9E6287ED; Tue, 4 Oct 2016 14:21:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E6241287F1 for ; Tue, 4 Oct 2016 14:21:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C8276E685; Tue, 4 Oct 2016 14:21:19 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 013616E685 for ; Tue, 4 Oct 2016 14:21:17 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id f193so15322910wmg.2 for ; Tue, 04 Oct 2016 07:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZxPOGHWZ3rzHq5nhzizpdGgeJQe9/lkY4GnRfGMvoE0=; b=My3MdvivxQ/7vrxhcxxFRZXjNC84B9zV/mFdN4QmILJKhKwViCuO1tJvvE/7NIAv/Q 9yIqDUsji5N5fX1rBw2ZpZ/06BfkLESven7Il82ADIUv0ZyFfghh8e72VLLVPaK4Gt1/ YjIlgcfR5wvjcQckuO+oTyybYGCfA6XDlr4TnFq4p7rK5Ohyyd0EYn4SA6pvtPq0GCql L6pOJePNWDE9/teC3pL2BnNB227WuWsjXE+ev/s0m+XSTkWOuRWPnPzMMYiOzPdvL7sZ FOiqf5B+4FXWrSvNZ0FJroWZ3SSi/DuSfty1I7UumXPby6RbAEL4ftUU6ivxDWKG7A9W GTkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZxPOGHWZ3rzHq5nhzizpdGgeJQe9/lkY4GnRfGMvoE0=; b=Af7FXj/l8TKzAIV0w6GBe2Xzvp3nJqVDUOPlGXb71ZMGI6YCnpLPIPeuihAeTBuYbP cF7NnrtnS5WIYsIh3W9LsFu7J0ojp1jt+bfufPd1HdMVKedi/BWy8gtimiFySt72yAQA dxqa0ZVVpoAttuXHZHtFYFnwlDDX/3pIkuRNgntMwLITlKGtIzSwOlKXHj4OjVkCg6Ya vWlz2B4wcbow2NUe5NJ4irfl6TjdJPeM9gzVCRCfoke0Qp7aGxiHCxmKjx8ii6L//joB IW71kphsgO2y3FeuVEvAniIXXt3vDgo+UWZqLKjor4+mQnb9RiEjRkx973Mv+kMaTvi1 JnaA== X-Gm-Message-State: AA6/9RlcAqgCM9mlCjzVLlLJoDyWgnPeGJhmy/rHHH5st9jdjWVDtgRTLX4ds27mhxmwug== X-Received: by 10.28.113.80 with SMTP id m77mr4220840wmc.18.1475590875405; Tue, 04 Oct 2016 07:21:15 -0700 (PDT) Received: from localhost.localdomain ([192.198.151.61]) by smtp.googlemail.com with ESMTPSA id g9sm3822708wjk.25.2016.10.04.07.21.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Oct 2016 07:21:14 -0700 (PDT) From: Lionel Landwerlin X-Google-Original-From: Lionel Landwerlin To: intel-gfx@lists.freedesktop.org Date: Tue, 4 Oct 2016 15:21:11 +0100 Message-Id: <20161004142111.20370-1-lionel.g.landwerlin@intel.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] aubdump: add --command option to stream aubdump to another program X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Kristian Høgsberg --- 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 -- "$@"