Minor experimental changes to the download progress bar:
* change to Mb and Gb for both total size and transfer rate if needed * round up to 1 second for downloads that were between 1s and 0.5s This function needs some serious looking at, as it's probably not 64bit safe (thus the "wrong calculation" problem on the list).
This commit is contained in:
parent
96a0115630
commit
dd7f1d95b1
1 changed files with 38 additions and 12 deletions
|
@ -73,7 +73,7 @@ void log_progress(const char *filename, int xfered, int total)
|
||||||
timediff = get_update_timediff(0);
|
timediff = get_update_timediff(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(percent > 0 && percent < 100 && !timediff) {
|
if(percent > 0 && percent <= 100 && !timediff) {
|
||||||
/* only update the progress bar when
|
/* only update the progress bar when
|
||||||
* a) we first start
|
* a) we first start
|
||||||
* b) we end the progress
|
* b) we end the progress
|
||||||
|
@ -84,17 +84,22 @@ void log_progress(const char *filename, int xfered, int total)
|
||||||
|
|
||||||
gettimeofday(¤t_time, NULL);
|
gettimeofday(¤t_time, NULL);
|
||||||
total_timediff = current_time.tv_sec-initial_time.tv_sec
|
total_timediff = current_time.tv_sec-initial_time.tv_sec
|
||||||
+ (float)(current_time.tv_usec-initial_time.tv_usec) / 1000000;
|
+ (float)(current_time.tv_usec-initial_time.tv_usec) / 1000000.0;
|
||||||
|
|
||||||
if(xfered == total) {
|
if(xfered == total) {
|
||||||
/* compute final values */
|
/* compute final values */
|
||||||
rate = (float)total / (total_timediff * 1024);
|
rate = (float)total / (total_timediff * 1024.0);
|
||||||
eta_s = (unsigned int)total_timediff;
|
if(total_timediff < 1.0 && total_timediff > 0.5) {
|
||||||
|
/* round up so we don't display 00:00:00 for quick downloads all the time*/
|
||||||
|
eta_s = 1;
|
||||||
|
} else {
|
||||||
|
eta_s = (unsigned int)total_timediff;
|
||||||
|
}
|
||||||
set_output_padding(0); /* shut off padding */
|
set_output_padding(0); /* shut off padding */
|
||||||
} else {
|
} else {
|
||||||
rate = (float)(xfered - xfered_last) / (timediff * 1024);
|
rate = (float)(xfered - xfered_last) / (timediff * 1024.0);
|
||||||
rate = (float)(rate + 2*rate_last) / 3;
|
rate = (float)(rate + 2*rate_last) / 3;
|
||||||
eta_s = (unsigned int)(total - xfered) / (rate * 1024);
|
eta_s = (unsigned int)(total - xfered) / (rate * 1024.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
rate_last = rate;
|
rate_last = rate;
|
||||||
|
@ -114,14 +119,35 @@ void log_progress(const char *filename, int xfered, int total)
|
||||||
fname[FILENAME_TRIM_LEN] = '\0';
|
fname[FILENAME_TRIM_LEN] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DL rate cap, for printf formatting - this should be sane for a while
|
/* Awesome formatting for progress bar. We need a mess of Kb->Mb->Gb stuff
|
||||||
* if anything we can change to MB/s if we need a higher rate */
|
* here. We'll use limit of 2048 for each until we get some empirical */
|
||||||
if(rate > 9999.9) {
|
char rate_size = 'K';
|
||||||
rate = 9999.9;
|
char xfered_size = 'K';
|
||||||
|
if(rate > 2048.0) {
|
||||||
|
rate /= 1024.0;
|
||||||
|
rate_size = 'M';
|
||||||
|
if(rate > 2048.0) {
|
||||||
|
rate /= 1024.0;
|
||||||
|
rate_size = 'G';
|
||||||
|
/* we should not go higher than this for a few years (9999.9 Gb/s?)*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" %-*s %6dK %#6.1fK/s %02u:%02u:%02u", FILENAME_TRIM_LEN, fname,
|
xfered /= 1024; /* convert to K by default */
|
||||||
xfered/1024, rate, eta_h, eta_m, eta_s);
|
if(xfered > 2048) {
|
||||||
|
xfered /= 1024;
|
||||||
|
xfered_size = 'M';
|
||||||
|
if(xfered > 2048) {
|
||||||
|
xfered /= 1024;
|
||||||
|
xfered_size = 'G';
|
||||||
|
/* I should seriously hope that archlinux packages never break
|
||||||
|
* the 9999.9GB mark... we'd have more serious problems than the progress
|
||||||
|
* bar in pacman */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" %-*s %6d%c %#6.1f%c/s %02u:%02u:%02u", FILENAME_TRIM_LEN, fname,
|
||||||
|
xfered/1024, xfered_size, rate, rate_size, eta_h, eta_m, eta_s);
|
||||||
|
|
||||||
free(fname);
|
free(fname);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue