* [PATCH] change throughput display units with fast links
@ 2009-10-14 3:02 Nicolas Pitre
2009-10-14 7:07 ` Johannes Sixt
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Pitre @ 2009-10-14 3:02 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Switch to MiB/s when the connection is fast enough (i.e. on a LAN).
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
---
diff --git a/progress.c b/progress.c
index 132ed95..3971f49 100644
--- a/progress.c
+++ b/progress.c
@@ -131,7 +131,13 @@ static void throughput_string(struct throughput *tp, off_t total,
} else {
l -= snprintf(tp->display, l, ", %u bytes", (int)total);
}
- if (rate)
+
+ if (rate > 1 << 10) {
+ int x = rate + 5; /* for rounding */
+ snprintf(tp->display + sizeof(tp->display) - l, l,
+ " | %u.%2.2u MiB/s",
+ x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
+ } else if (rate)
snprintf(tp->display + sizeof(tp->display) - l, l,
" | %u KiB/s", rate);
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] change throughput display units with fast links
2009-10-14 3:02 [PATCH] change throughput display units with fast links Nicolas Pitre
@ 2009-10-14 7:07 ` Johannes Sixt
2009-10-14 9:13 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Sixt @ 2009-10-14 7:07 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: Junio C Hamano, git
Nicolas Pitre schrieb:
> + if (rate > 1 << 10) {
> + int x = rate + 5; /* for rounding */
> + snprintf(tp->display + sizeof(tp->display) - l, l,
> + " | %u.%2.2u MiB/s",
Shouldn't the fractional part be "%02.2u" (leading zeros instead of blanks)?
> + x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
> + } else if (rate)
> snprintf(tp->display + sizeof(tp->display) - l, l,
> " | %u KiB/s", rate);
> }
-- Hannes
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] change throughput display units with fast links
2009-10-14 7:07 ` Johannes Sixt
@ 2009-10-14 9:13 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2009-10-14 9:13 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Nicolas Pitre, git
Johannes Sixt <j.sixt@viscovery.net> writes:
> Nicolas Pitre schrieb:
>> + if (rate > 1 << 10) {
>> + int x = rate + 5; /* for rounding */
>> + snprintf(tp->display + sizeof(tp->display) - l, l,
>> + " | %u.%2.2u MiB/s",
>
> Shouldn't the fractional part be "%02.2u" (leading zeros instead of blanks)?
>
>> + x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
>> + } else if (rate)
>> snprintf(tp->display + sizeof(tp->display) - l, l,
>> " | %u KiB/s", rate);
>> }
>
> -- Hannes
Judging from the surrounding existing code, I do not think so.
$ cat <<\EOF >j.c
#include <stdio.h>
int main(int ac, char **av)
{
printf("%u.%2.2u\n", 4, 5);
return 0;
}
EOF
$ gcc -o j j.c && ./j
4.05
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-10-14 9:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-14 3:02 [PATCH] change throughput display units with fast links Nicolas Pitre
2009-10-14 7:07 ` Johannes Sixt
2009-10-14 9:13 ` Junio C Hamano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.