From patchwork Mon Sep 5 20:19:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeni Dodonov X-Patchwork-Id: 1125412 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 p85KLmte000526 for ; Mon, 5 Sep 2011 20:22:08 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A31E39F51D for ; Mon, 5 Sep 2011 13:21:48 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from oproxy3-pub.bluehost.com (oproxy3-pub.bluehost.com [69.89.21.8]) by gabe.freedesktop.org (Postfix) with SMTP id B8D2CA0981 for ; Mon, 5 Sep 2011 13:20:30 -0700 (PDT) Received: (qmail 13057 invoked by uid 0); 5 Sep 2011 20:20:30 -0000 Received: from unknown (HELO box335.bluehost.com) (69.89.31.135) by oproxy3.bluehost.com with SMTP; 5 Sep 2011 20:20:30 -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=Lw5ZzOZqOL4KNacy18mMhomrdDZf3J557/M7rKOgGLM=; b=Lb3ZBc0g24LytzpfXuU6vqfUEw8lvawg+gvXBJWVLwufyHgmahAsDav93GkHboEKcWm5Gy2BIuPrEBMmN8Wea8OkBad5kOzRNRB2466WvVc4uzfjUwug4NmwSym29GqX; 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 1R0fee-0007ag-Ge; Mon, 05 Sep 2011 14:20:30 -0600 From: Eugeni Dodonov To: intel-gfx@lists.freedesktop.org Date: Mon, 5 Sep 2011 17:19:29 -0300 Message-Id: <1315253973-18950-3-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 2/6] intel_gpu_top: suport command line parameters and variable samples per second 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:22:13 +0000 (UTC) From: Eugeni Dodonov This patch adds support for getopt, and adds two default parameters to it: -h to show usage notes; and -s to allow user to define number of samples to acquire per second. Manpage documentation is also adjusted accordingly. Signed-off-by: Eugeni Dodonov --- man/intel_gpu_top.1 | 9 ++++++++ tools/intel_gpu_top.c | 52 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/man/intel_gpu_top.1 b/man/intel_gpu_top.1 index 79c9c0e..2cbbec9 100644 --- a/man/intel_gpu_top.1 +++ b/man/intel_gpu_top.1 @@ -4,11 +4,20 @@ .SH NAME intel_gpu_top \- Display a top-like summary of Intel GPU usage .SH SYNOPSIS +.nf .B intel_gpu_top +.B intel_gpu_top [ parameters ] .SH DESCRIPTION .B intel_gpu_top is a tool to display usage information of an Intel GPU. It requires root privilege to map the graphics device. +.SS Options +.TP +.B -s [samples per second] +number of samples to acquire per second +.TP +.B -h +show usage notes .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 64ce828..abe9d4b 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -392,6 +392,23 @@ static void ring_print(struct ring *ring, unsigned long samples_per_sec) (int)((ring->full / samples_to_percent_ratio) / ring->size)); } +static void +usage(const char *appname) +{ + printf("intel_gpu_top - Display a top-like summary of Intel GPU usage\n" + "\n" + "usage: %s [parameters]\n" + "\n" + "The following parameters apply:\n" + "[-s ] samples per seconds (default %d)\n" + "[-h] show this help screen\n" + "\n", + appname, + SAMPLES_PER_SEC + ); + return; +} + int main(int argc, char **argv) { struct pci_device *pci_dev; @@ -408,7 +425,34 @@ int main(int argc, char **argv) .name = "blitter", .mmio = 0x22030, }; - int i; + int i, ch; + int samples_per_sec = SAMPLES_PER_SEC; + + /* Parse options? */ + while ((ch = getopt(argc, argv, "s:h")) != -1) + { + switch (ch) + { + case 's': samples_per_sec = atoi(optarg); + if (samples_per_sec < 100) { + fprintf(stderr, "Error: samples per second must be >= 100\n"); + exit(1); + } + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + fprintf(stderr, "Invalid flag %c!\n", (char)optopt); + usage(argv[0]); + exit(1); + break; + } + + } + argc -= optind; + argv += optind; pci_dev = intel_get_pci_device(); devid = pci_dev->device_id; @@ -432,8 +476,8 @@ int main(int argc, char **argv) for (;;) { int j; unsigned long long t1, ti, tf; - unsigned long long def_sleep = 1000000 / SAMPLES_PER_SEC; - unsigned long long last_samples_per_sec = SAMPLES_PER_SEC; + unsigned long long def_sleep = 1000000 / samples_per_sec; + unsigned long long last_samples_per_sec = samples_per_sec; char clear_screen[] = {0x1b, '[', 'H', 0x1b, '[', 'J', 0x0}; @@ -447,7 +491,7 @@ int main(int argc, char **argv) ring_reset(&bsd6_ring); ring_reset(&blt_ring); - for (i = 0; i < SAMPLES_PER_SEC; i++) { + for (i = 0; i < samples_per_sec; i++) { long long interval; ti = gettime(); if (IS_965(devid)) {