From a8ce5efba92a87ee57ae2241a9af4083cbad9049 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 1 Jan 2018 22:11:13 +1300 Subject: progress: calculate transfer speed on milliseconds if possible to increase accuracy for quick transfers Fixes #2200 Closes #2206 --- lib/progress.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 72c518a14..cc5e8be79 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -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; @@ -369,22 +370,27 @@ 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 */ + timespent_ms = (curl_off_t)data->progress.timespent/1000; /* ms */ /* 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) + data->progress.dlspeed = (dl * 1000 / (timespent_ms>0?timespent_ms:1)); + else + data->progress.dlspeed = (dl / (timespent>0?timespent:1)); /* The average upload speed this far */ - data->progress.ulspeed = (curl_off_t) - (data->progress.uploaded/ - (timespent>0?timespent:1)); + if(ul < CURL_OFF_T_MAX/1000) + data->progress.ulspeed = (ul * 1000 / (timespent_ms>0?timespent_ms:1)); + else + data->progress.ulspeed = (ul / (timespent>0?timespent:1)); /* Calculations done at most once a second, unless end is reached */ if(data->progress.lastshow != now.tv_sec) { -- cgit v1.2.1