I modified the patch to display bandwidth in bits for --bits option not the
length.
I attached change log and diff file
Thanks
Sasi
On Sun, Jan 15, 2012 at 2:14 AM, Sasikanth <[email protected]> wrote:
> No one asked. i had just thought it will be good to display all the output
> in either bits or bytes to avoid confusion to the user (I had confused).
>
> Anyhow thanks I will modify the patch.
>
> Thanks
> Sasi
>
>
> On Thu, Jan 12, 2012 at 3:11 PM, Hrvoje Niksic <[email protected]> wrote:
>
>> Sasikanth <[email protected]> writes:
>>
>> > I added a new option --bits as requested in
>> > https://savannah.gnu.org/bugs/?33210.
>> > This patch will display all data length in bits format for --bits
>> > option.
>>
>> I don't think anyone requested data *length* being displayed in bits.
>> Measuring bandwidth in bits per second is useful for compatibility with
>> units used by network equipment (which at the lowest level does deal
>> with individual bits). On the other hand, measuring downloaded data in
>> bits is not widely used and adds no new information nor convenience.
>>
>> The --bits option, if implemented, should only affect bandwidth display.
>>
>
>
diff -ur orig/wget-1.13/src/init.c wget-1.13/src/init.c
--- orig/wget-1.13/src/init.c 2011-08-07 01:57:37.000000000 +0530
+++ wget-1.13/src/init.c 2012-01-15 02:25:48.838638001 +0530
@@ -126,6 +126,7 @@
{ "backups", &opt.backups, cmd_number },
{ "base", &opt.base_href, cmd_string },
{ "bindaddress", &opt.bind_address, cmd_string },
+ { "bits", &opt.bits_fmt, cmd_boolean},
#ifdef HAVE_SSL
{ "cacertificate", &opt.ca_cert, cmd_file },
#endif
diff -ur orig/wget-1.13/src/main.c wget-1.13/src/main.c
--- orig/wget-1.13/src/main.c 2011-08-07 05:49:48.000000000 +0530
+++ wget-1.13/src/main.c 2012-01-15 02:29:13.818638001 +0530
@@ -166,6 +166,7 @@
{ "backups", 0, OPT_BOOLEAN, "backups", -1 },
{ "base", 'B', OPT_VALUE, "base", -1 },
{ "bind-address", 0, OPT_VALUE, "bindaddress", -1 },
+ { "bits", 0, OPT_BOOLEAN, "bits", -1 },
{ IF_SSL ("ca-certificate"), 0, OPT_VALUE, "cacertificate", -1 },
{ IF_SSL ("ca-directory"), 0, OPT_VALUE, "cadirectory", -1 },
{ "cache", 0, OPT_BOOLEAN, "cache", -1 },
@@ -704,6 +705,11 @@
-np, --no-parent don't ascend to the parent directory.\n"),
"\n",
+ N_("\
+Output format:\n"),
+ N_("\
+ --bits Output bandwidth in bits.\n"),
+ "\n",
N_("Mail bug reports and suggestions to <[email protected]>.\n")
};
diff -ur orig/wget-1.13/src/options.h wget-1.13/src/options.h
--- orig/wget-1.13/src/options.h 2011-08-06 15:54:32.000000000 +0530
+++ wget-1.13/src/options.h 2012-01-15 02:23:57.845638003 +0530
@@ -255,6 +255,7 @@
bool show_all_dns_entries; /* Show all the DNS entries when resolving a
name. */
+ bool bits_fmt; /*Output bandwidth in bits format*/
};
extern struct options opt;
diff -ur orig/wget-1.13/src/progress.c wget-1.13/src/progress.c
--- orig/wget-1.13/src/progress.c 2011-01-01 17:42:35.000000000 +0530
+++ wget-1.13/src/progress.c 2012-01-15 02:54:53.115637998 +0530
@@ -861,7 +861,7 @@
struct bar_progress_hist *hist = &bp->hist;
/* The progress bar should look like this:
- xx% [=======> ] nn,nnn 12.34K/s eta 36m 51s
+ xx% [=======> ] nn,nnn 12.34KB/s eta 36m 51s
Calculate the geometry. The idea is to assign as much room as
possible to the progress bar. The other idea is to never let
@@ -873,7 +873,7 @@
"xx% " or "100%" - percentage - 4 chars
"[]" - progress bar decorations - 2 chars
" nnn,nnn,nnn" - downloaded bytes - 12 chars or very rarely
more
- " 12.5K/s" - download rate - 8 chars
+ " 12.5KB/s" - download rate - 9 chars
" eta 36m 51s" - ETA - 14 chars
"=====>..." - progress bar - the rest
@@ -977,10 +977,11 @@
*p++ = ' ';
}
- /* " 12.52K/s" */
+ /* " 12.52Kb/s or 12.52KB/s" */
if (hist->total_time > 0 && hist->total_bytes)
{
- static const char *short_units[] = { "B/s", "K/s", "M/s", "G/s" };
+ static const char *short_units[] = { "B/s", "KB/s", "MB/s", "GB/s" };
+ static const char *short_units_bits[] = { "b/s", "Kb/s", "Mb/s", "Gb/s"
};
int units = 0;
/* Calculate the download speed using the history ring and
recent data that hasn't made it to the ring yet. */
@@ -988,7 +989,7 @@
double dltime = hist->total_time + (dl_total_time - bp->recent_start);
double dlspeed = calc_rate (dlquant, dltime, &units);
sprintf (p, " %4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2,
- dlspeed, short_units[units]);
+ dlspeed,
!opt.bits_fmt?short_units[units]:short_units_bits[units]);
move_to_end (p);
}
else
diff -ur orig/wget-1.13/src/retr.c wget-1.13/src/retr.c
--- orig/wget-1.13/src/retr.c 2011-07-26 15:13:17.000000000 +0530
+++ wget-1.13/src/retr.c 2012-01-15 02:22:33.030638001 +0530
@@ -577,6 +577,7 @@
{
static char res[20];
static const char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" };
+ static const char *rate_names_bits[] = {"b/s", "Kb/s", "Mb/s", "Gb/s" };
int units;
double dlrate = calc_rate (bytes, secs, &units);
@@ -584,7 +585,7 @@
e.g. "1022", "247", "12.5", "2.38". */
sprintf (res, "%.*f %s",
dlrate >= 99.95 ? 0 : dlrate >= 9.995 ? 1 : 2,
- dlrate, rate_names[units]);
+ dlrate, !opt.bits_fmt? rate_names[units]: rate_names_bits[units]);
return res;
}
@@ -601,6 +602,11 @@
calc_rate (wgint bytes, double secs, int *units)
{
double dlrate;
+ double in_bits = 8.0;
+
+ if (!opt.bits_fmt)
+ in_bits = 1.0;
+
assert (secs >= 0);
assert (bytes >= 0);
@@ -612,16 +618,17 @@
0 and the timer's resolution, assume half the resolution. */
secs = ptimer_resolution () / 2.0;
- dlrate = bytes / secs;
- if (dlrate < 1024.0)
+ dlrate = convert_to_bits (bytes) / secs;
+ if (dlrate < (1024.0 * in_bits))
*units = 0;
- else if (dlrate < 1024.0 * 1024.0)
- *units = 1, dlrate /= 1024.0;
- else if (dlrate < 1024.0 * 1024.0 * 1024.0)
- *units = 2, dlrate /= (1024.0 * 1024.0);
+ else if (dlrate < (1024.0 * 1024.0 * in_bits))
+ *units = 1, dlrate /= (1024.0 * in_bits);
+ else if (dlrate < (1024.0 * 1024.0 * 1024.0 * in_bits))
+ *units = 2, dlrate /= (1024.0 * 1024.0 * in_bits);
+
else
/* Maybe someone will need this, one day. */
- *units = 3, dlrate /= (1024.0 * 1024.0 * 1024.0);
+ *units = 3, dlrate /= (1024.0 * 1024.0 * 1024.0 * in_bits);
return dlrate;
}
diff -ur orig/wget-1.13/src/utils.c wget-1.13/src/utils.c
--- orig/wget-1.13/src/utils.c 2011-08-08 01:52:15.000000000 +0530
+++ wget-1.13/src/utils.c 2012-01-15 02:59:40.635638001 +0530
@@ -1803,6 +1803,17 @@
ringpos = (ringpos + 1) % RING_SIZE;
return buf;
}
+
+/* Converts the byte to bits format if --bits option is enabled
+ */
+wgint
+convert_to_bits (wgint num)
+{
+ if (opt.bits_fmt)
+ return num * 8;
+ return num;
+}
+
/* Determine the width of the terminal we're running on. If that's
not possible, return 0. */
2012-01-15 Sasikantha babu <[email protected]>
* utils.c (convert_to_bits): Added new function convert_to_bits to
convert bytes to bits
* retr.c (calc_rate): Modified the function to handle --bits option
and download rate calculated per bits per sec for --bits otherwise
bytes.
(retr_rate): Rates will display in bits per sec for --bits
* options.h (struct opt): Added --bit option bool variable bits_fmt
* main.c (print_help) : Added help for --bit
* init.c: Defined command for --bit option