Skip to content

Commit

Permalink
progress: calculate transfer speed on milliseconds if possible
Browse files Browse the repository at this point in the history
to increase accuracy for quick transfers

Bug #2200
  • Loading branch information
bagder committed Jan 1, 2018
1 parent 481539e commit f1a9b4c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
32 changes: 23 additions & 9 deletions lib/progress.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2018, 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
Expand Down Expand Up @@ -358,6 +358,7 @@ int Curl_pgrsUpdate(struct connectdata *conn)
curl_off_t total_transfer;
curl_off_t total_expected_transfer;
curl_off_t timespent;
curl_off_t timespent_ms; /* milliseconds */
struct Curl_easy *data = conn->data;
int nowindex = data->progress.speeder_c% CURR_TIME;
int checkindex;
Expand All @@ -369,22 +370,35 @@ int Curl_pgrsUpdate(struct connectdata *conn)
curl_off_t dlestimate = 0;
curl_off_t total_estimate;
bool shownow = FALSE;
curl_off_t dl = data->progress.downloaded;
curl_off_t ul = data->progress.uploaded;

now = Curl_now(); /* what time is it */

/* The time spent so far (from the start) */
data->progress.timespent = Curl_timediff_us(now, data->progress.start);
timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */

/* The average download speed this far */
data->progress.dlspeed = (curl_off_t)
(data->progress.downloaded/
(timespent>0?timespent:1));
if((dl < CURL_OFF_T_MAX/1000) && (ul < CURL_OFF_T_MAX/1000)) {
timespent_ms = (curl_off_t)data->progress.timespent/1000; /* ms */

/* The average upload speed this far */
data->progress.ulspeed = (curl_off_t)
(data->progress.uploaded/
(timespent>0?timespent:1));
/* The average download speed this far */
data->progress.dlspeed = (curl_off_t)
(dl * 1000 / (timespent_ms>0?timespent_ms:1));

/* The average upload speed this far */
data->progress.ulspeed = (curl_off_t)
(ul * 1000 / (timespent_ms>0?timespent_ms:1));
}
else {
/* The average download speed this far */
data->progress.dlspeed = (curl_off_t)
(dl / (timespent>0?timespent:1));

/* The average upload speed this far */
data->progress.ulspeed = (curl_off_t)
(ul / (timespent>0?timespent:1));
}

/* Calculations done at most once a second, unless end is reached */
if(data->progress.lastshow != now.tv_sec) {
Expand Down
10 changes: 1 addition & 9 deletions lib/strtoofft.h
Expand Up @@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2018, 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
Expand Down Expand Up @@ -40,14 +40,6 @@
* of 'long' the conversion function to use is strtol().
*/

#if (SIZEOF_CURL_OFF_T == 4)
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
#else
/* assume CURL_SIZEOF_CURL_OFF_T == 8 */
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
#endif
#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))

typedef enum {
CURL_OFFT_OK, /* parsed fine */
CURL_OFFT_FLOW, /* over or underflow */
Expand Down
10 changes: 9 additions & 1 deletion lib/urldata.h
Expand Up @@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2018, 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
Expand Down Expand Up @@ -147,6 +147,14 @@
#define CURLMAX(x,y) ((x)>(y)?(x):(y))
#define CURLMIN(x,y) ((x)<(y)?(x):(y))

#if (SIZEOF_CURL_OFF_T == 4)
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
#else
/* assume CURL_SIZEOF_CURL_OFF_T == 8 */
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
#endif
#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))

#ifdef HAVE_GSSAPI
/* Types needed for krb5-ftp connections */
struct krb5buffer {
Expand Down
10 changes: 9 additions & 1 deletion src/tool_getparam.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2018, 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
Expand Down Expand Up @@ -42,6 +42,14 @@

#include "memdebug.h" /* keep this as LAST include */

#if (SIZEOF_CURL_OFF_T == 4)
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
#else
/* assume CURL_SIZEOF_CURL_OFF_T == 8 */
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
#endif
#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))

#ifdef MSDOS
# define USE_WATT32
#endif
Expand Down

0 comments on commit f1a9b4c

Please sign in to comment.