mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
curl: make --progress-bar update the line less frequently
Also, use memset() instead of a lame loop. The previous logic that tried to avoid too many updates were very ineffective for really fast transfers, as then it could easily end up doing hundreds of updates per second that would make a significant impact in transfer performance! Bug: http://curl.haxx.se/mail/archive-2013-07/0031.html Reported-by: Marc Doughty
This commit is contained in:
parent
9dedcbf9ec
commit
1691a31cab
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -49,17 +49,19 @@ int tool_progress_cb(void *clientp,
|
||||
double percent;
|
||||
int barwidth;
|
||||
int num;
|
||||
int i;
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct ProgressData *bar = (struct ProgressData *)clientp;
|
||||
curl_off_t total;
|
||||
curl_off_t point;
|
||||
|
||||
if(bar->prevtime == now) /* wait with update */
|
||||
return 0;
|
||||
|
||||
/* expected transfer size */
|
||||
curl_off_t total = (curl_off_t)dltotal + (curl_off_t)ultotal +
|
||||
bar->initial_size;
|
||||
total = (curl_off_t)dltotal + (curl_off_t)ultotal + bar->initial_size;
|
||||
|
||||
/* we've come this far */
|
||||
curl_off_t point = (curl_off_t)dlnow + (curl_off_t)ulnow +
|
||||
bar->initial_size;
|
||||
point = (curl_off_t)dlnow + (curl_off_t)ulnow + bar->initial_size;
|
||||
|
||||
if(point > total)
|
||||
/* we have got more than the expected total! */
|
||||
@ -83,14 +85,14 @@ int tool_progress_cb(void *clientp,
|
||||
num = (int) (((double)barwidth) * frac);
|
||||
if(num > MAX_BARLENGTH)
|
||||
num = MAX_BARLENGTH;
|
||||
for(i = 0; i < num; i++)
|
||||
line[i] = '#';
|
||||
line[i] = '\0';
|
||||
memset(line, '#', num);
|
||||
line[num] = '\0';
|
||||
snprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth);
|
||||
fprintf(bar->out, format, line, percent);
|
||||
}
|
||||
fflush(bar->out);
|
||||
bar->prev = point;
|
||||
bar->prevtime = now;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -29,6 +29,7 @@
|
||||
struct ProgressData {
|
||||
int calls;
|
||||
curl_off_t prev;
|
||||
time_t prevtime;
|
||||
int width;
|
||||
FILE *out; /* where to write everything to */
|
||||
curl_off_t initial_size;
|
||||
|
Loading…
Reference in New Issue
Block a user