[PATCH i-g-t v2 17/21] gputop: print percentage number
Lucas De Marchi
lucas.demarchi at intel.com
Tue Apr 23 23:44:27 UTC 2024
Besides printing the bar, also print the raw number for easy
visualization of small quantities. While at it, make sure gputop still
works with small console widths.
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
tools/gputop.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/gputop.c b/tools/gputop.c
index 9edb76acc..820a1b553 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -42,17 +42,19 @@ static void n_spaces(const unsigned int n)
static void print_percentage_bar(double percent, int max_len)
{
- int bar_len, i, len = max_len - 2;
+ int bar_len, i, len = max_len - 1;
const int w = 8;
- assert(max_len > 0);
+ len -= printf("|%.1f%% ", percent);
+
+ /* no space left for bars, do what we can */
+ if (len < 0)
+ len = 0;
bar_len = ceil(w * percent * len / 100.0);
if (bar_len > w * len)
bar_len = w * len;
- putchar('|');
-
for (i = bar_len; i >= w; i -= w)
printf("%s", bars[w]);
if (i)
--
2.43.0
More information about the igt-dev
mailing list