diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2024-05-01 12:33:00 -0500 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2024-05-08 05:31:56 -0700 |
commit | e8861cad28fdd4c9fe6ef712cb9ad16eb2fcaff5 (patch) | |
tree | b60939f2666ee98eb2f021f52d95ee9f1c9566b0 /tools/gputop.c | |
parent | 5d7b61b7ceefedfde2683ff72cd98179c99ab746 (diff) |
gputop: print percentage number
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
Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Link: https://lore.kernel.org/r/20240501173303.115737-2-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Diffstat (limited to 'tools/gputop.c')
-rw-r--r-- | tools/gputop.c | 10 |
1 files 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) |