* [Intel-gfx] [PATCH i-g-t 1/2] intel_gpu_top: Display large pids nicely in interactive mode
@ 2023-03-16 10:06 Tvrtko Ursulin
2023-03-16 10:06 ` [Intel-gfx] [PATCH i-g-t 2/2] intel_gpu_top: Use full console width for global metrics Tvrtko Ursulin
0 siblings, 1 reply; 2+ messages in thread
From: Tvrtko Ursulin @ 2023-03-16 10:06 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] 2+ messages in thread* [Intel-gfx] [PATCH i-g-t 2/2] intel_gpu_top: Use full console width for global metrics
2023-03-16 10:06 [Intel-gfx] [PATCH i-g-t 1/2] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
@ 2023-03-16 10:06 ` Tvrtko Ursulin
0 siblings, 0 replies; 2+ messages in thread
From: Tvrtko Ursulin @ 2023-03-16 10:06 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] 2+ messages in thread
end of thread, other threads:[~2023-03-16 10:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-16 10:06 [Intel-gfx] [PATCH i-g-t 1/2] intel_gpu_top: Display large pids nicely in interactive mode Tvrtko Ursulin
2023-03-16 10:06 ` [Intel-gfx] [PATCH i-g-t 2/2] intel_gpu_top: Use full console width for global metrics Tvrtko Ursulin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox