From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>,
Tvrtko Ursulin <tursulin@ursulin.net>,
Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH 1/4] gputop: print percentage number
Date: Wed, 1 May 2024 12:33:00 -0500 [thread overview]
Message-ID: <20240501173303.115737-2-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20240501173303.115737-1-lucas.demarchi@intel.com>
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.
v2: Use %5.1f instead of %.1f so it also aligns the non-decimal part
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
tools/gputop.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/gputop.c b/tools/gputop.c
index 8cec951b4..7fd9e9790 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("|%5.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.45.0
next prev parent reply other threads:[~2024-05-01 17:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-01 17:32 [PATCH 0/4] Minor gputop improvements Lucas De Marchi
2024-05-01 17:33 ` Lucas De Marchi [this message]
2024-05-07 18:22 ` [PATCH 1/4] gputop: print percentage number Kamil Konieczny
2024-05-01 17:33 ` [PATCH 2/4] gputop: Add option parsing Lucas De Marchi
2024-05-07 18:24 ` Kamil Konieczny
2024-05-01 17:33 ` [PATCH 3/4] gputop: Allow to limit number of executions Lucas De Marchi
2024-05-07 18:26 ` Kamil Konieczny
2024-05-01 17:33 ` [PATCH 4/4] gputop: Allow to set delay interval Lucas De Marchi
2024-05-07 18:29 ` Kamil Konieczny
2024-05-01 18:17 ` ✓ CI.xeBAT: success for Minor gputop improvements Patchwork
2024-05-01 18:23 ` ✓ Fi.CI.BAT: " Patchwork
2024-05-01 19:15 ` ✗ CI.xeFULL: failure " Patchwork
2024-05-01 19:42 ` ✗ Fi.CI.IGT: " Patchwork
2024-05-08 15:57 ` [PATCH 0/4] " Lucas De Marchi
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=20240501173303.115737-2-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=tursulin@ursulin.net \
--cc=umesh.nerlige.ramappa@intel.com \
/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