All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH i-g-t 2/2] intel_gpu_top: Add option to sort by PID
Date: Wed,  3 Feb 2021 11:44:56 +0000	[thread overview]
Message-ID: <20210203114456.895974-2-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20210203114456.895974-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Useful to mimick top view.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 man/intel_gpu_top.rst |  2 +-
 tools/intel_gpu_top.c | 46 +++++++++++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/man/intel_gpu_top.rst b/man/intel_gpu_top.rst
index 118d8b953a70..b145d85c0440 100644
--- a/man/intel_gpu_top.rst
+++ b/man/intel_gpu_top.rst
@@ -56,7 +56,7 @@ Supported keys:
     'q'    Exit from the tool.
     '1'    Toggle between aggregated engine class and physical engine mode.
     'n'    Toggle display of numeric client busyness overlay.
-    's'    Toggle between sort modes (runtime, total runtime, client id).
+    's'    Toggle between sort modes (runtime, total runtime, pid, client id).
     'i'    Toggle display of clients which used no GPU time.
 
 DEVICE SELECTION
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index b409106f3718..24a87d2f4f3f 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -959,6 +959,24 @@ static int client_id_cmp(const void *_a, const void *_b)
 	return (int)b->id - a->id;
 }
 
+static int client_pid_cmp(const void *_a, const void *_b)
+{
+	const struct client *a = _a;
+	const struct client *b = _b;
+	int pid_a, pid_b;
+
+	pid_a = a->status == ALIVE ? a->pid : INT_MAX;
+	pid_b = b->status == ALIVE ? b->pid : INT_MAX;
+
+	pid_b -= pid_a;
+	if (pid_b > 0)
+		return -1;
+	if (pid_b < 0)
+		return 1;
+
+	return (int)a->id - b->id;
+}
+
 static int (*client_cmp)(const void *, const void *) = client_last_cmp;
 
 static void sort_clients(struct clients *clients)
@@ -2149,21 +2167,23 @@ static void interactive_stdin(void)
 
 static void select_client_sort(void)
 {
+	struct {
+		int (*cmp)(const void *, const void *);
+		const char *msg;
+	} cmp[] = {
+		{ client_last_cmp, "Sorting clients by current GPU usage." },
+		{ client_total_cmp, "Sorting clients by accummulated GPU usage." },
+		{ client_pid_cmp, "Sorting clients by pid." },
+		{ client_id_cmp, "Sorting clients by sysfs id." },
+	};
 	static unsigned int client_sort;
 
-	switch (++client_sort % 3) {
-	case 0:
-		client_cmp = client_last_cmp;
-		header_msg = "Sorting clients by current GPU usage.";
-		break;
-	case 1:
-		client_cmp = client_total_cmp;
-		header_msg = "Sorting clients by accummulated GPU usage.";
-		break;
-	case 2:
-		client_cmp = client_id_cmp;
-		header_msg = "Sorting clients by sysfs id.";
-	}
+	++client_sort;
+	if (client_sort >= ARRAY_SIZE(cmp))
+		client_sort = 0;
+
+	client_cmp = cmp[client_sort].cmp;
+	header_msg = cmp[client_sort].msg;
 }
 
 static void process_stdin(unsigned int timeout_us)
-- 
2.27.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org,
	Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [PATCH i-g-t 2/2] intel_gpu_top: Add option to sort by PID
Date: Wed,  3 Feb 2021 11:44:56 +0000	[thread overview]
Message-ID: <20210203114456.895974-2-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20210203114456.895974-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Useful to mimick top view.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 man/intel_gpu_top.rst |  2 +-
 tools/intel_gpu_top.c | 46 +++++++++++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/man/intel_gpu_top.rst b/man/intel_gpu_top.rst
index 118d8b953a70..b145d85c0440 100644
--- a/man/intel_gpu_top.rst
+++ b/man/intel_gpu_top.rst
@@ -56,7 +56,7 @@ Supported keys:
     'q'    Exit from the tool.
     '1'    Toggle between aggregated engine class and physical engine mode.
     'n'    Toggle display of numeric client busyness overlay.
-    's'    Toggle between sort modes (runtime, total runtime, client id).
+    's'    Toggle between sort modes (runtime, total runtime, pid, client id).
     'i'    Toggle display of clients which used no GPU time.
 
 DEVICE SELECTION
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index b409106f3718..24a87d2f4f3f 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -959,6 +959,24 @@ static int client_id_cmp(const void *_a, const void *_b)
 	return (int)b->id - a->id;
 }
 
+static int client_pid_cmp(const void *_a, const void *_b)
+{
+	const struct client *a = _a;
+	const struct client *b = _b;
+	int pid_a, pid_b;
+
+	pid_a = a->status == ALIVE ? a->pid : INT_MAX;
+	pid_b = b->status == ALIVE ? b->pid : INT_MAX;
+
+	pid_b -= pid_a;
+	if (pid_b > 0)
+		return -1;
+	if (pid_b < 0)
+		return 1;
+
+	return (int)a->id - b->id;
+}
+
 static int (*client_cmp)(const void *, const void *) = client_last_cmp;
 
 static void sort_clients(struct clients *clients)
@@ -2149,21 +2167,23 @@ static void interactive_stdin(void)
 
 static void select_client_sort(void)
 {
+	struct {
+		int (*cmp)(const void *, const void *);
+		const char *msg;
+	} cmp[] = {
+		{ client_last_cmp, "Sorting clients by current GPU usage." },
+		{ client_total_cmp, "Sorting clients by accummulated GPU usage." },
+		{ client_pid_cmp, "Sorting clients by pid." },
+		{ client_id_cmp, "Sorting clients by sysfs id." },
+	};
 	static unsigned int client_sort;
 
-	switch (++client_sort % 3) {
-	case 0:
-		client_cmp = client_last_cmp;
-		header_msg = "Sorting clients by current GPU usage.";
-		break;
-	case 1:
-		client_cmp = client_total_cmp;
-		header_msg = "Sorting clients by accummulated GPU usage.";
-		break;
-	case 2:
-		client_cmp = client_id_cmp;
-		header_msg = "Sorting clients by sysfs id.";
-	}
+	++client_sort;
+	if (client_sort >= ARRAY_SIZE(cmp))
+		client_sort = 0;
+
+	client_cmp = cmp[client_sort].cmp;
+	header_msg = cmp[client_sort].msg;
 }
 
 static void process_stdin(unsigned int timeout_us)
-- 
2.27.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2021-02-03 11:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 11:44 [Intel-gfx] [PATCH i-g-t 1/2] intel_gpu_top: Show banner messages when cycling sort modes Tvrtko Ursulin
2021-02-03 11:44 ` [igt-dev] " Tvrtko Ursulin
2021-02-03 11:44 ` Tvrtko Ursulin [this message]
2021-02-03 11:44   ` [igt-dev] [PATCH i-g-t 2/2] intel_gpu_top: Add option to sort by PID Tvrtko Ursulin
2021-02-03 11:50   ` [Intel-gfx] " Chris Wilson
2021-02-03 11:50     ` [igt-dev] " Chris Wilson
2021-02-03 11:47 ` [Intel-gfx] [igt-dev] [PATCH i-g-t 1/2] intel_gpu_top: Show banner messages when cycling sort modes Chris Wilson
2021-02-03 11:47   ` Chris Wilson
2021-02-03 11:49   ` [Intel-gfx] " Tvrtko Ursulin
2021-02-03 11:49     ` Tvrtko Ursulin
2021-02-03 15:01 ` [igt-dev] ✗ Fi.CI.BUILD: failure for series starting with [i-g-t,1/2] " Patchwork

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=20210203114456.895974-2-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=igt-dev@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.