From patchwork Mon Sep 5 20:19:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeni Dodonov X-Patchwork-Id: 1125452 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p85KNlOG000765 for ; Mon, 5 Sep 2011 20:24:07 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A868A0997 for ; Mon, 5 Sep 2011 13:23:47 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from oproxy9.bluehost.com (oproxy9.bluehost.com [69.89.24.6]) by gabe.freedesktop.org (Postfix) with SMTP id 99F82A0980 for ; Mon, 5 Sep 2011 13:20:44 -0700 (PDT) Received: (qmail 30226 invoked by uid 0); 5 Sep 2011 20:20:44 -0000 Received: from unknown (HELO box335.bluehost.com) (69.89.31.135) by oproxy9.bluehost.com with SMTP; 5 Sep 2011 20:20:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dodonov.net; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=EsL0krmdEAH+mX5B0l6aln4r3FzWQfdYFn2CP1kYr/s=; b=M/hV32NStTUrD5QQv+83M8q95XNQ5+XD7K4LIqUkBZYG/UAxi+8gyUHLYtb3tJb4Gg97A5UFaWGpCAXIldKQ1wgbxxq0ZmphG4apmxyengIF7gYYTe6MWGzUvHtfJb/A; Received: from 200.188.217.18.dedicated.neoviatelecom.com.br ([200.188.217.18] helo=localhost.localdomain) by box335.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1R0fet-0007ag-R4; Mon, 05 Sep 2011 14:20:44 -0600 From: Eugeni Dodonov To: intel-gfx@lists.freedesktop.org Date: Mon, 5 Sep 2011 17:19:33 -0300 Message-Id: <1315253973-18950-7-git-send-email-eugeni@dodonov.net> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <1315253973-18950-1-git-send-email-eugeni@dodonov.net> References: <1315253973-18950-1-git-send-email-eugeni@dodonov.net> X-Identified-User: {669:box335.bluehost.com:dodonovn:dodonov.net} {sentby:smtp auth 200.188.217.18 authed with eugeni@dodonov.net} Cc: Eugeni Dodonov Subject: [Intel-gfx] [PATCH 6/6] intel_gpu_top: support profiling user-specified commands X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 05 Sep 2011 20:24:22 +0000 (UTC) From: Eugeni Dodonov This patch adds support for running intel_gpu_top to profile specific commands. The required command will be carried out in separate process, and main intel_gpu_top will leave when the child process will exit. Signed-off-by: Eugeni Dodonov --- man/intel_gpu_top.1 | 10 ++++++++ tools/intel_gpu_top.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletions(-) diff --git a/man/intel_gpu_top.1 b/man/intel_gpu_top.1 index bca83f0..db2f362 100644 --- a/man/intel_gpu_top.1 +++ b/man/intel_gpu_top.1 @@ -19,8 +19,18 @@ number of samples to acquire per second .B -o [output file] run non-interactively and collect usage statistics to [file] .TP +.B -e ["command to profile"] +execute a command, and leave when it is finished. Note that the entire command +with all parameters should be included as one parameter. +.TP .B -h show usage notes +.SH EXAMPLES +.TP +intel_gpu_top -o "cairo-trace-gvim.log" -s 100 -e "cairo-perf-trace /tmp/gvim" +will run cairo-perf-trace with /tmp/gvim trace, non-interactively, saving the +statistics into cairo-trace-gvim.log file, and collecting 100 samples per +second. .PP Note that idle units are not displayed, so an entirely idle GPU will only display the ring status and diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 88f7157..3619d1b 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "intel_gpu_tools.h" #include "instdone.h" @@ -447,12 +449,17 @@ int main(int argc, char **argv) FILE *output = stdout; double elapsed_time=0; int print_headers=1; + pid_t child_pid=-1; + int child_stat; + char *cmd=NULL; /* Parse options? */ - while ((ch = getopt(argc, argv, "s:o:h")) != -1) + while ((ch = getopt(argc, argv, "s:o:e:h")) != -1) { switch (ch) { + case 'e': cmd = strdup(optarg); + break; case 's': samples_per_sec = atoi(optarg); if (samples_per_sec < 100) { fprintf(stderr, "Error: samples per second must be >= 100\n"); @@ -481,6 +488,37 @@ int main(int argc, char **argv) argc -= optind; argv += optind; + /* Do we have a command to run? */ + if (cmd != NULL) + { + if (output != stdout) { + fprintf(output, "# Profiling: %s\n", cmd); + fflush(output); + } + child_pid = fork(); + if (child_pid < 0) + { + perror("fork"); + exit(1); + } + else if (child_pid == 0) { + int res; + res = system(cmd); + free(cmd); + if (res < 0) + perror("running command"); + if (output != stdout) { + fflush(output); + fprintf(output, "# %s exited with status %d\n", cmd, res); + fflush(output); + } + exit(0); + } + else { + free(cmd); + } + } + pci_dev = intel_get_pci_device(); devid = pci_dev->device_id; intel_get_mmio(pci_dev); @@ -673,7 +711,23 @@ int main(int argc, char **argv) if (i < STATS_COUNT) last_stats[i] = stats[i]; } + + /* Check if child has gone */ + if (child_pid > 0) + { + int res; + if ((res = waitpid(child_pid, &child_stat, WNOHANG)) == -1) { + perror("waitpid"); + exit(1); + } + if (res == 0) + continue; + if (WIFEXITED(child_stat)) + break; + } } + fclose(output); + return 0; }