threads / patch / 21234

patchchange throughput display units with fast links

Subject: [PATCH] change throughput display units with fast links

## tl;dr

3 messages between Oct 14, 2009 and Oct 14, 2009. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Nicolas Pitre· Oct 14, 2009, 03:02 UTC · lore
Switch to MiB/s when the connection is fast enough (i.e. on a LAN).
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
---
Show changes to progress.c +7 −1
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);
 }
Johannes Sixt· Oct 14, 2009, 07:07 UTC · re: Nicolas Pitre · lore

Re: [PATCH] change throughput display units with fast links

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)?
Show 5 quoted lines
> +			 x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
> +	} else if (rate)
>  		snprintf(tp->display + sizeof(tp->display) - l, l,
>  			 " | %u KiB/s", rate);
>  }
-- Hannes
Junio C Hamano· Oct 14, 2009, 09:13 UTC · re: Johannes Sixt · lore

Re: [PATCH] change throughput display units with fast links

Johannes Sixt <j.sixt@viscovery.net> writes:
Show 15 quoted lines
> 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

← back to recent threads