intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Eugeni Dodonov <eugeni@dodonov.net>
To: intel-gfx@lists.freedesktop.org
Cc: Eugeni Dodonov <eugeni.dodonov@intel.com>
Subject: [PATCH 2/6] intel_gpu_top: suport command line parameters and variable samples per second
Date: Mon,  5 Sep 2011 17:19:29 -0300	[thread overview]
Message-ID: <1315253973-18950-3-git-send-email-eugeni@dodonov.net> (raw)
In-Reply-To: <1315253973-18950-1-git-send-email-eugeni@dodonov.net>

From: Eugeni Dodonov <eugeni.dodonov@intel.com>

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 <eugeni.dodonov@intel.com>
---
 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>]       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)) {
-- 
1.7.6.1

  parent reply	other threads:[~2011-09-05 20:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-05 20:19 [PATCH 0/6] additional intel_gpu_top profiling features Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 1/6] intel_gpu_top: account for time spent in syscalls Eugeni Dodonov
2011-09-05 20:19 ` Eugeni Dodonov [this message]
2011-09-05 21:44   ` [PATCH 2/6] intel_gpu_top: suport command line parameters and variable samples per second Chris Wilson
2011-09-05 22:16     ` Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 3/6] intel_gpu_tool: initial support for non-screen output Eugeni Dodonov
2011-09-05 22:56   ` Łukasz Kuryło
2011-09-05 23:48     ` Łukasz Kuryło
2011-09-06  0:05     ` Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 4/6] intel_gpu_top: initialize monitoring statistics at startup Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 5/6] intel_gpu_top: support non-interactive mode Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 6/6] intel_gpu_top: support profiling user-specified commands Eugeni Dodonov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1315253973-18950-3-git-send-email-eugeni@dodonov.net \
    --to=eugeni@dodonov.net \
    --cc=eugeni.dodonov@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).