From patchwork Thu Oct 6 15:16:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lionel Landwerlin X-Patchwork-Id: 9364939 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 B40466077E for ; Thu, 6 Oct 2016 15:16:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A57572909F for ; Thu, 6 Oct 2016 15:16:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99F67290A2; Thu, 6 Oct 2016 15:16:56 +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 7B460290A0 for ; Thu, 6 Oct 2016 15:16:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 84BA26E9E6; Thu, 6 Oct 2016 15:16:46 +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 DD1F76E9EA for ; Thu, 6 Oct 2016 15:16:44 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id 123so3988190wmb.3 for ; Thu, 06 Oct 2016 08:16:44 -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:in-reply-to:references; bh=Z4xUPQvYukemDe3ZqnDZ3B5kA9+cwA+yALfyI7Tk2Gk=; b=eMHAuO3H3ua8mgCaK7RFrZfRLDDOTCsDVtBk8P5q1EpdPwwtH0jzw38xreVfobsuNY pjXmAiZ6/05CZB9Cw9z3E4h5CRTw7qwzS7Bsg8dycBOi91PDWZWngm2+dBgoR9zj6rx1 sx5eE1Q8vOKHBjXZmG441eFDa7MemeIaaqxyp/Vw4fIqjEQX58rUjoaQTeL8IrFOSpXg 7VV6AmfVWEAUzlPMJD61OKpMM9gve+Xch5lvPqOWE6+cM9ZMN/p1brRzU+kY+8w3j68f e0ZDOnV9BSYIkMxOaqOQup8ORBfxc1VUaoRId5KOOGc24q9uN0qwqp1atLKZNidYXSvy zMRg== 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:in-reply-to :references; bh=Z4xUPQvYukemDe3ZqnDZ3B5kA9+cwA+yALfyI7Tk2Gk=; b=XyUHL/w/h/pZlHM8wlOP7eKO7lnoOhR0NPTWR4TswvtOR3f7YAGQKa9zee1GjbwG3j ZAsPw/vh2Qtp/I4CCYbk+ZMML3dj2GMbDEgWE8qk9Blx+GXFE0yN4eXewO1PCORqdfxW mnYXPvVxw2wAZiPUXYzI1CpDKFchizWo8/iq4ruufIiDYNF7xfKsk3WwaBZXI7zRLjmo g1I2PM4uGR0g+rCyqWNGM557y1LVOlS56FYzN0xgNjQ36V7OQJb42MGeImR2UY5jCRG/ EffQfryKumQ3brPGVGDW2yzE/OS+/ZyEkCjcPFGe7LTYfgKCsPMKjDYTZVPzHuNsqX1H sVYQ== X-Gm-Message-State: AA6/9RmAhnLapFg2TQWMNUPENLwUpX0aNAyHI42r94Cam/Hssvzr1hSCSx3sDPd51bAxgQ== X-Received: by 10.28.212.129 with SMTP id l123mr9708775wmg.22.1475767003028; Thu, 06 Oct 2016 08:16:43 -0700 (PDT) Received: from localhost.localdomain ([192.198.151.61]) by smtp.googlemail.com with ESMTPSA id u185sm15516997wmu.20.2016.10.06.08.16.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 08:16:42 -0700 (PDT) From: Lionel Landwerlin X-Google-Original-From: Lionel Landwerlin To: intel-gfx@lists.freedesktop.org Date: Thu, 6 Oct 2016 16:16:35 +0100 Message-Id: <20161006151635.28573-3-lionel.g.landwerlin@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161006151635.28573-1-lionel.g.landwerlin@intel.com> References: <20161006151635.28573-1-lionel.g.landwerlin@intel.com> Cc: Sirisha Gandikota Subject: [Intel-gfx] [PATCH v4 i-g-t 3/3] 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: , MIME-Version: 1.0 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 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 Cc: Sirisha Gandikota --- tools/aubdump.c | 81 ++++++++++++++++++++++++++++++++++++++++++++------ tools/intel_aubdump.in | 26 +++++++++++++++- 2 files changed, 97 insertions(+), 10 deletions(-) -- 2.9.3 diff --git a/tools/aubdump.c b/tools/aubdump.c index e82b514..61aa83c 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) { @@ -447,10 +503,15 @@ maybe_init(void) device_override = true; } else if (!strcmp(key, "file")) { filename = value; - file = fopen(filename, "w+"); - fail_if(file == NULL, + 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); } @@ -621,7 +682,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 445b60f..a8e96d6 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@