public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH i-g-t 0/3] Assorted intel_gpu_top tweaks
@ 2023-03-28 12:54 Tvrtko Ursulin
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tvrtko Ursulin @ 2023-03-28 12:54 UTC (permalink / raw)
  To: igt-dev, Intel-gfx

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

Just some display formatting and display tweaks and fixes.

Tvrtko Ursulin (3):
  intel_gpu_top: Display large pids nicely in interactive mode
  intel_gpu_top: Use full console width for global metrics
  intel_gpu_top: Show non-normalized client usage in numeric mode

 tools/intel_gpu_top.c | 90 +++++++++++++++++++++++++++++++++----------
 1 file changed, 70 insertions(+), 20 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode
  2023-03-28 12:54 [Intel-gfx] [PATCH i-g-t 0/3] Assorted intel_gpu_top tweaks Tvrtko Ursulin
@ 2023-03-28 12:54 ` Tvrtko Ursulin
  2023-04-14 15:24   ` Kamil Konieczny
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Use full console width for global metrics Tvrtko Ursulin
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode Tvrtko Ursulin
  2 siblings, 1 reply; 8+ messages in thread
From: Tvrtko Ursulin @ 2023-03-28 12:54 UTC (permalink / raw)
  To: igt-dev, Intel-gfx

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

So far the width of the PID column was hardcoded to six characters which
is not enough on systems with high uptime, where PID numbers can grow
large, and results in broken line formatting.

Fix it by tracking the largest width for both the pid and name fields and
use them dynamically.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tools/intel_gpu_top.c | 66 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 58 insertions(+), 8 deletions(-)

diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index a4302aa389b4..39be916297e4 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2007-2021 Intel Corporation
+ * Copyright © 2007-2023 Intel Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -693,6 +693,7 @@ struct client {
 	enum client_status status;
 	unsigned int id;
 	unsigned int pid;
+	char pid_str[10];
 	char name[24];
 	char print_name[24];
 	unsigned int samples;
@@ -709,6 +710,9 @@ struct clients {
 	unsigned int num_classes;
 	struct engine_class *class;
 
+	int max_pid_len;
+	int max_name_len;
+
 	char pci_slot[64];
 
 	struct client *client;
@@ -758,9 +762,14 @@ update_client(struct client *c, unsigned int pid, char *name,
 	      const struct drm_client_fdinfo *info)
 {
 	unsigned int i;
+	int len;
 
-	if (c->pid != pid)
+	if (c->pid != pid) {
 		c->pid = pid;
+		len = snprintf(c->pid_str, sizeof(c->pid_str) - 1, "%u", pid);
+		if (len > c->clients->max_pid_len)
+			c->clients->max_pid_len = len;
+	}
 
 	if (strcmp(c->name, name)) {
 		char *p;
@@ -774,6 +783,10 @@ update_client(struct client *c, unsigned int pid, char *name,
 				*p = '*';
 			p++;
 		}
+
+		len = strlen(c->print_name);
+		if (len > c->clients->max_name_len)
+			c->clients->max_name_len = len;
 	}
 
 	c->last_runtime = 0;
@@ -990,6 +1003,7 @@ static struct clients *display_clients(struct clients *clients)
 			ac->id = -c->pid;
 			ac->pid = c->pid;
 			strcpy(ac->name, c->name);
+			strcpy(ac->pid_str, c->pid_str);
 			strcpy(ac->print_name, c->print_name);
 			ac->val = calloc(clients->num_classes,
 					 sizeof(ac->val[0]));
@@ -1013,6 +1027,9 @@ static struct clients *display_clients(struct clients *clients)
 	aggregated->num_clients = num;
 	aggregated->active_clients = num;
 
+	aggregated->max_pid_len = clients->max_pid_len;
+	aggregated->max_name_len = clients->max_name_len;
+
 	clients = aggregated;
 
 out:
@@ -1104,9 +1121,34 @@ static size_t readat2buf(int at, const char *name, char *buf, const size_t sz)
 	}
 }
 
+static void clients_update_max_lengths(struct clients *clients)
+{
+	struct client *c;
+	int tmp;
+
+	clients->max_name_len = 0;
+	clients->max_pid_len = 0;
+
+	for_each_client(clients, c, tmp) {
+		int len;
+
+		if (c->status != ALIVE)
+			continue; /* Array not yet sorted by the caller. */
+
+		len = strlen(c->print_name);
+		if (len > clients->max_name_len)
+			clients->max_name_len = len;
+
+		len = strlen(c->pid_str);
+		if (len > clients->max_pid_len)
+			clients->max_pid_len = len;
+	}
+}
+
 static struct clients *scan_clients(struct clients *clients, bool display)
 {
 	struct dirent *proc_dent;
+	bool freed = false;
 	struct client *c;
 	DIR *proc_dir;
 	int tmp;
@@ -1208,12 +1250,17 @@ next:
 	closedir(proc_dir);
 
 	for_each_client(clients, c, tmp) {
-		if (c->status == PROBE)
+		if (c->status == PROBE) {
 			free_client(c);
-		else if (c->status == FREE)
+			freed = true;
+		} else if (c->status == FREE) {
 			break;
+		}
 	}
 
+	if (freed)
+		clients_update_max_lengths(clients);
+
 	return display ? display_clients(clients) : clients;
 }
 
@@ -2172,15 +2219,16 @@ print_clients_header(struct clients *clients, int lines,
 		     int con_w, int con_h, int *class_w)
 {
 	if (output_mode == INTERACTIVE) {
-		const char *pidname = "   PID              NAME ";
 		unsigned int num_active = 0;
-		int len = strlen(pidname);
+		int len;
 
 		if (lines++ >= con_h)
 			return lines;
 
 		printf("\033[7m");
-		printf("%s", pidname);
+		len = printf("%*s %*s ",
+			     clients->max_pid_len, "PID",
+			     clients->max_name_len, "NAME");
 
 		if (lines++ >= con_h || len >= con_w)
 			return lines;
@@ -2241,7 +2289,9 @@ print_client(struct client *c, struct engines *engines, double t, int lines,
 
 		lines++;
 
-		printf("%6u %17s ", c->pid, c->print_name);
+		printf("%*s %*s ",
+		       clients->max_pid_len, c->pid_str,
+		       clients->max_name_len, c->print_name);
 
 		for (i = 0; c->samples > 1 && i < clients->num_classes; i++) {
 			double pct;
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Use full console width for global metrics
  2023-03-28 12:54 [Intel-gfx] [PATCH i-g-t 0/3] Assorted intel_gpu_top tweaks Tvrtko Ursulin
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
@ 2023-03-28 12:54 ` Tvrtko Ursulin
  2023-04-14 15:26   ` [Intel-gfx] [igt-dev] " Kamil Konieczny
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode Tvrtko Ursulin
  2 siblings, 1 reply; 8+ messages in thread
From: Tvrtko Ursulin @ 2023-03-28 12:54 UTC (permalink / raw)
  To: igt-dev, Intel-gfx

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

It appears we had an off by one of a kind where we were not using the full
width of the terminal window for the global metrics section.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tools/intel_gpu_top.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 39be916297e4..36da016c3df0 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -1960,8 +1960,7 @@ print_engines_header(struct engines *engines, double t,
 				a = "          ENGINE     BUSY  ";
 
 			printf("\033[7m%s%*s%s\033[0m\n",
-			       a, (int)(con_w - 1 - strlen(a) - strlen(b)),
-			       " ", b);
+			       a, (int)(con_w - strlen(a) - strlen(b)), " ", b);
 
 			lines++;
 		}
@@ -2000,7 +1999,6 @@ print_engine(struct engines *engines, unsigned int i, double t,
 	print_groups(groups);
 
 	if (output_mode == INTERACTIVE) {
-		unsigned int max_w = con_w - 1;
 		unsigned int len;
 		char buf[128];
 		double val;
@@ -2012,7 +2010,7 @@ print_engine(struct engines *engines, unsigned int i, double t,
 			      engine->display_name, engine_items[0].buf);
 
 		val = pmu_calc(&engine->busy.val, 1e9, t, 100);
-		print_percentage_bar(val, max_w > len ? max_w - len : 0, false);
+		print_percentage_bar(val, con_w > len ? con_w - len : 0, false);
 
 		printf("%s\n", buf);
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode
  2023-03-28 12:54 [Intel-gfx] [PATCH i-g-t 0/3] Assorted intel_gpu_top tweaks Tvrtko Ursulin
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Use full console width for global metrics Tvrtko Ursulin
@ 2023-03-28 12:54 ` Tvrtko Ursulin
  2023-04-14 15:28   ` Kamil Konieczny
  2 siblings, 1 reply; 8+ messages in thread
From: Tvrtko Ursulin @ 2023-03-28 12:54 UTC (permalink / raw)
  To: igt-dev, Intel-gfx

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

When numeric display is selected in the interactive mode it is more
descriptive to show client's non-normalized (by number of engines per
class) usage. Rendering of the visual representation (bar) is kept the
same.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tools/intel_gpu_top.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 36da016c3df0..b6827b3de9bd 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -1275,14 +1275,14 @@ static void n_spaces(const unsigned int n)
 }
 
 static void
-print_percentage_bar(double percent, int max_len, bool numeric)
+print_percentage_bar(double percent, double max, int max_len, bool numeric)
 {
 	int bar_len, i, len = max_len - 2;
 	const int w = 8;
 
 	assert(max_len > 0);
 
-	bar_len = ceil(w * percent * len / 100.0);
+	bar_len = ceil(w * percent * len / max);
 	if (bar_len > w * len)
 		bar_len = w * len;
 
@@ -2010,7 +2010,8 @@ print_engine(struct engines *engines, unsigned int i, double t,
 			      engine->display_name, engine_items[0].buf);
 
 		val = pmu_calc(&engine->busy.val, 1e9, t, 100);
-		print_percentage_bar(val, con_w > len ? con_w - len : 0, false);
+		print_percentage_bar(val, 100.0, con_w > len ? con_w - len : 0,
+				     false);
 
 		printf("%s\n", buf);
 
@@ -2292,23 +2293,24 @@ print_client(struct client *c, struct engines *engines, double t, int lines,
 		       clients->max_name_len, c->print_name);
 
 		for (i = 0; c->samples > 1 && i < clients->num_classes; i++) {
-			double pct;
+			double pct, max;
 
 			if (!clients->class[i].num_engines)
 				continue; /* Assert in the ideal world. */
 
-			pct = (double)c->val[i] / period_us / 1e3 * 100 /
-			      clients->class[i].num_engines;
+			pct = (double)c->val[i] / period_us / 1e3 * 100;
 
 			/*
 			 * Guard against possible time-drift between sampling
 			 * client data and time we obtained our time-delta from
 			 * PMU.
 			 */
-			if (pct > 100.0)
-				pct = 100.0;
+			max = 100.0 * clients->class[i].num_engines;
+			if (pct > max)
+				pct = max;
 
-			print_percentage_bar(pct, *class_w, numeric_clients);
+			print_percentage_bar(pct, max, *class_w,
+					     numeric_clients);
 		}
 
 		putchar('\n');
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
@ 2023-04-14 15:24   ` Kamil Konieczny
  0 siblings, 0 replies; 8+ messages in thread
From: Kamil Konieczny @ 2023-04-14 15:24 UTC (permalink / raw)
  To: igt-dev; +Cc: Intel-gfx

Hi,

On 2023-03-28 at 13:54:27 +0100, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> So far the width of the PID column was hardcoded to six characters which
> is not enough on systems with high uptime, where PID numbers can grow
> large, and results in broken line formatting.
> 
> Fix it by tracking the largest width for both the pid and name fields and
> use them dynamically.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

> ---
>  tools/intel_gpu_top.c | 66 +++++++++++++++++++++++++++++++++++++------
>  1 file changed, 58 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index a4302aa389b4..39be916297e4 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright © 2007-2021 Intel Corporation
> + * Copyright © 2007-2023 Intel Corporation
>   *
>   * Permission is hereby granted, free of charge, to any person obtaining a
>   * copy of this software and associated documentation files (the "Software"),
> @@ -693,6 +693,7 @@ struct client {
>  	enum client_status status;
>  	unsigned int id;
>  	unsigned int pid;
> +	char pid_str[10];
>  	char name[24];
>  	char print_name[24];
>  	unsigned int samples;
> @@ -709,6 +710,9 @@ struct clients {
>  	unsigned int num_classes;
>  	struct engine_class *class;
>  
> +	int max_pid_len;
> +	int max_name_len;
> +
>  	char pci_slot[64];
>  
>  	struct client *client;
> @@ -758,9 +762,14 @@ update_client(struct client *c, unsigned int pid, char *name,
>  	      const struct drm_client_fdinfo *info)
>  {
>  	unsigned int i;
> +	int len;
>  
> -	if (c->pid != pid)
> +	if (c->pid != pid) {
>  		c->pid = pid;
> +		len = snprintf(c->pid_str, sizeof(c->pid_str) - 1, "%u", pid);
> +		if (len > c->clients->max_pid_len)
> +			c->clients->max_pid_len = len;
> +	}
>  
>  	if (strcmp(c->name, name)) {
>  		char *p;
> @@ -774,6 +783,10 @@ update_client(struct client *c, unsigned int pid, char *name,
>  				*p = '*';
>  			p++;
>  		}
> +
> +		len = strlen(c->print_name);
> +		if (len > c->clients->max_name_len)
> +			c->clients->max_name_len = len;
>  	}
>  
>  	c->last_runtime = 0;
> @@ -990,6 +1003,7 @@ static struct clients *display_clients(struct clients *clients)
>  			ac->id = -c->pid;
>  			ac->pid = c->pid;
>  			strcpy(ac->name, c->name);
> +			strcpy(ac->pid_str, c->pid_str);
>  			strcpy(ac->print_name, c->print_name);
>  			ac->val = calloc(clients->num_classes,
>  					 sizeof(ac->val[0]));
> @@ -1013,6 +1027,9 @@ static struct clients *display_clients(struct clients *clients)
>  	aggregated->num_clients = num;
>  	aggregated->active_clients = num;
>  
> +	aggregated->max_pid_len = clients->max_pid_len;
> +	aggregated->max_name_len = clients->max_name_len;
> +
>  	clients = aggregated;
>  
>  out:
> @@ -1104,9 +1121,34 @@ static size_t readat2buf(int at, const char *name, char *buf, const size_t sz)
>  	}
>  }
>  
> +static void clients_update_max_lengths(struct clients *clients)
> +{
> +	struct client *c;
> +	int tmp;
> +
> +	clients->max_name_len = 0;
> +	clients->max_pid_len = 0;
> +
> +	for_each_client(clients, c, tmp) {
> +		int len;
> +
> +		if (c->status != ALIVE)
> +			continue; /* Array not yet sorted by the caller. */
> +
> +		len = strlen(c->print_name);
> +		if (len > clients->max_name_len)
> +			clients->max_name_len = len;
> +
> +		len = strlen(c->pid_str);
> +		if (len > clients->max_pid_len)
> +			clients->max_pid_len = len;
> +	}
> +}
> +
>  static struct clients *scan_clients(struct clients *clients, bool display)
>  {
>  	struct dirent *proc_dent;
> +	bool freed = false;
>  	struct client *c;
>  	DIR *proc_dir;
>  	int tmp;
> @@ -1208,12 +1250,17 @@ next:
>  	closedir(proc_dir);
>  
>  	for_each_client(clients, c, tmp) {
> -		if (c->status == PROBE)
> +		if (c->status == PROBE) {
>  			free_client(c);
> -		else if (c->status == FREE)
> +			freed = true;
> +		} else if (c->status == FREE) {
>  			break;
> +		}
>  	}
>  
> +	if (freed)
> +		clients_update_max_lengths(clients);
> +
>  	return display ? display_clients(clients) : clients;
>  }
>  
> @@ -2172,15 +2219,16 @@ print_clients_header(struct clients *clients, int lines,
>  		     int con_w, int con_h, int *class_w)
>  {
>  	if (output_mode == INTERACTIVE) {
> -		const char *pidname = "   PID              NAME ";
>  		unsigned int num_active = 0;
> -		int len = strlen(pidname);
> +		int len;
>  
>  		if (lines++ >= con_h)
>  			return lines;
>  
>  		printf("\033[7m");
> -		printf("%s", pidname);
> +		len = printf("%*s %*s ",
> +			     clients->max_pid_len, "PID",
> +			     clients->max_name_len, "NAME");
>  
>  		if (lines++ >= con_h || len >= con_w)
>  			return lines;
> @@ -2241,7 +2289,9 @@ print_client(struct client *c, struct engines *engines, double t, int lines,
>  
>  		lines++;
>  
> -		printf("%6u %17s ", c->pid, c->print_name);
> +		printf("%*s %*s ",
> +		       clients->max_pid_len, c->pid_str,
> +		       clients->max_name_len, c->print_name);
>  
>  		for (i = 0; c->samples > 1 && i < clients->num_classes; i++) {
>  			double pct;
> -- 
> 2.37.2
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 2/3] intel_gpu_top: Use full console width for global metrics
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Use full console width for global metrics Tvrtko Ursulin
@ 2023-04-14 15:26   ` Kamil Konieczny
  0 siblings, 0 replies; 8+ messages in thread
From: Kamil Konieczny @ 2023-04-14 15:26 UTC (permalink / raw)
  To: igt-dev; +Cc: Intel-gfx

On 2023-03-28 at 13:54:28 +0100, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> It appears we had an off by one of a kind where we were not using the full
> width of the terminal window for the global metrics section.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

> ---
>  tools/intel_gpu_top.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index 39be916297e4..36da016c3df0 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -1960,8 +1960,7 @@ print_engines_header(struct engines *engines, double t,
>  				a = "          ENGINE     BUSY  ";
>  
>  			printf("\033[7m%s%*s%s\033[0m\n",
> -			       a, (int)(con_w - 1 - strlen(a) - strlen(b)),
> -			       " ", b);
> +			       a, (int)(con_w - strlen(a) - strlen(b)), " ", b);
>  
>  			lines++;
>  		}
> @@ -2000,7 +1999,6 @@ print_engine(struct engines *engines, unsigned int i, double t,
>  	print_groups(groups);
>  
>  	if (output_mode == INTERACTIVE) {
> -		unsigned int max_w = con_w - 1;
>  		unsigned int len;
>  		char buf[128];
>  		double val;
> @@ -2012,7 +2010,7 @@ print_engine(struct engines *engines, unsigned int i, double t,
>  			      engine->display_name, engine_items[0].buf);
>  
>  		val = pmu_calc(&engine->busy.val, 1e9, t, 100);
> -		print_percentage_bar(val, max_w > len ? max_w - len : 0, false);
> +		print_percentage_bar(val, con_w > len ? con_w - len : 0, false);
>  
>  		printf("%s\n", buf);
>  
> -- 
> 2.37.2
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode
  2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode Tvrtko Ursulin
@ 2023-04-14 15:28   ` Kamil Konieczny
  2023-04-17 10:58     ` Tvrtko Ursulin
  0 siblings, 1 reply; 8+ messages in thread
From: Kamil Konieczny @ 2023-04-14 15:28 UTC (permalink / raw)
  To: igt-dev; +Cc: Intel-gfx

On 2023-03-28 at 13:54:29 +0100, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> When numeric display is selected in the interactive mode it is more
> descriptive to show client's non-normalized (by number of engines per
> class) usage. Rendering of the visual representation (bar) is kept the
> same.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

> ---
>  tools/intel_gpu_top.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index 36da016c3df0..b6827b3de9bd 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -1275,14 +1275,14 @@ static void n_spaces(const unsigned int n)
>  }
>  
>  static void
> -print_percentage_bar(double percent, int max_len, bool numeric)
> +print_percentage_bar(double percent, double max, int max_len, bool numeric)
>  {
>  	int bar_len, i, len = max_len - 2;
>  	const int w = 8;
>  
>  	assert(max_len > 0);
>  
> -	bar_len = ceil(w * percent * len / 100.0);
> +	bar_len = ceil(w * percent * len / max);
>  	if (bar_len > w * len)
>  		bar_len = w * len;
>  
> @@ -2010,7 +2010,8 @@ print_engine(struct engines *engines, unsigned int i, double t,
>  			      engine->display_name, engine_items[0].buf);
>  
>  		val = pmu_calc(&engine->busy.val, 1e9, t, 100);
> -		print_percentage_bar(val, con_w > len ? con_w - len : 0, false);
> +		print_percentage_bar(val, 100.0, con_w > len ? con_w - len : 0,
> +				     false);
>  
>  		printf("%s\n", buf);
>  
> @@ -2292,23 +2293,24 @@ print_client(struct client *c, struct engines *engines, double t, int lines,
>  		       clients->max_name_len, c->print_name);
>  
>  		for (i = 0; c->samples > 1 && i < clients->num_classes; i++) {
> -			double pct;
> +			double pct, max;
>  
>  			if (!clients->class[i].num_engines)
>  				continue; /* Assert in the ideal world. */
>  
> -			pct = (double)c->val[i] / period_us / 1e3 * 100 /
> -			      clients->class[i].num_engines;
> +			pct = (double)c->val[i] / period_us / 1e3 * 100;
>  
>  			/*
>  			 * Guard against possible time-drift between sampling
>  			 * client data and time we obtained our time-delta from
>  			 * PMU.
>  			 */
> -			if (pct > 100.0)
> -				pct = 100.0;
> +			max = 100.0 * clients->class[i].num_engines;
> +			if (pct > max)
> +				pct = max;
>  
> -			print_percentage_bar(pct, *class_w, numeric_clients);
> +			print_percentage_bar(pct, max, *class_w,
> +					     numeric_clients);
>  		}
>  
>  		putchar('\n');
> -- 
> 2.37.2
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode
  2023-04-14 15:28   ` Kamil Konieczny
@ 2023-04-17 10:58     ` Tvrtko Ursulin
  0 siblings, 0 replies; 8+ messages in thread
From: Tvrtko Ursulin @ 2023-04-17 10:58 UTC (permalink / raw)
  To: Kamil Konieczny, igt-dev, Intel-gfx


Hi Kamil,

On 14/04/2023 16:28, Kamil Konieczny wrote:
> On 2023-03-28 at 13:54:29 +0100, Tvrtko Ursulin wrote:
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> When numeric display is selected in the interactive mode it is more
>> descriptive to show client's non-normalized (by number of engines per
>> class) usage. Rendering of the visual representation (bar) is kept the
>> same.
>>
>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

Thanks for reviewing all three and merging them too!

Regards,

Tvrtko

>> ---
>>   tools/intel_gpu_top.c | 20 +++++++++++---------
>>   1 file changed, 11 insertions(+), 9 deletions(-)
>>
>> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
>> index 36da016c3df0..b6827b3de9bd 100644
>> --- a/tools/intel_gpu_top.c
>> +++ b/tools/intel_gpu_top.c
>> @@ -1275,14 +1275,14 @@ static void n_spaces(const unsigned int n)
>>   }
>>   
>>   static void
>> -print_percentage_bar(double percent, int max_len, bool numeric)
>> +print_percentage_bar(double percent, double max, int max_len, bool numeric)
>>   {
>>   	int bar_len, i, len = max_len - 2;
>>   	const int w = 8;
>>   
>>   	assert(max_len > 0);
>>   
>> -	bar_len = ceil(w * percent * len / 100.0);
>> +	bar_len = ceil(w * percent * len / max);
>>   	if (bar_len > w * len)
>>   		bar_len = w * len;
>>   
>> @@ -2010,7 +2010,8 @@ print_engine(struct engines *engines, unsigned int i, double t,
>>   			      engine->display_name, engine_items[0].buf);
>>   
>>   		val = pmu_calc(&engine->busy.val, 1e9, t, 100);
>> -		print_percentage_bar(val, con_w > len ? con_w - len : 0, false);
>> +		print_percentage_bar(val, 100.0, con_w > len ? con_w - len : 0,
>> +				     false);
>>   
>>   		printf("%s\n", buf);
>>   
>> @@ -2292,23 +2293,24 @@ print_client(struct client *c, struct engines *engines, double t, int lines,
>>   		       clients->max_name_len, c->print_name);
>>   
>>   		for (i = 0; c->samples > 1 && i < clients->num_classes; i++) {
>> -			double pct;
>> +			double pct, max;
>>   
>>   			if (!clients->class[i].num_engines)
>>   				continue; /* Assert in the ideal world. */
>>   
>> -			pct = (double)c->val[i] / period_us / 1e3 * 100 /
>> -			      clients->class[i].num_engines;
>> +			pct = (double)c->val[i] / period_us / 1e3 * 100;
>>   
>>   			/*
>>   			 * Guard against possible time-drift between sampling
>>   			 * client data and time we obtained our time-delta from
>>   			 * PMU.
>>   			 */
>> -			if (pct > 100.0)
>> -				pct = 100.0;
>> +			max = 100.0 * clients->class[i].num_engines;
>> +			if (pct > max)
>> +				pct = max;
>>   
>> -			print_percentage_bar(pct, *class_w, numeric_clients);
>> +			print_percentage_bar(pct, max, *class_w,
>> +					     numeric_clients);
>>   		}
>>   
>>   		putchar('\n');
>> -- 
>> 2.37.2
>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-17 10:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-28 12:54 [Intel-gfx] [PATCH i-g-t 0/3] Assorted intel_gpu_top tweaks Tvrtko Ursulin
2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 1/3] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
2023-04-14 15:24   ` Kamil Konieczny
2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 2/3] intel_gpu_top: Use full console width for global metrics Tvrtko Ursulin
2023-04-14 15:26   ` [Intel-gfx] [igt-dev] " Kamil Konieczny
2023-03-28 12:54 ` [Intel-gfx] [PATCH i-g-t 3/3] intel_gpu_top: Show non-normalized client usage in numeric mode Tvrtko Ursulin
2023-04-14 15:28   ` Kamil Konieczny
2023-04-17 10:58     ` Tvrtko Ursulin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox