diff options
author | Eric Anholt <eric@anholt.net> | 2009-06-09 11:30:25 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2009-06-09 11:31:52 -0700 |
commit | 49c564ec2fa47f62d097c7dee42730ae43445f8b (patch) | |
tree | 324b34c7d025533306a0c3462cb8aa2a1bdd9f61 /tools/intel_gpu_top.c | |
parent | 8c7be935443934297763af03f0b4b7fcd4999dde (diff) |
Make the precentage bars fit in 80 columns.
Signed-off-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'tools/intel_gpu_top.c')
-rw-r--r-- | tools/intel_gpu_top.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 5374e223..1a02732a 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -190,24 +190,26 @@ print_clock_info(void) return -1; } +#define PERCENTAGE_BAR_END 79 static void -print_percentage_bar(float percent) +print_percentage_bar(float percent, int cur_line_len) { - int bar_len = 3.6 * percent; - int bar_char_len = bar_len / 8; + int bar_avail_len = (PERCENTAGE_BAR_END - cur_line_len - 1) * 8; + int bar_len = bar_avail_len * (percent + .5) / 100.0; int i; - if (bar_len % 8) - bar_char_len++; - - for (i = bar_len; i >= 8; i -= 8) + for (i = bar_len; i >= 8; i -= 8) { printf("%s", bars[8]); - if (i) + cur_line_len++; + } + if (i) { printf("%s", bars[i]); + cur_line_len++; + } /* NB: We can't use a field width with utf8 so we manually * guarantee a field with of 45 chars for any bar. */ - printf("%*s\n", (45 - bar_char_len), ""); + printf("%*s\n", PERCENTAGE_BAR_END - cur_line_len, ""); } int main(int argc, char **argv) @@ -282,6 +284,7 @@ int main(int argc, char **argv) int total_ring_full = 0; int ring_idle = 0; int percent; + int len; for (i = 0; i < SAMPLES_PER_SEC; i++) { uint32_t ring_head, ring_tail; @@ -318,8 +321,8 @@ int main(int argc, char **argv) print_clock_info(); percent = ring_idle / SAMPLES_TO_PERCENT_RATIO; - printf("%30s: %3d%%: ", "ring idle", percent); - print_percentage_bar (percent); + len = printf("%30s: %3d%%: ", "ring idle", percent); + print_percentage_bar (percent, len); printf("%30s: %d/%d (%d%%)\n", "ring space", total_ring_full / SAMPLES_PER_SEC, @@ -332,10 +335,10 @@ int main(int argc, char **argv) break; percent = top_bits_sorted[i]->count / SAMPLES_TO_PERCENT_RATIO; - printf("%30s: %3d%%: ", - top_bits_sorted[i]->name, - percent); - print_percentage_bar (percent); + len = printf("%30s: %3d%%: ", + top_bits_sorted[i]->name, + percent); + print_percentage_bar (percent, len); top_bits_sorted[i]->count = 0; } |