mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
Fixed the time fields no never get wider than 8 letters. They can now switch
to a "days + hours" or even "just days" display if the time value is very large. I also switched several calculations over to fixed-point instead of the previous doubles.
This commit is contained in:
parent
d426db3d27
commit
d44f3f84f8
122
lib/progress.c
122
lib/progress.c
@ -26,9 +26,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/* 20000318 mgs
|
|
||||||
* later we use _scrsize to determine the screen width, this emx library
|
|
||||||
* function needs stdlib.h to be included */
|
|
||||||
#if defined(__EMX__)
|
#if defined(__EMX__)
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
@ -36,19 +33,34 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include "sendf.h"
|
#include "sendf.h"
|
||||||
|
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
|
|
||||||
#define _MPRINTF_REPLACE /* use our functions only */
|
#define _MPRINTF_REPLACE /* use our functions only */
|
||||||
#include <curl/mprintf.h>
|
#include <curl/mprintf.h>
|
||||||
|
|
||||||
|
/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
|
||||||
static void time2str(char *r, int t)
|
byte) */
|
||||||
|
static void time2str(char *r, long t)
|
||||||
{
|
{
|
||||||
int h = (t/3600);
|
int h;
|
||||||
int m = (t-(h*3600))/60;
|
if(!t) {
|
||||||
int s = (t-(h*3600)-(m*60));
|
strcpy(r, "--:--:--");
|
||||||
sprintf(r,"%2d:%02d:%02d",h,m,s);
|
return;
|
||||||
|
}
|
||||||
|
h = (t/3600);
|
||||||
|
if(h <= 99) {
|
||||||
|
int m = (t-(h*3600))/60;
|
||||||
|
int s = (t-(h*3600)-(m*60));
|
||||||
|
sprintf(r, "%2d:%02d:%02d",h,m,s);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* this equals to more than 99 hours, switch to a more suitable output
|
||||||
|
format to fit within the limits. */
|
||||||
|
if(h/24 <= 99)
|
||||||
|
sprintf(r, " %2dd %02dh", h/24, h-(h/24)*24);
|
||||||
|
else
|
||||||
|
sprintf(r, "%7dd", h/24);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The point of this function would be to return a string of the input data,
|
/* The point of this function would be to return a string of the input data,
|
||||||
@ -195,44 +207,27 @@ void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size)
|
|||||||
data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
|
data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EXAMPLE OUTPUT to follow:
|
|
||||||
|
|
||||||
% Total % Received % Xferd Average Speed Time Curr.
|
|
||||||
Dload Upload Total Current Left Speed
|
|
||||||
100 12345 100 12345 100 12345 12345 12345 12:12:12 12:12:12 12:12:12 12345
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
int Curl_pgrsUpdate(struct connectdata *conn)
|
int Curl_pgrsUpdate(struct connectdata *conn)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
char max5[6][10];
|
char max5[6][10];
|
||||||
double dlpercen=0;
|
int dlpercen=0;
|
||||||
double ulpercen=0;
|
int ulpercen=0;
|
||||||
double total_percen=0;
|
int total_percen=0;
|
||||||
|
|
||||||
curl_off_t total_transfer;
|
curl_off_t total_transfer;
|
||||||
curl_off_t total_expected_transfer;
|
curl_off_t total_expected_transfer;
|
||||||
double timespent;
|
long timespent;
|
||||||
|
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
|
|
||||||
int nowindex = data->progress.speeder_c% CURR_TIME;
|
int nowindex = data->progress.speeder_c% CURR_TIME;
|
||||||
int checkindex;
|
int checkindex;
|
||||||
|
|
||||||
int countindex; /* amount of seconds stored in the speeder array */
|
int countindex; /* amount of seconds stored in the speeder array */
|
||||||
|
|
||||||
char time_left[10];
|
char time_left[10];
|
||||||
char time_total[10];
|
char time_total[10];
|
||||||
char time_current[10];
|
char time_spent[10];
|
||||||
|
long ulestimate=0;
|
||||||
double ulestimate=0;
|
long dlestimate=0;
|
||||||
double dlestimate=0;
|
long total_estimate;
|
||||||
|
|
||||||
double total_estimate;
|
|
||||||
|
|
||||||
|
|
||||||
if(data->progress.flags & PGRS_HIDE)
|
if(data->progress.flags & PGRS_HIDE)
|
||||||
; /* We do enter this function even if we don't wanna see anything, since
|
; /* We do enter this function even if we don't wanna see anything, since
|
||||||
@ -246,26 +241,26 @@ int Curl_pgrsUpdate(struct connectdata *conn)
|
|||||||
"\n",
|
"\n",
|
||||||
conn->resume_from);
|
conn->resume_from);
|
||||||
fprintf(data->set.err,
|
fprintf(data->set.err,
|
||||||
" %% Total %% Received %% Xferd Average Speed Time Curr.\n"
|
" %% Total %% Received %% Xferd Average Speed Time Time Time Current\n"
|
||||||
" Dload Upload Total Current Left Speed\n");
|
" Dload Upload Total Spent Left Speed\n");
|
||||||
}
|
}
|
||||||
data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */
|
data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */
|
||||||
}
|
}
|
||||||
|
|
||||||
now = Curl_tvnow(); /* what time is it */
|
now = Curl_tvnow(); /* what time is it */
|
||||||
|
|
||||||
/* The exact time spent so far (from the start) */
|
/* The time spent so far (from the start) */
|
||||||
timespent = (double)Curl_tvdiff (now, data->progress.start)/1000;
|
timespent = Curl_tvdiff(now, data->progress.start)/1000;
|
||||||
|
|
||||||
data->progress.timespent = timespent;
|
data->progress.timespent = (double)timespent;
|
||||||
|
|
||||||
/* The average download speed this far */
|
/* The average download speed this far */
|
||||||
data->progress.dlspeed =
|
data->progress.dlspeed =
|
||||||
data->progress.downloaded/(timespent>0.01?timespent:1);
|
data->progress.downloaded/(timespent?timespent:1);
|
||||||
|
|
||||||
/* The average upload speed this far */
|
/* The average upload speed this far */
|
||||||
data->progress.ulspeed =
|
data->progress.ulspeed =
|
||||||
data->progress.uploaded/(timespent>0.01?timespent:1);
|
data->progress.uploaded/(timespent?timespent:1);
|
||||||
|
|
||||||
if(data->progress.lastshow == Curl_tvlong(now))
|
if(data->progress.lastshow == Curl_tvlong(now))
|
||||||
return 0; /* never update this more than once a second if the end isn't
|
return 0; /* never update this more than once a second if the end isn't
|
||||||
@ -338,35 +333,25 @@ int Curl_pgrsUpdate(struct connectdata *conn)
|
|||||||
/* Figure out the estimated time of arrival for the upload */
|
/* Figure out the estimated time of arrival for the upload */
|
||||||
if((data->progress.flags & PGRS_UL_SIZE_KNOWN) &&
|
if((data->progress.flags & PGRS_UL_SIZE_KNOWN) &&
|
||||||
(data->progress.ulspeed > 0)) {
|
(data->progress.ulspeed > 0)) {
|
||||||
ulestimate = (double)data->progress.size_ul / data->progress.ulspeed;
|
ulestimate = data->progress.size_ul / data->progress.ulspeed;
|
||||||
ulpercen = ((double)data->progress.uploaded / data->progress.size_ul)*100;
|
ulpercen = (data->progress.uploaded / data->progress.size_ul)*100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... and the download */
|
/* ... and the download */
|
||||||
if((data->progress.flags & PGRS_DL_SIZE_KNOWN) &&
|
if((data->progress.flags & PGRS_DL_SIZE_KNOWN) &&
|
||||||
(data->progress.dlspeed > 0)) {
|
(data->progress.dlspeed > 0)) {
|
||||||
dlestimate = (double)data->progress.size_dl / data->progress.dlspeed;
|
dlestimate = data->progress.size_dl / data->progress.dlspeed;
|
||||||
dlpercen = ((double)data->progress.downloaded / data->progress.size_dl)*100;
|
dlpercen = (data->progress.downloaded / data->progress.size_dl)*100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now figure out which of them that is slower and use for the for
|
/* Now figure out which of them that is slower and use for the for
|
||||||
total estimate! */
|
total estimate! */
|
||||||
total_estimate = ulestimate>dlestimate?ulestimate:dlestimate;
|
total_estimate = ulestimate>dlestimate?ulestimate:dlestimate;
|
||||||
|
|
||||||
|
/* create the three time strings */
|
||||||
/* If we have a total estimate, we can display that and the expected
|
time2str(time_left, total_estimate > 0?(total_estimate - timespent):0);
|
||||||
time left */
|
time2str(time_total, total_estimate);
|
||||||
if(total_estimate > 0) {
|
time2str(time_spent, timespent);
|
||||||
time2str(time_left, (int)(total_estimate - data->progress.timespent));
|
|
||||||
time2str(time_total, (int)total_estimate);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* otherwise we blank those times */
|
|
||||||
strcpy(time_left, "--:--:--");
|
|
||||||
strcpy(time_total, "--:--:--");
|
|
||||||
}
|
|
||||||
/* The time spent so far is always known */
|
|
||||||
time2str(time_current, (int)data->progress.timespent);
|
|
||||||
|
|
||||||
/* Get the total amount of data expected to get transfered */
|
/* Get the total amount of data expected to get transfered */
|
||||||
total_expected_transfer =
|
total_expected_transfer =
|
||||||
@ -384,18 +369,17 @@ int Curl_pgrsUpdate(struct connectdata *conn)
|
|||||||
|
|
||||||
fprintf(data->set.err,
|
fprintf(data->set.err,
|
||||||
"\r%3d %s %3d %s %3d %s %s %s %s %s %s %s",
|
"\r%3d %s %3d %s %3d %s %s %s %s %s %s %s",
|
||||||
(int)total_percen, /* total % */
|
total_percen, /* 3 letters */ /* total % */
|
||||||
max5data(total_expected_transfer, max5[2]), /* total size */
|
max5data(total_expected_transfer, max5[2]), /* total size */
|
||||||
(int)dlpercen, /* rcvd % */
|
dlpercen, /* 3 letters */ /* rcvd % */
|
||||||
max5data(data->progress.downloaded, max5[0]), /* rcvd size */
|
max5data(data->progress.downloaded, max5[0]), /* rcvd size */
|
||||||
(int)ulpercen, /* xfer % */
|
ulpercen, /* 3 letters */ /* xfer % */
|
||||||
max5data(data->progress.uploaded, max5[1]), /* xfer size */
|
max5data(data->progress.uploaded, max5[1]), /* xfer size */
|
||||||
|
max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */
|
||||||
max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */
|
max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */
|
||||||
max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */
|
time_total, /* 8 letters */ /* total time */
|
||||||
time_total, /* total time */
|
time_spent, /* 8 letters */ /* time spent */
|
||||||
time_current, /* current time */
|
time_left, /* 8 letters */ /* time left */
|
||||||
time_left, /* time left */
|
|
||||||
max5data(data->progress.current_speed, max5[5]) /* current speed */
|
max5data(data->progress.current_speed, max5[5]) /* current speed */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user