aboutsummaryrefslogtreecommitdiff
path: root/src/tool_cb_prg.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2013-07-31 00:17:56 +0200
committerDaniel Stenberg <daniel@haxx.se>2013-07-31 13:41:00 +0200
commit1691a31cab33ef1d6a186bd08e5f8cf7661e34c1 (patch)
treee4cf1d89822270eacfe7dca38a88c4b7664bf961 /src/tool_cb_prg.c
parent9dedcbf9ec47b436a43c1e4744921b9e620e5fe2 (diff)
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
Diffstat (limited to 'src/tool_cb_prg.c')
-rw-r--r--src/tool_cb_prg.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c
index 7a701b692..9facd9e76 100644
--- a/src/tool_cb_prg.c
+++ b/src/tool_cb_prg.c
@@ -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;
}